]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: disable GC during calibration test
authorRhys Hiltner <rhys@justin.tv>
Sat, 30 Oct 2021 00:35:30 +0000 (17:35 -0700)
committerMichael Pratt <mpratt@google.com>
Wed, 3 Nov 2021 15:59:11 +0000 (15:59 +0000)
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 <mpratt@google.com>
Trust: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>

src/runtime/pprof/pprof_test.go

index 06e0274e9abb3ff57d1375eb4838b56b8afea0a1..417d5034a6e2bed949b90dee7669230bb23e018a 100644 (file)
@@ -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() {