diff --git a/envs/monkey_zoo/blackbox/analyzers/performance_analyzer.py b/envs/monkey_zoo/blackbox/analyzers/performance_analyzer.py index 665ec18af..4a43ab6a5 100644 --- a/envs/monkey_zoo/blackbox/analyzers/performance_analyzer.py +++ b/envs/monkey_zoo/blackbox/analyzers/performance_analyzer.py @@ -19,14 +19,14 @@ class PerformanceAnalyzer(Analyzer): single_page_time_less_then_max = True total_time = timedelta() for endpoint, elapsed in self.endpoint_timings.items(): - LOGGER.info(f"Endpoint {endpoint} took {str(elapsed)}") total_time += elapsed if elapsed > self.performance_test_config.max_allowed_single_page_time: single_page_time_less_then_max = False total_time_less_then_max = total_time < self.performance_test_config.max_allowed_total_time - LOGGER.info(f"total time is {str(total_time)}") + PerformanceAnalyzer.log_slowest_endpoints(self.endpoint_timings) + LOGGER.info(f"Total time is {str(total_time)}") performance_is_good_enough = total_time_less_then_max and single_page_time_less_then_max @@ -38,3 +38,11 @@ class PerformanceAnalyzer(Analyzer): breakpoint() return performance_is_good_enough + + @staticmethod + def log_slowest_endpoints(endpoint_timings, max_endpoints_to_display=100): + slow_endpoint_list = list(endpoint_timings.items()) + slow_endpoint_list.sort(key=lambda x: x[1], reverse=True) + slow_endpoint_list = slow_endpoint_list[:max_endpoints_to_display] + for endpoint in slow_endpoint_list: + LOGGER.info(f"{endpoint[0]} took {str(endpoint[1])}") diff --git a/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py b/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py index 236625288..719ec5806 100644 --- a/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py +++ b/envs/monkey_zoo/blackbox/tests/performance/telemetry_performance_test.py @@ -49,5 +49,5 @@ class TelemetryPerformanceTest: def get_verbose_telemetry_endpoint(telemetry): telem_category = "" if "telem_category" in telemetry['content']: - telem_category = "_" + json.loads(telemetry['content'])['telem_category'] + telem_category = "_" + json.loads(telemetry['content'])['telem_category'] + "_" + telemetry['_id']['$oid'] return telemetry['endpoint'] + telem_category