Skip to content

Commit 01e0e8b

Browse files
committed
runtime/pprof: include PCs for deduplication in TestMutexBlockFullAggregation
TestMutexBlockFullAggregation aggregates stacks by function, file, and line number. But there can be multiple function calls on the same line, giving us different sequences of PCs. This causes the test to spuriously fail in some cases. Include PCs in the stacks for this test. Also pick up a small "range over int" modernize suggestion while we're looking at the test. Fixes #73641 Change-Id: I50489e19fcf920e27b9eebd9d4b35feb89981cbc Reviewed-on: https://go-review.googlesource.com/c/go/+/673115 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent b338f6b commit 01e0e8b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/runtime/pprof/pprof_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ func produceProfileEvents(t *testing.T, depth int) {
26322632
goroutineDeep(t, depth-4) // -4 for produceProfileEvents, **, chanrecv1, chanrev, gopark
26332633
}
26342634

2635-
func getProfileStacks(collect func([]runtime.BlockProfileRecord) (int, bool), fileLine bool) []string {
2635+
func getProfileStacks(collect func([]runtime.BlockProfileRecord) (int, bool), fileLine bool, pcs bool) []string {
26362636
var n int
26372637
var ok bool
26382638
var p []runtime.BlockProfileRecord
@@ -2651,6 +2651,9 @@ func getProfileStacks(collect func([]runtime.BlockProfileRecord) (int, bool), fi
26512651
if i > 0 {
26522652
stack.WriteByte('\n')
26532653
}
2654+
if pcs {
2655+
fmt.Fprintf(&stack, "%x ", pc)
2656+
}
26542657
// Use FuncForPC instead of CallersFrames,
26552658
// because we want to see the info for exactly
26562659
// the PCs returned by the mutex profile to
@@ -2691,9 +2694,9 @@ func TestMutexBlockFullAggregation(t *testing.T) {
26912694

26922695
wg := sync.WaitGroup{}
26932696
wg.Add(workers)
2694-
for j := 0; j < workers; j++ {
2697+
for range workers {
26952698
go func() {
2696-
for i := 0; i < iters; i++ {
2699+
for range iters {
26972700
m.Lock()
26982701
// Wait at least 1 millisecond to pass the
26992702
// starvation threshold for the mutex
@@ -2706,7 +2709,7 @@ func TestMutexBlockFullAggregation(t *testing.T) {
27062709
wg.Wait()
27072710

27082711
assertNoDuplicates := func(name string, collect func([]runtime.BlockProfileRecord) (int, bool)) {
2709-
stacks := getProfileStacks(collect, true)
2712+
stacks := getProfileStacks(collect, true, true)
27102713
seen := make(map[string]struct{})
27112714
for _, s := range stacks {
27122715
if _, ok := seen[s]; ok {
@@ -2782,7 +2785,7 @@ runtime/pprof.inlineA`,
27822785

27832786
for _, tc := range tcs {
27842787
t.Run(tc.Name, func(t *testing.T) {
2785-
stacks := getProfileStacks(tc.Collect, false)
2788+
stacks := getProfileStacks(tc.Collect, false, false)
27862789
for _, s := range stacks {
27872790
if strings.Contains(s, tc.SubStack) {
27882791
return

0 commit comments

Comments
 (0)