#!/usr/bin/env python3 """Server-side view of each probe run: per-request server time and the request mix, from the probe server's events.jsonl and summary.jsonl. server-costs.py """ import json, math, sys from pathlib import Path out = Path(sys.argv[1]) events = [json.loads(l) for l in (out / "events.jsonl").open()] def pct(xs, p): s = sorted(xs) return s[max(0, math.ceil(p * len(s)) - 1)] if s else float("nan") print(f"{'run':22} {'POST/s':>7} {'GET/s':>6} {'SSE ev/s':>8} {'SSE B/s':>8} {'POST ms p50/p95':>16} {'GET ms p50/p95':>15} {'CPU ms/s':>9} {'CPU/POST':>9} {'alloc MB/s':>10} {'heap MB':>8}") for line in (out / "summary.jsonl").open(): s = json.loads(line) t0, t1 = s["t0"], s["typed"] + 2000 secs = (t1 - t0) / 1000 win = [e for e in events if t0 <= e["t"] <= t1] posts = [e["end"] - e["t"] for e in win if e["ev"] == "req" and e["method"] == "POST" and e["path"].endswith("/updates")] gets = [e["end"] - e["t"] for e in win if e["ev"] == "req" and e["method"] == "GET" and "/updates?since" in e["path"]] sse = [e for e in win if e["ev"] == "sse"] cpu = s["server_cpu_ms"] print(f"{s['label']:22} {len(posts)/secs:7.1f} {len(gets)/secs:6.1f} {len(sse)/secs:8.1f} {sum(e['bytes'] for e in sse)/secs:8.0f} " f"{pct(posts,.5):7.1f}/{pct(posts,.95):<7.1f} {pct(gets,.5):6.1f}/{pct(gets,.95):<7.1f} {cpu/secs:9.0f} {cpu/max(1,len(posts)):9.1f} " f"{s['server_alloc_mb']/secs:10.1f} {s['server_heap_inuse_mb']:8.0f}")