Skip to content

Commit

Permalink
fix(profiler): do not collect disabled profile types (#2836)
Browse files Browse the repository at this point in the history
* fix(profiler): do not collect disabled profile types
Fixes #2835
  • Loading branch information
kalyanac committed Sep 12, 2020
1 parent a6e7a3d commit faeb498
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
13 changes: 13 additions & 0 deletions profiler/profiler.go
Expand Up @@ -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 {

This comment has been minimized.

Copy link
@aalexand

aalexand Sep 12, 2020

Contributor

Note that this change should become unnecessary once b/112391682 is fixed.

@wyk9787 FYI

This comment has been minimized.

Copy link
@wyk9787

wyk9787 Sep 13, 2020

It this change still good to have even if that bug is fixed?

This comment has been minimized.

Copy link
@aalexand

aalexand via email Sep 13, 2020

Contributor
debugLog("skipping collection of disabled profile type: %v", pt)
return
}

switch pt {
case pb.ProfileType_CPU:
duration, err := ptypes.Duration(p.Duration)
Expand Down
17 changes: 11 additions & 6 deletions profiler/profiler_test.go
Expand Up @@ -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},
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -218,6 +219,10 @@ func TestProfileAndUpload(t *testing.T) {
return nil
},
},
{
profileType: pb.ProfileType_CONTENTION,
deltaMutexProfileFunc: errFunc,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit faeb498

Please sign in to comment.