diff --git a/profiler/profiler.go b/profiler/profiler.go index 6e3e176752b..fdcfc2dd60f 100644 --- a/profiler/profiler.go +++ b/profiler/profiler.go @@ -353,6 +353,19 @@ func (a *agent) profileAndUpload(ctx context.Context, p *pb.Profile) { var prof bytes.Buffer pt := p.GetProfileType() + ptEnabled := false + for _, enabled := range a.profileTypes { + if enabled == pt { + ptEnabled = true + break + } + } + + if !ptEnabled { + debugLog("skipping collection of disabled profile type: %v", pt) + return + } + switch pt { case pb.ProfileType_CPU: duration, err := ptypes.Duration(p.Duration) diff --git a/profiler/profiler_test.go b/profiler/profiler_test.go index eeb709cbbb4..097640b0cc1 100644 --- a/profiler/profiler_test.go +++ b/profiler/profiler_test.go @@ -76,7 +76,7 @@ func createTestAgent(psc pb.ProfilerServiceClient) *agent { client: psc, deployment: createTestDeployment(), profileLabels: map[string]string{instanceLabel: testInstance}, - profileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS}, + profileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_HEAP_ALLOC, pb.ProfileType_THREADS}, } } @@ -140,11 +140,12 @@ func TestProfileAndUpload(t *testing.T) { errFunc := func(io.Writer) error { return errors.New("") } testDuration := time.Second * 5 tests := []struct { - profileType pb.ProfileType - duration *time.Duration - startCPUProfileFunc func(io.Writer) error - writeHeapProfileFunc func(io.Writer) error - wantBytes []byte + profileType pb.ProfileType + duration *time.Duration + startCPUProfileFunc func(io.Writer) error + writeHeapProfileFunc func(io.Writer) error + deltaMutexProfileFunc func(io.Writer) error + wantBytes []byte }{ { profileType: pb.ProfileType_CPU, @@ -218,6 +219,10 @@ func TestProfileAndUpload(t *testing.T) { return nil }, }, + { + profileType: pb.ProfileType_CONTENTION, + deltaMutexProfileFunc: errFunc, + }, } for _, tt := range tests {