#!/usr/bin/env python3 """Per-arm, per-request restore and timing lines of a port replay log (q245_port.sh): reused / re-prefilled tokens, TTFT, decode, tokens per round. Offline; no runtime use. The arms of one process run the same requests in the same order on the same loaded model, which makes their TTFT a paired comparison (the first request of each arm meets an empty cache). usage: q245_ttft.py LOG [LOG ...] """ import re, sys for path in sys.argv[1:]: arm, rows = None, {} for line in open(path, errors="replace"): m = re.search(r"REPLAY-ARM start label=(\S+) mode=(\S+)", line) if m: arm = m.group(1) rows[arm] = [] continue m = re.match(r"REPLAY #(\d+) pass=\d+ \S+ arm=\S+ file=(\S+) prompt=(\d+) reused=(\d+) reprefill=(\d+) ttft_ms=([\d.]+) produced=(\d+) rounds=(\d+) tok_per_round=([\d.]+) decode_ms=([\d.]+) decode_tok_s=([\d.]+)", line) if m and arm: rows[arm].append(tuple(float(x) if "." in x else int(x) for x in m.groups()[2:]) + (m.group(2),)) print(path) for arm, rs in rows.items(): if not rs: continue print(f" arm {arm}: requests {len(rs)} re-prefilled tokens {sum(r[2] for r in rs)} sum TTFT {sum(r[3] for r in rs) / 1000:.1f} s median TTFT {sorted(r[3] for r in rs)[len(rs) // 2] / 1000:.2f} s tokens/round {sum(r[4] for r in rs) / max(1, sum(r[5] for r in rs)):.2f}") print(" per request (prompt, reused, re-prefilled, ttft_ms): " + "; ".join(f"{r[0]}/{r[1]}/{r[2]}/{r[3]:.0f}" for r in rs))