Files
leleka/scripts/perf3/parse_spans.py
T

36 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Sum of the serve-profile spans (`DBG profile request: name=ms/count ...`) per replay arm.
usage: parse_spans.py FULL_LOG [span ...] (FULL_LOG: the raw output of a replay job, ~/work/leleka-ttft-runs/<label>.full)
Arms are split by `REPLAY-ARM start label=` lines; every `DBG profile request:` line belongs to one request. Prints, per arm, the total ms and the
call count of each span over all requests (default: the spans that differ between prefill shapes and the decode-phase totals).
"""
import re
import sys
log = sys.argv[1]
wanted = sys.argv[2:] or [
"prefill.read", "prefill.refill", "refill.queue", "refill.sync", "prefill.seed", "prefix.export_kv", "prefix.export_index", "prefix.park_tail",
"prefix.after_prefill", "prefix.park_state", "prefix.import_session", "decode.assemble", "decode.seed_ple", "round.run_window", "round.verify_commit",
"round.apply_pending", "window.ple", "pool.cpu", "round.adapt", "commit.wait", "window.verifier", "round.T", "round.acc",
]
arms = []
cur = None
for line in open(log, errors="replace"):
m = re.search(r"REPLAY-ARM start label=(\S+)", line)
if m:
cur = {"label": m[1], "n": 0, "ms": {}, "cnt": {}}
arms.append(cur)
continue
if cur is None or "DBG profile request:" not in line:
continue
cur["n"] += 1
for name, ms, cnt in re.findall(r"([\w.]+)=([\d.]+)/(\d+)", line.split("DBG profile request:", 1)[1]):
cur["ms"][name] = cur["ms"].get(name, 0.0) + float(ms)
cur["cnt"][name] = cur["cnt"].get(name, 0) + int(cnt)
print(f"{'span':<26}" + "".join(f"{a['label']:>22}" for a in arms))
print(f"{'requests':<26}" + "".join(f"{a['n']:>22}" for a in arms))
for w in wanted:
print(f"{w:<26}" + "".join(f"{a['ms'].get(w, 0.0):>13.0f} ms /{a['cnt'].get(w, 0):>6}" for a in arms))