MCPcopy Index your code
hub / github.com/bytebase/bytebase / TakeStacktrace

Function TakeStacktrace

backend/common/stacktrace/stack.go:9–35  ·  view source on GitHub ↗

TakeStacktrace takes at most n stacks, skiping the first skip stacks.

(n, skip uint)

Source from the content-addressed store, hash-verified

7
8// TakeStacktrace takes at most n stacks, skiping the first skip stacks.
9func TakeStacktrace(n, skip uint) []byte {
10 var buf []byte
11 pcs := make([]uintptr, n)
12
13 // +2 to exclude runtime.Callers and TakeStacktrace
14 numFrames := runtime.Callers(2+int(skip), pcs)
15 if numFrames == 0 {
16 return buf
17 }
18 frames := runtime.CallersFrames(pcs[:numFrames])
19 for i := 0; ; i++ {
20 frame, more := frames.Next()
21 if i != 0 {
22 buf = append(buf, '\n')
23 }
24 buf = append(buf, []byte(frame.Function)...)
25 buf = append(buf, '\n')
26 buf = append(buf, '\t')
27 buf = append(buf, []byte(frame.File)...)
28 buf = append(buf, ':')
29 buf = append(buf, []byte(strconv.Itoa(frame.Line))...)
30 if !more {
31 break
32 }
33 }
34 return buf
35}

Callers 4

RouterMethod · 0.92
configureGrpcRoutersFunction · 0.92
BBStackFunction · 0.92
TestTakeStacktraceFunction · 0.85

Calls 1

NextMethod · 0.45

Tested by 1

TestTakeStacktraceFunction · 0.68