Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codeguru_profiler_agent/model/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def end(self):
@end.setter
def end(self, value):
self._validate_positive_number(value)
if value < self.start:
if value <= self.start:
raise ValueError(
"Profile end value must be greater than or equal to {}, got {}".format(self.start, value))
"Profile end value must be greater than {}, got {}".format(self.start, value))
self._end = value
# this is the total cpu time spent in this application since start, not just the overhead
self.cpu_time_seconds = time.process_time() - self._start_process_time
Expand Down
1 change: 1 addition & 0 deletions codeguru_profiler_agent/profiler_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def _run_profiler(self):
if self.is_profiling_in_progress:
if self.collector.flush():
self.is_profiling_in_progress = False
return True
sample = self.sampler.sample()
self.collector.add(sample)
return True
Expand Down
10 changes: 8 additions & 2 deletions test/acceptance/test_live_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ def test_live_profiling(self):
start_status = profiler.start()
assert start_status
assert profiler.is_running()
time.sleep(3)
time.sleep(4)
finally:
profiler.stop()

assert wrapped_add.call_count >= 3
# We should see at least 2 samples in 4 seconds as the sequence should happen in the order of
# initial delay (1 second)
# After 1 second, no flush -> sample
# After 2 seconds, it attempt to flush (possibly succeed) -> sample/ no sample
# After 3 seconds, it attempt to flush (must succeed if it did not flush before) -> no sample/ sample
# After 4 seconds, no flush -> sample (if profiler has not stopped yet)
assert wrapped_add.call_count >= 2
assert wrapped_post_agent_profile.call_count >= 1
assert wrapped_configure_agent.call_count >= 1
assert AgentConfiguration.get().sampling_interval == timedelta(seconds=1)
Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_profiler_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def test_when_it_is_time_to_report_it_refreshes_configuration_again(self):
self.profiler_runner._profiling_command()
self.mock_collector.refresh_configuration.assert_called_once()

def test_when_it_reports_it_does_not_sample(self):
self.is_time_to_report = True

assert self.profiler_runner._profiling_command()
self.mock_collector.flush.assert_called_once()
self.mock_collector.add.assert_not_called()

def test_when_disabler_say_to_stop(self):
self.mock_disabler.should_stop_profiling.return_value = True
self.profiler_runner._profiling_command()
Expand Down