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 <mpratt@google.com>
Trust: Michael Pratt <mpratt@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Rhys Hiltner 2021-10-29 17:35:30 -07:00 committed by Michael Pratt
parent c143661568
commit 5f0e5d21bb
1 changed files with 9 additions and 0 deletions

View 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() {