monkey/envs/monkey_zoo/blackbox/analyzers/performance_analyzer.py

41 lines
1.7 KiB
Python
Raw Normal View History

import logging
2020-02-23 21:24:44 +08:00
from datetime import timedelta
from typing import Dict
2020-02-23 21:24:44 +08:00
from envs.monkey_zoo.blackbox.analyzers.analyzer import Analyzer
from envs.monkey_zoo.blackbox.tests.performance.performance_test_config import PerformanceTestConfig
LOGGER = logging.getLogger(__name__)
2020-02-23 21:24:44 +08:00
class PerformanceAnalyzer(Analyzer):
2020-02-25 20:57:50 +08:00
def __init__(self, performance_test_config: PerformanceTestConfig, endpoint_timings: Dict[str, timedelta]):
self.performance_test_config = performance_test_config
self.endpoint_timings = endpoint_timings
def analyze_test_results(self):
# Calculate total time and check each endpoint
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
2020-02-23 21:24:44 +08:00
total_time_less_then_max = total_time < self.performance_test_config.max_allowed_total_time
2020-02-23 21:24:44 +08:00
LOGGER.info(f"total time is {str(total_time)}")
2020-02-23 21:24:44 +08:00
performance_is_good_enough = total_time_less_then_max and single_page_time_less_then_max
if self.performance_test_config.break_on_timeout and not performance_is_good_enough:
LOGGER.warning(
"Calling breakpoint - pausing to enable investigation of island. Type 'c' to continue once you're done "
"investigating. Type 'p timings' and 'p total_time' to see performance information."
)
breakpoint()
2020-02-25 20:57:50 +08:00
return performance_is_good_enough