From d5868b684b605bea4b6b6a718e5b5d7cccc0db06 Mon Sep 17 00:00:00 2001 From: Ryan Schneider Date: Mon, 4 Jun 2018 17:21:24 -0700 Subject: [PATCH 1/4] debug: Use pprof goroutine writer in debug.Stacks() to ensure all goroutines are captured. * Up to 64MB limit, previous code only captured first 1MB of goroutines. --- internal/debug/api.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/debug/api.go b/internal/debug/api.go index 048b7d76359c..88b91f1351a9 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -33,6 +33,8 @@ import ( "sync" "time" + "bufio" + "bytes" "github.com/ethereum/go-ethereum/log" ) @@ -190,9 +192,13 @@ func (*HandlerT) WriteMemProfile(file string) error { // Stacks returns a printed representation of the stacks of all goroutines. func (*HandlerT) Stacks() string { - buf := make([]byte, 1024*1024) - buf = buf[:runtime.Stack(buf, true)] - return string(buf) + var b bytes.Buffer + b.Grow(1024 * 1024) + w := bufio.NewWriter(&b) + pprof.Lookup("goroutine").WriteTo(w, 2) + w.Flush() + + return b.String() } // FreeOSMemory returns unused memory to the OS. From 205b26bf1328f32ecf0f4c7f2b404bcc575a9a20 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 14 Jun 2018 13:53:25 +0200 Subject: [PATCH 2/4] internal/debug: simplify stacks handler --- internal/debug/api.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/internal/debug/api.go b/internal/debug/api.go index 88b91f1351a9..3118777eed12 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -21,6 +21,7 @@ package debug import ( + "bytes" "errors" "io" "os" @@ -33,8 +34,6 @@ import ( "sync" "time" - "bufio" - "bytes" "github.com/ethereum/go-ethereum/log" ) @@ -193,11 +192,7 @@ func (*HandlerT) WriteMemProfile(file string) error { // Stacks returns a printed representation of the stacks of all goroutines. func (*HandlerT) Stacks() string { var b bytes.Buffer - b.Grow(1024 * 1024) - w := bufio.NewWriter(&b) pprof.Lookup("goroutine").WriteTo(w, 2) - w.Flush() - return b.String() } From 53e5166eb04a3a58a752f60fb56e17bb0967c8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 14 Jun 2018 15:26:51 +0300 Subject: [PATCH 3/4] fix typo --- internal/debug/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/debug/api.go b/internal/debug/api.go index 3118777eed12..232834d8c0bb 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -191,9 +191,9 @@ func (*HandlerT) WriteMemProfile(file string) error { // Stacks returns a printed representation of the stacks of all goroutines. func (*HandlerT) Stacks() string { - var b bytes.Buffer - pprof.Lookup("goroutine").WriteTo(w, 2) - return b.String() + var buf bytes.Buffer + pprof.Lookup("goroutine").WriteTo(buf, 2) + return buf.String() } // FreeOSMemory returns unused memory to the OS. From 0c022a77e157849c5133d274f414aaec974e0a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 14 Jun 2018 16:21:56 +0300 Subject: [PATCH 4/4] fix pointer receiver --- internal/debug/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/debug/api.go b/internal/debug/api.go index 232834d8c0bb..86a4218f6a57 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -191,7 +191,7 @@ func (*HandlerT) WriteMemProfile(file string) error { // Stacks returns a printed representation of the stacks of all goroutines. func (*HandlerT) Stacks() string { - var buf bytes.Buffer + buf := new(bytes.Buffer) pprof.Lookup("goroutine").WriteTo(buf, 2) return buf.String() }