From 416e66ad83ebde35df0e09f02e65ac149e193b0e Mon Sep 17 00:00:00 2001 From: Prashant Varanasi Date: Fri, 18 Aug 2017 16:41:21 -0700 Subject: [PATCH] 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. --- stacktrace.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/stacktrace.go b/stacktrace.go index de335c2e1..100fac216 100644 --- a/stacktrace.go +++ b/stacktrace.go @@ -31,10 +31,6 @@ import ( const _zapPackage = "go.uber.org/zap" var ( - _stacktraceIgnorePrefixes = []string{ - "runtime.goexit", - "runtime.main", - } _stacktracePool = sync.Pool{ New: func() interface{} { return newProgramCounters(64) @@ -69,10 +65,11 @@ func takeStacktrace() string { i := 0 skipZapFrames := true // skip all consecutive zap frames at the beginning. frames := runtime.CallersFrames(programCounters.pcs[:numFrames]) + + // Note: On the last iteration, frames.Next() returns false, with a valid + // frame, but we ignore this frame. The last frame is a a runtime frame which + // adds noise, since it's only either runtime.main or runtime.goexit. for frame, more := frames.Next(); more; frame, more = frames.Next() { - if shouldIgnoreStacktraceFunction(frame.Function) { - continue - } if skipZapFrames && isZapFrame(frame.Function) { continue } else { @@ -112,15 +109,6 @@ func isZapFrame(function string) bool { return false } -func shouldIgnoreStacktraceFunction(function string) bool { - for _, prefix := range _stacktraceIgnorePrefixes { - if strings.HasPrefix(function, prefix) { - return true - } - } - return false -} - type programCounters struct { pcs []uintptr }