Revision b43f3c151a89acffba1f84a207693f1da37dc80d authored by Piotr Galar on 20 March 2023, 12:25:23 UTC, committed by galargh on 20 March 2023, 14:03:07 UTC
fix: remove outdated changelog part
(cherry picked from commit 624846fc15a55fd76f0899fb41a87f41772c8b47)
1 parent 1386592
Raw File
goroutines.go
package profile

import (
	"io"
	"runtime"
)

// WriteAllGoroutineStacks writes a stack trace to the given writer.
// This is distinct from the Go-provided method because it does not truncate after 64 MB.
func WriteAllGoroutineStacks(w io.Writer) error {
	// this is based on pprof.writeGoroutineStacks, and removes the 64 MB limit
	buf := make([]byte, 1<<20)
	for i := 0; ; i++ {
		n := runtime.Stack(buf, true)
		if n < len(buf) {
			buf = buf[:n]
			break
		}
		// if len(buf) >= 64<<20 {
		// 	// Filled 64 MB - stop there.
		// 	break
		// }
		buf = make([]byte, 2*len(buf))
	}
	_, err := w.Write(buf)
	return err
}
back to top