Skip to content

Commit

Permalink
Use runtime.CallersFrames
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Mar 9, 2017
1 parent 14d7845 commit 2694c26
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,29 @@ func takeStacktrace() string {
}

i := 0
for _, programCounter := range programCounters.pcs {
f := runtime.FuncForPC(programCounter)
name := f.Name()
if shouldIgnoreStacktraceName(name) {
frames := runtime.CallersFrames(programCounters.pcs)
for frame, more := frames.Next(); more; frame, more = frames.Next() {
if shouldIgnoreStacktraceFunction(frame.Function) {
continue
}
if i != 0 {
buffer.AppendByte('\n')
}
i++
file, line := f.FileLine(programCounter - 1)
buffer.AppendString(name)
buffer.AppendString(frame.Function)
buffer.AppendByte('\n')
buffer.AppendByte('\t')
buffer.AppendString(file)
buffer.AppendString(frame.File)
buffer.AppendByte(':')
buffer.AppendInt(int64(line))
buffer.AppendInt(int64(frame.Line))
}

return buffer.String()
}

func shouldIgnoreStacktraceName(name string) bool {
func shouldIgnoreStacktraceFunction(function string) bool {
for _, prefix := range _stacktraceIgnorePrefixes {
if strings.HasPrefix(name, prefix) {
if strings.HasPrefix(function, prefix) {
return true
}
}
Expand Down

0 comments on commit 2694c26

Please sign in to comment.