diff --git a/pkg/server/profiler/cpuprofile_test.go b/pkg/server/profiler/cpuprofile_test.go index cb74da8b65f2..2f26870ccc23 100644 --- a/pkg/server/profiler/cpuprofile_test.go +++ b/pkg/server/profiler/cpuprofile_test.go @@ -30,6 +30,7 @@ func TestCPUProfiler(t *testing.T) { s.Version = clusterversion.MakeVersionHandle(sv) sv.Init(ctx, s.Version) cpuProfileInterval.Override(ctx, sv, time.Hour) + cpuProfileEnabled.Override(ctx, sv, true) pastTime := time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC) cases := []struct { name string diff --git a/pkg/server/profiler/cpuprofiler.go b/pkg/server/profiler/cpuprofiler.go index 75591d590716..44b28c68fff2 100644 --- a/pkg/server/profiler/cpuprofiler.go +++ b/pkg/server/profiler/cpuprofiler.go @@ -59,6 +59,13 @@ var cpuProfileDuration = settings.RegisterDurationSetting( 10*time.Second, settings.PositiveDuration, ) +var cpuProfileEnabled = settings.RegisterBoolSetting( + settings.TenantWritable, + "server.cpu_profile.enabled", + "a bool which indicates whether cpu profiles should be taken by the cpu profiler", + false, +) + const cpuProfFileNamePrefix = "cpuprof" // CPUProfiler is used to take CPU profiles. @@ -100,6 +107,9 @@ func NewCPUProfiler(ctx context.Context, dir string, st *cluster.Settings) (*CPU // MaybeTakeProfile takes a cpu profile if cpu usage is high enough. func (cp *CPUProfiler) MaybeTakeProfile(ctx context.Context, currentCpuUsage int64) { + if !cpuProfileEnabled.Get(&cp.st.SV) { + return + } cp.profiler.maybeTakeProfile(ctx, currentCpuUsage, cp.takeCPUProfile) }