Skip to content

Commit

Permalink
debug: Use pprof goroutine writer in debug.Stacks() to ensure all gor…
Browse files Browse the repository at this point in the history
…outines are captured.

* Up to 64MB limit, previous code only captured first 1MB of goroutines.
  • Loading branch information
ryanschneider committed Jun 6, 2018
1 parent eae63c5 commit d5868b6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"sync"
"time"

"bufio"
"bytes"
"github.com/ethereum/go-ethereum/log"
)

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d5868b6

Please sign in to comment.