]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: log profile when mutex profile test fails
authorRhys Hiltner <rhys.hiltner@gmail.com>
Fri, 14 Mar 2025 20:47:54 +0000 (13:47 -0700)
committerGopher Robot <gobot@golang.org>
Sat, 15 Mar 2025 20:07:01 +0000 (13:07 -0700)
For #70602

Change-Id: I3f723ebc17ef690d5be7f4f948c9dd1f890196fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/658095
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/metrics_test.go

index 9191d86d0437700e547e08a566edc8f5f144d472..a036f37b975e0e249808671e8b2c99f2c3d6b2a0 100644 (file)
@@ -1020,8 +1020,8 @@ func TestRuntimeLockMetricsAndProfile(t *testing.T) {
                return metricGrowth, profileGrowth, p
        }
 
-       testcase := func(strictTiming bool, acceptStacks [][]string, workers int, fn func() bool) func(t *testing.T) (metricGrowth, profileGrowth float64, n, value int64) {
-               return func(t *testing.T) (metricGrowth, profileGrowth float64, n, value int64) {
+       testcase := func(strictTiming bool, acceptStacks [][]string, workers int, fn func() bool) func(t *testing.T) (metricGrowth, profileGrowth float64, n, value int64, explain func()) {
+               return func(t *testing.T) (metricGrowth, profileGrowth float64, n, value int64, explain func()) {
                        metricGrowth, profileGrowth, p := measureDelta(t, func() {
                                var started, stopped sync.WaitGroup
                                started.Add(workers)
@@ -1113,7 +1113,9 @@ func TestRuntimeLockMetricsAndProfile(t *testing.T) {
                                }
                        }
 
-                       return metricGrowth, profileGrowth, n, value
+                       return metricGrowth, profileGrowth, n, value, func() {
+                               t.Logf("profile:\n%s", p)
+                       }
                }
        }
 
@@ -1173,7 +1175,12 @@ func TestRuntimeLockMetricsAndProfile(t *testing.T) {
                        defer runtime.SetMutexProfileFraction(old)
 
                        needContention.Store(int64(len(mus) - 1))
-                       metricGrowth, profileGrowth, n, _ := testcase(true, stks, workers, fn)(t)
+                       metricGrowth, profileGrowth, n, _, explain := testcase(true, stks, workers, fn)(t)
+                       defer func() {
+                               if t.Failed() {
+                                       explain()
+                               }
+                       }()
 
                        t.Run("metric", func(t *testing.T) {
                                // The runtime/metrics view may be sampled at 1 per
@@ -1208,7 +1215,12 @@ func TestRuntimeLockMetricsAndProfile(t *testing.T) {
                        defer runtime.SetMutexProfileFraction(old)
 
                        needContention.Store(int64(len(mus) - 1))
-                       metricGrowth, profileGrowth, n, _ := testcase(true, stks, workers, fn)(t)
+                       metricGrowth, profileGrowth, n, _, explain := testcase(true, stks, workers, fn)(t)
+                       defer func() {
+                               if t.Failed() {
+                                       explain()
+                               }
+                       }()
 
                        // With 100 trials and profile fraction of 2, we expect to capture
                        // 50 samples. Allow the test to pass if we get at least 20 samples;