Commit 897ea01d authored by Ryan Schneider's avatar Ryan Schneider Committed by Péter Szilágyi

internal/debug: use pprof goroutine writer for debug_stacks (#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
parent ec192f18
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package debug package debug
import ( import (
"bytes"
"errors" "errors"
"io" "io"
"os" "os"
...@@ -190,9 +191,9 @@ func (*HandlerT) WriteMemProfile(file string) error { ...@@ -190,9 +191,9 @@ func (*HandlerT) WriteMemProfile(file string) error {
// Stacks returns a printed representation of the stacks of all goroutines. // Stacks returns a printed representation of the stacks of all goroutines.
func (*HandlerT) Stacks() string { func (*HandlerT) Stacks() string {
buf := make([]byte, 1024*1024) buf := new(bytes.Buffer)
buf = buf[:runtime.Stack(buf, true)] pprof.Lookup("goroutine").WriteTo(buf, 2)
return string(buf) return buf.String()
} }
// FreeOSMemory returns unused memory to the OS. // FreeOSMemory returns unused memory to the OS.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment