in codeguru_profiler_agent/profiler_disabler.py [0:0]
def is_overall_cpu_usage_limit_reached(self, profile=None):
"""
This function carries out an overall cpu limit check that covers the cpu overhead caused for the full
sampling cycle: refresh config -> (sample -> aggregate) * n -> profile submission. We expect this function to
be called after profile submission.
"""
profiler_metric = self.timer.metrics.get("runProfiler")
if not profile or not profiler_metric or profiler_metric.counter < MINIMUM_MEASURES_IN_DURATION_METRICS:
return False
used_time_percentage = 100 * profiler_metric.total/(profile.get_active_millis_since_start()/1000)
cpu_limit_percentage = AgentConfiguration.get().cpu_limit_percentage
if used_time_percentage >= cpu_limit_percentage:
logger.debug(self.timer.metrics)
logger.debug("Profile active seconds since start: {:.2f} s".format(profile.get_active_millis_since_start()/1000))
logger.info(
"Profiler overall cpu usage limit reached: {:.2f} % (limit: {:.2f} %), will stop CodeGuru Profiler."
.format(used_time_percentage, cpu_limit_percentage))
return True
else:
return False