forked from stackrox/stackrox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazy_stacktrace.go
More file actions
25 lines (20 loc) · 793 Bytes
/
Copy pathlazy_stacktrace.go
File metadata and controls
25 lines (20 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package debug
import "runtime"
// LazyStacktrace is a stack trace that is cheap to construct, and will resolve frames to source/function information
// on demand.
type LazyStacktrace []uintptr
const (
maxStacktrace = 10
)
// GetLazyStacktrace returns a lazy stacktrace, skipping the given number of frames. A skip value of 0 indicates that the
// frame for GetLazyStacktrace should be part of the stack trace.
func GetLazyStacktrace(skip int) LazyStacktrace {
callerPCs := make([]uintptr, maxStacktrace)
numCallers := runtime.Callers(skip+1, callerPCs)
return LazyStacktrace(callerPCs[:numCallers])
}
// String returns a string representation of the stacktrace.
func (t LazyStacktrace) String() string {
frames := runtime.CallersFrames([]uintptr(t))
return FramesToString(frames)
}