From: Rhys Hiltner Date: Sat, 30 Oct 2021 00:35:30 +0000 (-0700) Subject: runtime/pprof: disable GC during calibration test X-Git-Tag: go1.18beta1~577 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5f0e5d21bb1f2c1baf15bfd90ad5b090b88e6292;p=gostls13.git runtime/pprof: disable GC during calibration test TestCPUProfileMultithreadMagnitude compares Go's CPU profile against the OS's accounting of the process's execution time, expecting them to be near equal. Background work from the runtime (especially in the garbage collector) can add significant noise to that measurement and flakiness to the test. Disable automatic GC cycles during the test. Updates #49065 Change-Id: Ie88895bfea17374278c5187f3a83e9f486bd37fb Reviewed-on: https://go-review.googlesource.com/c/go/+/359934 Reviewed-by: Michael Pratt Trust: Michael Pratt Trust: Michael Knyszek --- diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 06e0274e9a..417d5034a6 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -20,6 +20,7 @@ import ( "os/exec" "regexp" "runtime" + "runtime/debug" "strings" "sync" "sync/atomic" @@ -133,6 +134,14 @@ func TestCPUProfileMultithreadMagnitude(t *testing.T) { parallelism := runtime.GOMAXPROCS(0) + // This test compares the process's total CPU time against the CPU + // profiler's view of time spent in direct execution of user code. + // Background work, especially from the garbage collector, adds noise to + // that measurement. Disable automatic triggering of the GC, and then + // request a complete GC cycle (up through sweep termination). + defer debug.SetGCPercent(debug.SetGCPercent(-1)) + runtime.GC() + var cpuTime1, cpuTimeN time.Duration p := testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1", "runtime/pprof.cpuHog3"}, avoidFunctions(), func(dur time.Duration) { cpuTime1 = diffCPUTime(t, func() {