Skip to content

Commit 33152e2

Browse files
author
Colman Yau
committed
Update check to be carried out only after profile submission
1 parent aed725e commit 33152e2

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

codeguru_profiler_agent/profiler_disabler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def is_overall_cpu_usage_limit_reached(self, profile=None):
4646
"""
4747
This function carries out an overall cpu limit check that covers the cpu overhead caused for the full
4848
sampling cycle: refresh config -> (sample -> aggregate) * n -> profile submission. We expect this function to
49-
be called after configuration refresh and profile submission.
49+
be called after profile submission.
5050
"""
5151
profiler_metric = self.timer.metrics.get("runProfiler")
5252
if not profile or not profiler_metric or profiler_metric.counter < MINIMUM_MEASURES_IN_DURATION_METRICS:

codeguru_profiler_agent/profiler_runner.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ def _profiling_command(self):
7272
self.collector.setup()
7373
self._first_execution = False
7474
sample_result = self._run_profiler()
75-
if sample_result.success and sample_result.should_check_overall:
75+
if sample_result.success and sample_result.is_end_of_cycle:
7676
if self.profiler_disabler.should_stop_profiling(profile=self.collector.profile):
7777
return False
78-
if sample_result.should_reset:
79-
self.collector.reset()
80-
return True
78+
self.collector.reset()
79+
return True
8180
return sample_result.success
8281
except:
8382
logger.info("An unexpected issue caused the profiling command to terminate.", exc_info=True)
@@ -86,20 +85,18 @@ def _profiling_command(self):
8685
@with_timer("runProfiler")
8786
def _run_profiler(self):
8887
if self.profiler_disabler.should_stop_sampling(self.collector.profile):
89-
return RunProfilerStatus(success=False, should_check_overall=False, should_reset=False)
88+
return RunProfilerStatus(success=False, is_end_of_cycle=False)
9089

91-
refreshed_config = False
9290
if not self.is_profiling_in_progress:
9391
self._refresh_configuration()
94-
refreshed_config = True
9592

9693
# after the refresh we may be working on a profile
9794
if self.is_profiling_in_progress:
9895
if self.collector.flush(reset=False):
9996
self.is_profiling_in_progress = False
100-
return RunProfilerStatus(success=True, should_check_overall=True, should_reset=True)
97+
return RunProfilerStatus(success=True, is_end_of_cycle=True)
10198
self._sample_and_aggregate()
102-
return RunProfilerStatus(success=True, should_check_overall=refreshed_config, should_reset=False)
99+
return RunProfilerStatus(success=True, is_end_of_cycle=False)
103100

104101
@with_timer("sampleAndAggregate")
105102
def _sample_and_aggregate(self):
@@ -141,7 +138,6 @@ def pause(self, block=False):
141138

142139

143140
class RunProfilerStatus:
144-
def __init__(self, success, should_check_overall, should_reset):
141+
def __init__(self, success, is_end_of_cycle):
145142
self.success = success
146-
self.should_check_overall = should_check_overall
147-
self.should_reset = should_reset
143+
self.is_end_of_cycle = is_end_of_cycle

test/unit/test_profiler_disabler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_when_average_duration_exceeds_limit_it_returns_true(self):
248248
# timer: (0.5*20/100) * 100= 10%
249249
assert self.process_duration_check.is_overall_cpu_usage_limit_reached(self.profile)
250250

251-
def test_when_average_duragtion_is_below_limit_it_returns_false(self):
251+
def test_when_average_duration_is_below_limit_it_returns_false(self):
252252
# timer: (0.5*20/100) * 100= 10%
253253
set_agent_config(cpu_limit_percentage=11)
254254
assert not self.process_duration_check.is_overall_cpu_usage_limit_reached(self.profile)

0 commit comments

Comments
 (0)