Skip to content

Commit f185599

Browse files
korniltsevgopherbot
authored andcommitted
runtime: skip trailing wrappers in runtime_expandFinalInlineFrame
The existing runtime_expandFinalInlineFrame implementation doesn't skip trailing wrappers, but gentraceback does skip wrapper functions. This change makes runtime_expandFinalInlineFrame handling wrapper functions consistent to gentraceback. Fixes #58288 Change-Id: I1b0e2c10b0a89bcb1e787b98d27730cb40a34406 Reviewed-on: https://go-review.googlesource.com/c/go/+/465097 Reviewed-by: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Michael Pratt <[email protected]> Run-TryBot: Michael Pratt <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent b7736cb commit f185599

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/runtime/pprof/pprof_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,23 @@ func inlinedCalleeDump(pcs []uintptr) {
333333
dumpCallers(pcs)
334334
}
335335

336+
type inlineWrapperInterface interface {
337+
dump(stack []uintptr)
338+
}
339+
340+
type inlineWrapper struct {
341+
}
342+
343+
func (h inlineWrapper) dump(pcs []uintptr) {
344+
dumpCallers(pcs)
345+
}
346+
347+
func inlinedWrapperCallerDump(pcs []uintptr) {
348+
var h inlineWrapperInterface
349+
h = &inlineWrapper{}
350+
h.dump(pcs)
351+
}
352+
336353
func TestCPUProfileRecursion(t *testing.T) {
337354
matches := matchAndAvoidStacks(stackContains, []string{"runtime/pprof.inlinedCallee", "runtime/pprof.recursionCallee", "runtime/pprof.recursionCaller"}, avoidFunctions())
338355
p := testCPUProfile(t, matches, func(dur time.Duration) {
@@ -2054,6 +2071,8 @@ func TestTryAdd(t *testing.T) {
20542071
for i := range pcs {
20552072
inlinedCallerStack[i] = uint64(pcs[i])
20562073
}
2074+
wrapperPCs := make([]uintptr, 1)
2075+
inlinedWrapperCallerDump(wrapperPCs)
20572076

20582077
if _, found := findInlinedCall(recursionChainBottom, 4<<10); !found {
20592078
t.Skip("Can't determine whether anything was inlined into recursionChainBottom.")
@@ -2226,6 +2245,17 @@ func TestTryAdd(t *testing.T) {
22262245
{Value: []int64{70, 70 * period}, Location: []*profile.Location{{ID: 1}}},
22272246
{Value: []int64{80, 80 * period}, Location: []*profile.Location{{ID: 2}, {ID: 1}}},
22282247
},
2248+
}, {
2249+
name: "expand_wrapper_function",
2250+
input: []uint64{
2251+
3, 0, 500, // hz = 500. Must match the period.
2252+
4, 0, 50, uint64(wrapperPCs[0]),
2253+
},
2254+
count: 2,
2255+
wantLocs: [][]string{{"runtime/pprof.inlineWrapper.dump"}},
2256+
wantSamples: []*profile.Sample{
2257+
{Value: []int64{50, 50 * period}, Location: []*profile.Location{{ID: 1}}},
2258+
},
22292259
}}
22302260

22312261
for _, tc := range testCases {

src/runtime/symtab.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr {
230230
}
231231

232232
// N.B. we want to keep the last parentPC which is not inline.
233-
stk = append(stk, pc)
233+
if f.funcID == funcID_wrapper && elideWrapperCalling(lastFuncID) {
234+
// Ignore wrapper functions (except when they trigger panics).
235+
} else {
236+
stk = append(stk, pc)
237+
}
234238

235239
return stk
236240
}

0 commit comments

Comments
 (0)