NTP-1234 | Macrobenchmark | Update analyse.py (#14510)
This commit is contained in:
98
.github/actions/macrobenchmark/analyse.py
vendored
98
.github/actions/macrobenchmark/analyse.py
vendored
@@ -3,6 +3,55 @@ import requests
|
||||
import sys
|
||||
|
||||
|
||||
def find_benchmark_by_name(benchmarks, name_substring):
|
||||
for benchmark in benchmarks:
|
||||
if name_substring.lower() in benchmark['name'].lower():
|
||||
return benchmark
|
||||
return None
|
||||
|
||||
|
||||
def extract_metrics(benchmark_file):
|
||||
try:
|
||||
benchmarks = benchmark_file['benchmarks']
|
||||
|
||||
startup_benchmark = find_benchmark_by_name(benchmarks, 'startup')
|
||||
homepage_benchmark = find_benchmark_by_name(benchmarks, 'scroll')
|
||||
|
||||
if not startup_benchmark:
|
||||
raise ValueError("Startup benchmark not found")
|
||||
if not homepage_benchmark:
|
||||
raise ValueError("Homepage scroll benchmark not found")
|
||||
|
||||
startup_metrics = startup_benchmark['metrics']['timeToInitialDisplayMs']
|
||||
min_value = startup_metrics['minimum']
|
||||
median_value = startup_metrics['median']
|
||||
max_value = startup_metrics['maximum']
|
||||
|
||||
homepage_metrics = homepage_benchmark['sampledMetrics']['frameDurationCpuMs']
|
||||
p50_value = homepage_metrics['P50']
|
||||
p90_value = homepage_metrics['P90']
|
||||
p95_value = homepage_metrics['P95']
|
||||
p99_value = homepage_metrics['P99']
|
||||
|
||||
device_model = benchmark_file['context']['build']['model']
|
||||
|
||||
return {
|
||||
'device_model': device_model,
|
||||
'min_value': min_value,
|
||||
'median_value': median_value,
|
||||
'max_value': max_value,
|
||||
'p50_value': p50_value,
|
||||
'p90_value': p90_value,
|
||||
'p95_value': p95_value,
|
||||
'p99_value': p99_value
|
||||
}
|
||||
|
||||
except KeyError as e:
|
||||
raise ValueError(f"Failed to find key in benchmark data: {str(e)}")
|
||||
except Exception as e:
|
||||
raise ValueError(f"Error processing benchmark data: {str(e)}")
|
||||
|
||||
|
||||
def send_message_to_metabase(device_model, version_code, run_id, min, median, max, homepage_p50,
|
||||
homepage_p90, homepage_p95, homepage_p99):
|
||||
url = "https://janus.prod.navi-tech.in/events/json"
|
||||
@@ -48,21 +97,38 @@ def send_message_to_metabase(device_model, version_code, run_id, min, median, ma
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: script.py <run_id> <version_code>")
|
||||
sys.exit(1)
|
||||
|
||||
run_id = sys.argv[1]
|
||||
version_code = sys.argv[2]
|
||||
with open('macrobenchmark_results.json', 'r') as file_current:
|
||||
benchmark_file = json.load(file_current)
|
||||
benchmark = benchmark_file['benchmarks']
|
||||
homePage_metrics = benchmark[0]['sampledMetrics']['frameDurationCpuMs']
|
||||
p50_value = homePage_metrics['P50']
|
||||
p90_value = homePage_metrics['P90']
|
||||
p95_value = homePage_metrics['P95']
|
||||
p99_value = homePage_metrics['P99']
|
||||
startup_metrics = benchmark[1]['metrics']['timeToInitialDisplayMs']
|
||||
median_value = startup_metrics['median']
|
||||
min_value = startup_metrics['minimum']
|
||||
max_value = startup_metrics['maximum']
|
||||
context = benchmark_file['context']
|
||||
device_model = context['build']['model']
|
||||
send_message_to_metabase(device_model, version_code, run_id, min_value, median_value, max_value,
|
||||
p50_value, p90_value, p95_value, p99_value)
|
||||
|
||||
try:
|
||||
with open('macrobenchmark_results.json', 'r') as file_current:
|
||||
benchmark_file = json.load(file_current)
|
||||
|
||||
metrics = extract_metrics(benchmark_file)
|
||||
|
||||
send_message_to_metabase(
|
||||
metrics['device_model'],
|
||||
version_code,
|
||||
run_id,
|
||||
metrics['min_value'],
|
||||
metrics['median_value'],
|
||||
metrics['max_value'],
|
||||
metrics['p50_value'],
|
||||
metrics['p90_value'],
|
||||
metrics['p95_value'],
|
||||
metrics['p99_value']
|
||||
)
|
||||
|
||||
except FileNotFoundError:
|
||||
print("Error: macrobenchmark_results.json file not found")
|
||||
sys.exit(1)
|
||||
except json.JSONDecodeError:
|
||||
print("Error: Invalid JSON in macrobenchmark_results.json")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user