-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share callstack b/w Caller and Stack #808
Changes from 1 commit
512b342
3e14bd1
3520ae7
954fa36
332434f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ func takeStacktrace() string { | |
pcs := newProgramCounters() | ||
defer pcs.Release() | ||
|
||
return makeStacktrace(pcs.Callers(1)) | ||
return makeStacktrace(pcs.Callers(1 /* skip */, 0 /* limit */)) | ||
} | ||
|
||
func makeStacktrace(pcs []uintptr) string { | ||
|
@@ -113,19 +113,40 @@ func (pcs *programCounters) Release() { | |
_stacktracePool.Put(pcs) | ||
} | ||
|
||
func (pcs *programCounters) Callers(skip int) []uintptr { | ||
// Callers captures program counters of callers of the current function. | ||
// | ||
// skip specifies the number of functions to skip. | ||
// limit specifies how deep into the stack we go, zero meaning unlimited. | ||
func (pcs *programCounters) Callers(skip int, limit int) []uintptr { | ||
pc := pcs.pcs | ||
if limit > 0 { | ||
// The shortened slice will never be placed back into the | ||
// pool, but the longer one will. | ||
if limit < len(pc) { | ||
pc = pc[:limit] | ||
} else { | ||
pc = make([]uintptr, limit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this case never gets hit in prod right? anyway we can refactor the change to avoid adding a case that's not necessary in prod? |
||
pcs.pcs = pc | ||
} | ||
} | ||
|
||
var numFrames int | ||
for { | ||
// Skip the call to runtime.Callers and programCounter.Callers | ||
// so that the program counters start at our caller. | ||
numFrames = runtime.Callers(skip+2, pcs.pcs) | ||
if numFrames < len(pcs.pcs) { | ||
return pcs.pcs[:numFrames] | ||
numFrames = runtime.Callers(skip+2, pc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can do |
||
|
||
// All required frames have been captured if the limit was | ||
// non-zero or if the stack depth is smaller than the size of | ||
// the slice. | ||
if limit > 0 || numFrames < len(pc) { | ||
return pc[:numFrames] | ||
} | ||
|
||
// Don't put the too-short counter slice back into the pool; this lets | ||
// the pool adjust if we consistently take deep stacktraces. | ||
pcs.pcs = make([]uintptr, len(pcs.pcs)*2) | ||
pc = make([]uintptr, len(pcs.pcs)*2) | ||
pcs.pcs = pc | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are adding caller and stack, then the
stackSkip
passed in is 0 (e.g., no caller skip), so the caller value used here would be incorrect right, since we wouldn't be respecting thelog.callerSkip