1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00
any-sync/util/debug/stack.go
2024-05-19 14:11:07 +02:00

28 lines
489 B
Go

package debug
import (
"bytes"
"compress/gzip"
"encoding/base64"
"runtime"
)
func StackCompact(allGoroutines bool) string {
var buf bytes.Buffer
gz := gzip.NewWriter(&buf)
_, _ = gz.Write(Stack(allGoroutines))
_ = gz.Close()
return base64.StdEncoding.EncodeToString(buf.Bytes())
}
func Stack(allGoroutines bool) []byte {
buf := make([]byte, 1024)
for {
n := runtime.Stack(buf, allGoroutines)
if n < len(buf) {
return buf[:n]
}
buf = make([]byte, 2*len(buf))
}
}