diff --git a/go/enclave/main/main.go b/go/enclave/main/main.go index 48ffc8c4be..d558de853b 100644 --- a/go/enclave/main/main.go +++ b/go/enclave/main/main.go @@ -2,6 +2,9 @@ package main import ( "fmt" + "os" + "runtime/pprof" + "time" "github.com/ten-protocol/go-ten/go/common/container" tenflag "github.com/ten-protocol/go-ten/go/common/flag" @@ -25,6 +28,29 @@ func main() { panic(fmt.Errorf("unable to create config from flags - %w", err)) } + // temporary code to help identify OOM + go func() { + for { + heap, err := os.Create(fmt.Sprintf("/data/heap_%d.pprof", time.Now().UnixMilli())) + if err != nil { + panic(fmt.Errorf("could not open heap profile: %w", err)) + } + err = pprof.WriteHeapProfile(heap) + if err != nil { + panic(fmt.Errorf("could not write CPU profile: %w", err)) + } + stack, err := os.Create(fmt.Sprintf("/data/stack_%d.pprof", time.Now().UnixMilli())) + if err != nil { + panic(fmt.Errorf("could not open stack profile: %w", err)) + } + err = pprof.Lookup("goroutine").WriteTo(stack, 1) + if err != nil { + panic(fmt.Errorf("could not write CPU profile: %w", err)) + } + time.Sleep(1 * time.Hour) + } + }() + enclaveContainer := enclavecontainer.NewEnclaveContainerFromConfig(enclaveConfig) container.Serve(enclaveContainer) } diff --git a/go/host/main/main.go b/go/host/main/main.go index e8ab9fae4f..c47c33ff36 100644 --- a/go/host/main/main.go +++ b/go/host/main/main.go @@ -2,6 +2,9 @@ package main import ( "fmt" + "os" + "runtime/pprof" + "time" "github.com/ten-protocol/go-ten/go/common/container" hostcontainer "github.com/ten-protocol/go-ten/go/host/container" @@ -14,6 +17,29 @@ func main() { panic(fmt.Errorf("could not parse config. Cause: %w", err)) } + // temporary code to help identify OOM + go func() { + for { + heap, err := os.Create(fmt.Sprintf("/data/heap_%d.pprof", time.Now().UnixMilli())) + if err != nil { + panic(fmt.Errorf("could not open heap profile: %w", err)) + } + err = pprof.WriteHeapProfile(heap) + if err != nil { + panic(fmt.Errorf("could not write CPU profile: %w", err)) + } + stack, err := os.Create(fmt.Sprintf("/data/stack_%d.pprof", time.Now().UnixMilli())) + if err != nil { + panic(fmt.Errorf("could not open stack profile: %w", err)) + } + err = pprof.Lookup("goroutine").WriteTo(stack, 1) + if err != nil { + panic(fmt.Errorf("could not write CPU profile: %w", err)) + } + time.Sleep(1 * time.Hour) + } + }() + hostContainer := hostcontainer.NewHostContainerFromConfig(parsedConfig, nil) container.Serve(hostContainer) }