Report aligned per-second CPU power requests latency and errors

This commit is contained in:
Steffen committed 2026-10-08 12:59:43 +02:00
1 parent 17f3b0dbd3
commit 743674a022
5 files changed
+201

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""Verify clock alignment, one-second aggregation and missing-data semantics."""
import csv,datetime as dt,json,tempfile
from pathlib import Path
import report
with tempfile.TemporaryDirectory(prefix='healthapp-report-') as name:
folder=Path(name);start=1000000
(folder/'timeline.json').write_text(json.dumps({'warmup_start_ms':start,'measurement_start_ms':start+2000,'measurement_end_ms':start+5000}))
(folder/'run.json').write_text(json.dumps({'scenario':'mixed','exit_code':0,'finished_utc':dt.datetime.fromtimestamp((start+5000)/1000,dt.timezone.utc).isoformat()}))
def write(name,fields,rows):
with (folder/name).open('w') as f:w=csv.DictWriter(f,fieldnames=fields);w.writeheader();w.writerows(rows)
write('samples.csv',['timeStamp','elapsed','label','success'],[{'timeStamp':start+2050,'elapsed':200,'label':'HTTP Read profile','success':'true'},{'timeStamp':start+2200,'elapsed':1000,'label':'HTTP Read overview','success':'false'},{'timeStamp':start+2250,'elapsed':10,'label':'POWER Shelly status','success':'true'}])
write('perfmon.csv',['timeStamp','elapsed','label','success'],[{'timeStamp':start+2100,'elapsed':30000,'label':'NUC CPU combined','success':'true'},{'timeStamp':start+2800,'elapsed':50000,'label':'NUC CPU combined','success':'true'},{'timeStamp':start+2110,'elapsed':104857600000,'label':'NUC Memory actualused','success':'true'}])
write('shelly.csv',['timeStamp','elapsed','label','success','shelly_power_watts','shelly_energy_wh'],[{'timeStamp':start+2150,'elapsed':100,'label':'POWER Shelly status','success':'true','shelly_power_watts':20,'shelly_energy_wh':3}])
original=report.plot;report.plot=lambda *args:None
rows=report.build(folder)
report.plot=original
assert len(rows)==5
assert rows[2]['phase']=='measurement' and rows[1]['phase']=='warmup'
assert rows[2]['cpu_percent']==40 and rows[2]['ram_MiB']==100 and rows[2]['power_watts']==20
assert rows[2]['requests_s']==2 and rows[2]['errors_s']==1 and rows[2]['error_percent']==50
assert rows[2]['latency_mean_ms']==600 and rows[2]['latency_p95_ms']==1000
assert rows[3]['cpu_percent'] is None and rows[3]['latency_mean_ms'] is None and rows[3]['requests_s']==0
assert (folder/'report.html').exists() and (folder/'per-second.csv').exists()
print('One-second request/latency/error aggregation, UTC alignment, warmup and missing measurements passed')