From 8556bc7729a90a329fc4c7e8277d6fbda6b96abe Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Sun, 3 Nov 2024 21:25:35 -0500 Subject: [PATCH] sql/tests: disable profiling during sysbench setup This commit disables memory, mutex, and block profiling during sysbench setup. All three of these profile types record events from process startup onward if we don't manully disable them. Epic: None Release note: None --- pkg/sql/tests/sysbench_test.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/sql/tests/sysbench_test.go b/pkg/sql/tests/sysbench_test.go index 4e6cc08e2e3c..05a7bb5f83ed 100644 --- a/pkg/sql/tests/sysbench_test.go +++ b/pkg/sql/tests/sysbench_test.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "math/rand" + "runtime" "slices" "testing" @@ -638,23 +639,44 @@ func BenchmarkSysbench(b *testing.B) { } }() + // Set up the cluster and dataset. + disableProfiling() ctx := context.Background() sys, cleanup := driver.constructorFn(ctx, b) defer cleanup() - rng := rand.New(rand.NewSource(0)) sys.prep(rng) + // Start profiling and timer, then run the workload. + enableProfiling() b.ResetTimer() + b.ReportAllocs() for i := 0; i < b.N; i++ { workload.opFn(sys, rng) } + + // Stop timer and profiling to exclude (deferred) cluster teardown. + b.StopTimer() + disableProfiling() }) } }) } } +func disableProfiling() { + runtime.MemProfileRate = 0 + runtime.SetMutexProfileFraction(0) + runtime.SetBlockProfileRate(0) +} + +func enableProfiling() { + runtime.GC() + runtime.MemProfileRate = 1 + runtime.SetMutexProfileFraction(1) + runtime.SetBlockProfileRate(1) +} + func try0(err error) { if err != nil { panic(errors.WrapWithDepth(1, err, "try failed"))