#!/usr/bin/env python3 """Per-pass sums of the PREFILL-PROFILE chunk lines of a long-context smoke log (jobs p30 and friends). usage: parse_prof.py LOG [STAGE ...] (default stages: qsa gdn moe inject) A pass starts at its `long-smoke pass=N qsa_late=V` (or `stream_override=V`, or plain `long-smoke prompt tokens=`) marker; chunks are summed per pass, and the chunks are also listed in position buckets (first 25 % / last 25 % of the prompt) so that the position-dependent stages show. """ import re import sys log = sys.argv[1] stages = sys.argv[2:] or ["qsa", "gdn", "moe", "inject"] passes = [] cur = None for line in open(log, errors="replace"): m = re.match(r"long-smoke pass=(\d+) (\w+)=(\S+)", line) if m: cur = {"pass": int(m[1]), "label": f"{m[2]}={m[3]}", "chunks": [], "prefill_ms": None, "prompt": None} passes.append(cur) continue m = re.match(r"long-smoke prefill pass=(\d+) arm=\S+ prompt=(\d+) prompt_ms=([\d.]+)", line) if m and cur is not None: cur["prefill_ms"], cur["prompt"] = float(m[3]), int(m[2]) continue m = re.match(r"PREFILL-PROFILE first=(\d+) tokens=(\d+) total_ms=([\d.]+)", line) if m and cur is not None: row = {"first": int(m[1]), "tokens": int(m[2]), "total": float(m[3])} for s in stages: v = re.search(rf" {re.escape(s)}=([\d.]+)", line) row[s] = float(v[1]) if v else 0.0 cur["chunks"].append(row) for p in passes: c = p["chunks"] if not c: continue q = max(1, len(c) // 4) def tot(rows, key): return sum(r[key] for r in rows) print(f"pass {p['pass']:>2} {p['label']:<14} prompt={p['prompt']} prefill_ms={p['prefill_ms']} chunks={len(c)} sum_chunk_ms={tot(c, 'total'):.0f} " + " ".join(f"{s}={tot(c, s):.0f}" for s in stages) + f" | first quarter {' '.join(f'{s}={tot(c[:q], s) / q:.0f}' for s in stages)} | last quarter {' '.join(f'{s}={tot(c[-q:], s) / q:.0f}' for s in stages)}")