Remove unused code to ignore runtime stack frames (#493)
`runtime.CallerFrames` is currently ignoring the last frame, which is
always `runtime.main` (for the main goroutine) and `runtime.goexit` (for
additional goroutines). Since the main goroutine will include the user's
main function, this is noise that doesn't add much value.
We had special logic to ignore these runtime frames specifically, but
it's not required since it's only ever the very last stack frame and we
already ignore the last frame.
Prashant Varanasi authored 6 years ago
GitHub committed 6 years ago
30 | 30 | const _zapPackage = "go.uber.org/zap" |
31 | 31 | |
32 | 32 | var ( |
33 | _stacktraceIgnorePrefixes = []string{ | |
34 | "runtime.goexit", | |
35 | "runtime.main", | |
36 | } | |
37 | 33 | _stacktracePool = sync.Pool{ |
38 | 34 | New: func() interface{} { |
39 | 35 | return newProgramCounters(64) |
68 | 64 | i := 0 |
69 | 65 | skipZapFrames := true // skip all consecutive zap frames at the beginning. |
70 | 66 | frames := runtime.CallersFrames(programCounters.pcs[:numFrames]) |
67 | ||
68 | // Note: On the last iteration, frames.Next() returns false, with a valid | |
69 | // frame, but we ignore this frame. The last frame is a a runtime frame which | |
70 | // adds noise, since it's only either runtime.main or runtime.goexit. | |
71 | 71 | for frame, more := frames.Next(); more; frame, more = frames.Next() { |
72 | if shouldIgnoreStacktraceFunction(frame.Function) { | |
73 | continue | |
74 | } | |
75 | 72 | if skipZapFrames && isZapFrame(frame.Function) { |
76 | 73 | continue |
77 | 74 | } else { |
111 | 108 | return false |
112 | 109 | } |
113 | 110 | |
114 | func shouldIgnoreStacktraceFunction(function string) bool { | |
115 | for _, prefix := range _stacktraceIgnorePrefixes { | |
116 | if strings.HasPrefix(function, prefix) { | |
117 | return true | |
118 | } | |
119 | } | |
120 | return false | |
121 | } | |
122 | ||
123 | 111 | type programCounters struct { |
124 | 112 | pcs []uintptr |
125 | 113 | } |