]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: disable automatic GC for STW metric tests
authorRhys Hiltner <rhys@justin.tv>
Thu, 16 Nov 2023 17:44:21 +0000 (09:44 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 16 Nov 2023 22:15:03 +0000 (22:15 +0000)
A follow-up to https://go.dev/cl/534161 -- calls to runtime/trace.Start
and Stop synchronize with the GC, waiting for any in-progress mark phase
to complete. Disable automatic GCs to quiet the system, so we can
observe only the test's intentional pauses.

Change-Id: I6f8106c42528f9bda9afec1c151119783bbc78dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/543075
Run-TryBot: Rhys Hiltner <rhys@justin.tv>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Rhys Hiltner <rhys@justin.tv>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/metrics_test.go

index d7f21f1825085d82463a2882b2acee167f4f2a7e..1e82897381c43c86f72675ccdaa1682ae495dee9 100644 (file)
@@ -780,8 +780,6 @@ func TestCPUMetricsSleep(t *testing.T) {
 // Call f() and verify that the correct STW metrics increment. If isGC is true,
 // fn triggers a GC STW. Otherwise, fn triggers an other STW.
 func testSchedPauseMetrics(t *testing.T, fn func(t *testing.T), isGC bool) {
-       t.Helper()
-
        m := []metrics.Sample{
                {Name: "/sched/pauses/stopping/gc:seconds"},
                {Name: "/sched/pauses/stopping/other:seconds"},
@@ -848,7 +846,7 @@ func testSchedPauseMetrics(t *testing.T, fn func(t *testing.T), isGC bool) {
 }
 
 func TestSchedPauseMetrics(t *testing.T) {
-       tests := []struct{
+       tests := []struct {
                name string
                isGC bool
                fn   func(t *testing.T)
@@ -856,13 +854,13 @@ func TestSchedPauseMetrics(t *testing.T) {
                {
                        name: "runtime.GC",
                        isGC: true,
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                runtime.GC()
                        },
                },
                {
                        name: "runtime.GOMAXPROCS",
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                if runtime.GOARCH == "wasm" {
                                        t.Skip("GOMAXPROCS >1 not supported on wasm")
                                }
@@ -870,33 +868,33 @@ func TestSchedPauseMetrics(t *testing.T) {
                                n := runtime.GOMAXPROCS(0)
                                defer runtime.GOMAXPROCS(n)
 
-                               runtime.GOMAXPROCS(n+1)
+                               runtime.GOMAXPROCS(n + 1)
                        },
                },
                {
                        name: "runtime.GoroutineProfile",
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                var s [1]runtime.StackRecord
                                runtime.GoroutineProfile(s[:])
                        },
                },
                {
                        name: "runtime.ReadMemStats",
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                var mstats runtime.MemStats
                                runtime.ReadMemStats(&mstats)
                        },
                },
                {
                        name: "runtime.Stack",
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                var b [64]byte
                                runtime.Stack(b[:], true)
                        },
                },
                {
                        name: "runtime/debug.WriteHeapDump",
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                if runtime.GOOS == "js" {
                                        t.Skip("WriteHeapDump not supported on js")
                                }
@@ -912,7 +910,7 @@ func TestSchedPauseMetrics(t *testing.T) {
                },
                {
                        name: "runtime/trace.Start",
-                       fn:   func(t *testing.T) {
+                       fn: func(t *testing.T) {
                                if trace.IsEnabled() {
                                        t.Skip("tracing already enabled")
                                }
@@ -926,6 +924,15 @@ func TestSchedPauseMetrics(t *testing.T) {
                },
        }
 
+       // These tests count STW pauses, classified based on whether they're related
+       // to the GC or not. Disable automatic GC cycles during the test so we don't
+       // have an incidental GC pause when we're trying to observe only
+       // non-GC-related pauses. This is especially important for the
+       // runtime/trace.Start test, since (as of this writing) that will block
+       // until any active GC mark phase completes.
+       defer debug.SetGCPercent(debug.SetGCPercent(-1))
+       runtime.GC()
+
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
                        testSchedPauseMetrics(t, tc.fn, tc.isGC)