forked from mtusi2026/mtusi2026lab6
61 lines
2.9 KiB
Python
61 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Create a compact, reproducible table from measured track-1 JSON."""
|
|
import csv
|
|
import json
|
|
import re
|
|
import statistics
|
|
|
|
from observability_common import ROOT
|
|
|
|
|
|
def mib(value):
|
|
match = re.fullmatch(r'([0-9.]+)([A-Za-z]+)', value.strip())
|
|
if not match:
|
|
raise ValueError('Unrecognized Docker memory unit')
|
|
factor = {'B': 1/1048576, 'KiB': 1/1024, 'MiB': 1, 'GiB': 1024,
|
|
'kB': 1000/1048576, 'MB': 1000000/1048576, 'GB': 1000000000/1048576}
|
|
return float(match[1]) * factor[match[2]]
|
|
|
|
|
|
def summarize(row):
|
|
by_container = {}
|
|
for resource in row['resources']:
|
|
group = by_container.setdefault(resource['Name'], {'cpu': [], 'mem': []})
|
|
group['cpu'].append(float(resource['CPUPerc'].rstrip('%')))
|
|
group['mem'].append(mib(resource['MemUsage'].split('/')[0]))
|
|
app = [v for k, v in by_container.items() if '-api-' in k or '-worker-' in k]
|
|
telemetry = [v for k, v in by_container.items() if any('-' + service + '-' in k for service in ('collector', 'prometheus', 'loki', 'tempo', 'grafana'))]
|
|
def resources(items):
|
|
return round(sum(statistics.mean(v['cpu']) for v in items), 3), round(sum(max(v['mem']) for v in items), 3)
|
|
app_cpu, app_ram = resources(app)
|
|
telemetry_cpu, telemetry_ram = resources(telemetry)
|
|
sent = sum(v['sent'] for v in row['trace_retention'].values())
|
|
found = sum(v['found'] for v in row['trace_retention'].values())
|
|
return {'configuration': row['configuration'], 'repetition': row['repetition'],
|
|
'rps': row['successful_rps'], 'unexpected_errors': row['unexpected_errors'],
|
|
**row['all_request_latency_ms'], 'app_cpu_percent_sum_mean': app_cpu,
|
|
'app_ram_mib_sum_peak': app_ram, 'telemetry_cpu_percent_sum_mean': telemetry_cpu,
|
|
'telemetry_ram_mib_sum_peak': telemetry_ram,
|
|
'sent_requests': sent, 'retained_request_traces': found,
|
|
'missing_request_traces': sent-found,
|
|
**{k: v for k, v in row['counter_delta'].items()}}
|
|
|
|
|
|
def main():
|
|
report = json.loads((ROOT / 'evidence/lab6-research.json').read_text())
|
|
rows = [summarize(row) for row in report['trials']]
|
|
if not rows:
|
|
raise RuntimeError('No completed trials')
|
|
with (ROOT / 'evidence/lab6-research.csv').open('w', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=list(rows[0]))
|
|
writer.writeheader()
|
|
writer.writerows(rows)
|
|
print('| Config | Repeat | RPS | p50 ms | p95 ms | p99 ms | App CPU % | App MiB | Telemetry CPU % | Telemetry MiB | Request traces |')
|
|
print('| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |')
|
|
for row in rows:
|
|
print('| {configuration} | {repetition} | {rps} | {p50} | {p95} | {p99} | {app_cpu_percent_sum_mean} | {app_ram_mib_sum_peak} | {telemetry_cpu_percent_sum_mean} | {telemetry_ram_mib_sum_peak} | {retained_request_traces}/{sent_requests} |'.format(**row))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|