mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-17 15:06:47 +08:00

* feat: add block profiling to collect-profiles.sh * feat: add more profiles to 'ipfs diag profile' This adds mutex and block profiles, and brings the command up-to-par with 'collect-profiles.sh', so that we can remove it. Profiles are also now collected concurrently, which improves the runtime from (profile_time * num_profiles) to just (profile_time). Note that this has a backwards-incompatible change, removing --cpu-profile-time in favor of the more general --profile-time, which covers all sampling profiles. * docs(cli): ipfs diag profile * add CLI flag to select specific diag collectors Co-authored-by: Marcin Rataj <lidel@lidel.org>
28 lines
621 B
Go
28 lines
621 B
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
|
|
}
|