MCPcopy
hub / github.com/TarsCloud/TarsGo / DumpStack

Function DumpStack

tars/util/debug/debugtool.go:39–51  ·  view source on GitHub ↗

DumpStack used to dump stack info to file all: true means dumping all running goroutine stack, else only dumping the one that calls the func logname: prefix of the file's name, which is like logname.20060102-150405 msg: description message

(all bool, logname string, desc string)

Source from the content-addressed store, hash-verified

37// logname: prefix of the file's name, which is like logname.20060102-150405
38// msg: description message
39func DumpStack(all bool, logname string, desc string) {
40 buf := make([]byte, 1024)
41 for {
42 //the buf is no more than 64M, because Stack dumps no more than 64M
43 n := runtime.Stack(buf, all)
44 if n < len(buf) {
45 buf = buf[:n] //trim unreadable characters
46 break
47 }
48 buf = make([]byte, 2*len(buf))
49 }
50 write2File(logname, desc, buf)
51}
52
53// SigNotifyStack register os signals to be notified when to dumpstack
54// For example, SigNotifyStack(SIGUSR1, true, "stackinfo"), can dump all goroutine stack

Callers 3

NotifyMethod · 0.92
CheckPanicFunction · 0.92
TestDumpStackFunction · 0.85

Calls 1

write2FileFunction · 0.85

Tested by 1

TestDumpStackFunction · 0.68