Skip to content

Commit dfaa4f0

Browse files
ryanschneiderkielbarry
authored andcommitted
internal/debug: use pprof goroutine writer for debug_stacks (ethereum#16892)
* 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: simplify stacks handler * fix typo * fix pointer receiver
1 parent 6f49303 commit dfaa4f0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

internal/debug/api.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package debug
2222

2323
import (
24+
"bytes"
2425
"errors"
2526
"io"
2627
"os"
@@ -190,9 +191,9 @@ func (*HandlerT) WriteMemProfile(file string) error {
190191

191192
// Stacks returns a printed representation of the stacks of all goroutines.
192193
func (*HandlerT) Stacks() string {
193-
buf := make([]byte, 1024*1024)
194-
buf = buf[:runtime.Stack(buf, true)]
195-
return string(buf)
194+
buf := new(bytes.Buffer)
195+
pprof.Lookup("goroutine").WriteTo(buf, 2)
196+
return buf.String()
196197
}
197198

198199
// FreeOSMemory returns unused memory to the OS.

0 commit comments

Comments
 (0)