From d5868b684b605bea4b6b6a718e5b5d7cccc0db06 Mon Sep 17 00:00:00 2001 From: Ryan Schneider Date: Mon, 4 Jun 2018 17:21:24 -0700 Subject: [PATCH] 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 048b7d7635..88b91f1351 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.