Skip to content

Commit

Permalink
server: address AlexB comments
Browse files Browse the repository at this point in the history
Added an enabled cluster setting to
determine whether profiles should be taken.

Release note: None
  • Loading branch information
Santamaura committed Feb 24, 2023
1 parent 06f865c commit 471ec03
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/server/profiler/cpuprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/server/profiler/cpuprofiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 471ec03

Please sign in to comment.