From: Rhys Hiltner Date: Wed, 22 May 2024 16:57:14 +0000 (-0700) Subject: runtime/pprof: ignore runtime-internal samples in test X-Git-Tag: go1.23rc1~212 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=41884dcd05546ced3634496d931d0b005fc8c2e6;p=gostls13.git runtime/pprof: ignore runtime-internal samples in test Tests of the mutex profile focus on sync.Mutex, which is easy to control. But since those tests still use the runtime, and contention on internal runtime.mutex values is now also part of the mutex profile, we have to filter out those samples before examining the profile. Otherwise the test may be confused by stray contention on sched.lock (or other runtime-internal locks) as a natural consequence of using goroutines. Fixes #67563 Change-Id: I066a24674d8b719dbeca4a5c0f76b53bc07498c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/586957 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Auto-Submit: Rhys Hiltner Reviewed-by: Michael Pratt --- diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index e6fa068060..512e07e491 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -1349,14 +1349,21 @@ func TestMutexProfileRateAdjust(t *testing.T) { } for _, s := range p.Sample { + var match, runtimeInternal bool for _, l := range s.Location { for _, line := range l.Line { if line.Function.Name == "runtime/pprof.blockMutex.func1" { - contentions += s.Value[0] - delay += s.Value[1] + match = true + } + if line.Function.Name == "runtime.unlock" { + runtimeInternal = true } } } + if match && !runtimeInternal { + contentions += s.Value[0] + delay += s.Value[1] + } } return }