Skip to content

Commit 625d8e9

Browse files
committed
runtime/pprof: fix goroutine leak profile tests for noopt
The goroutine leak profile tests currently rely on a function being inlined, which results in a slightly different representation in the pprof proto. This function is not inlined on the noopt builder. Disable inlining of the one function which could be inlined to align but the regular and noopt builder versions of this test. We're not interested in testing the inlining functionality of profiles with this test, we care about certain stack frames appearing in a certain order. This also simplifies a bunch of the checking in the test. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-noopt Change-Id: I28902cc4c9fae32d1e3fa41b93b00c3be4d6074a Reviewed-on: https://go-review.googlesource.com/c/go/+/720100 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 4684a26 commit 625d8e9

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/runtime/pprof/pprof_test.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,9 @@ func containsCountsLabels(prof *profile.Profile, countLabels map[int64]map[strin
15691569
return true
15701570
}
15711571

1572+
// Inlining disabled to make identification simpler.
1573+
//
1574+
//go:noinline
15721575
func goroutineLeakExample() {
15731576
<-make(chan struct{})
15741577
panic("unreachable")
@@ -1595,12 +1598,12 @@ func TestGoroutineLeakProfileConcurrency(t *testing.T) {
15951598

15961599
checkFrame := func(i int, j int, locations []*profile.Location, expectedFunctionName string) {
15971600
if len(locations) <= i {
1598-
t.Errorf("leaked goroutine stack locations out of range at %d of %d", i+1, len(locations))
1601+
t.Errorf("leaked goroutine stack locations: out of range index %d, length %d", i, len(locations))
15991602
return
16001603
}
16011604
location := locations[i]
16021605
if len(location.Line) <= j {
1603-
t.Errorf("leaked goroutine stack location lines out of range at %d of %d", j+1, len(location.Line))
1606+
t.Errorf("leaked goroutine stack location lines: out of range index %d, length %d", j, len(location.Line))
16041607
return
16051608
}
16061609
if location.Line[j].Function.Name != expectedFunctionName {
@@ -1650,33 +1653,23 @@ func TestGoroutineLeakProfileConcurrency(t *testing.T) {
16501653
t.Errorf("expected %d leaked goroutines with specific stack configurations, but found %d", leakCount, pc)
16511654
return
16521655
}
1653-
switch len(locations) {
1654-
case 4:
1655-
// We expect a receive operation. This is the typical stack.
1656-
checkFrame(0, 0, locations, "runtime.gopark")
1657-
checkFrame(1, 0, locations, "runtime.chanrecv")
1658-
checkFrame(2, 0, locations, "runtime.chanrecv1")
1659-
switch len(locations[3].Line) {
1660-
case 2:
1661-
// Running `go func() { goroutineLeakExample() }()` will produce a stack with 2 lines.
1662-
// The anonymous function will have the call to goroutineLeakExample inlined.
1663-
checkFrame(3, 1, locations, "runtime/pprof.TestGoroutineLeakProfileConcurrency.func5")
1664-
fallthrough
1665-
case 1:
1666-
// Running `go goroutineLeakExample()` will produce a stack with 1 line.
1667-
checkFrame(3, 0, locations, "runtime/pprof.goroutineLeakExample")
1668-
default:
1669-
t.Errorf("leaked goroutine stack location expected 1 or 2 lines in the 4th location but found %d", len(locations[3].Line))
1670-
return
1671-
}
1672-
default:
1656+
if len(locations) < 4 || len(locations) > 5 {
16731657
message := fmt.Sprintf("leaked goroutine stack expected 4 or 5 locations but found %d", len(locations))
16741658
for _, location := range locations {
16751659
for _, line := range location.Line {
16761660
message += fmt.Sprintf("\n%s:%d", line.Function.Name, line.Line)
16771661
}
16781662
}
16791663
t.Errorf("%s", message)
1664+
return
1665+
}
1666+
// We expect a receive operation. This is the typical stack.
1667+
checkFrame(0, 0, locations, "runtime.gopark")
1668+
checkFrame(1, 0, locations, "runtime.chanrecv")
1669+
checkFrame(2, 0, locations, "runtime.chanrecv1")
1670+
checkFrame(3, 0, locations, "runtime/pprof.goroutineLeakExample")
1671+
if len(locations) == 5 {
1672+
checkFrame(4, 0, locations, "runtime/pprof.TestGoroutineLeakProfileConcurrency.func5")
16801673
}
16811674
}
16821675
}

0 commit comments

Comments
 (0)