Skip to content

Commit

Permalink
Remove unused code to ignore runtime stack frames (uber-go#493)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
prashantv authored Aug 18, 2017
1 parent 51996d5 commit 416e66a
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 416e66a

Please sign in to comment.