#!/usr/bin/env python3 """Predecessor effect on the baseline-pair runs (stdlib only): python3 -I baseline-pred.py A.csv [B.csv ...] Inputs are the CSVs written by `baseline-analyze.py RUNROOT --csv X.csv`. Runs are ordered by start time; the predecessor of a run is the run before it in that order, unless the gap between the two start times exceeds 8 minutes (a foreign job ran in between: predecessor "?"). Reports, for vanilla (v1 + v2) and for ours, the all-turn tok/s, ms/round, tokens/round, THP coverage (AnonHugePages of the engine process) and the free memory in blocks of 2 MiB or more before the run, grouped by the predecessor arm, with a Welch t statistic for vanilla-after-ours against vanilla-after-vanilla, and the same split with a linear time trend removed (the residuals of the pooled vanilla ms/round against uptime). """ import csv, math, statistics as st, sys rows = [] for p in sys.argv[1:]: rows += list(csv.DictReader(open(p))) for r in rows: r["t0"] = float(r["t0"]) rows.sort(key=lambda r: r["t0"]) def f(r, k): try: return float(r[k]) except Exception: return None for i, r in enumerate(rows): r["pred"] = "start" if i == 0 else (rows[i - 1]["arm"] if r["t0"] - rows[i - 1]["t0"] < 480 else "?") def welch(a, b): if len(a) < 2 or len(b) < 2: return None va, vb = st.variance(a) / len(a), st.variance(b) / len(b) return (st.mean(a) - st.mean(b)) / math.sqrt(va + vb) if va + vb > 0 else None def grp(label, rs): if not rs: print(" %-26s n=0" % label); return ts = [f(r, "mean") for r in rs]; ms = [f(r, "ms_round") for r in rs if f(r, "ms_round")]; tr = [f(r, "tok_round") for r in rs if f(r, "tok_round")] ah = [f(r, "proc_anonhuge_gib") for r in rs if f(r, "proc_anonhuge_gib") is not None]; bd = [f(r, "pre_buddy9_gib") for r in rs if f(r, "pre_buddy9_gib") is not None] print(" %-26s n=%2d tok/s %.1f (sd %.1f) | ms/round %.2f (sd %.2f) | tok/round %.2f | AnonHuge %s GiB | free>=2M before %s GiB | uptime %.1f..%.1f h" % ( label, len(rs), st.mean(ts), st.stdev(ts) if len(ts) > 1 else 0, st.mean(ms), st.stdev(ms) if len(ms) > 1 else 0, st.mean(tr), "%.1f" % st.mean(ah) if ah else "-", "%.1f" % st.mean(bd) if bd else "-", min(f(r, "uptime_h") for r in rs), max(f(r, "uptime_h") for r in rs))) van = [r for r in rows if r["arm"] in ("v1", "v2")] ours = [r for r in rows if r["arm"] == "ours"] print("runs: %d vanilla, %d ours\n" % (len(van), len(ours))) print("vanilla (v1+v2) by predecessor:") for pr in ("ours", "v1", "v2", "?", "start"): grp("after " + pr, [r for r in van if r["pred"] == pr]) ao = [r for r in van if r["pred"] == "ours"]; av = [r for r in van if r["pred"] in ("v1", "v2")] if len(ao) >= 2 and len(av) >= 2: print(" vanilla after ours - after vanilla: tok/s %+.1f (Welch t %.2f), ms/round %+.2f (Welch t %.2f), n=%d vs %d" % ( st.mean(f(r, "mean") for r in ao) - st.mean(f(r, "mean") for r in av), welch([f(r, "mean") for r in ao], [f(r, "mean") for r in av]), st.mean(f(r, "ms_round") for r in ao) - st.mean(f(r, "ms_round") for r in av), welch([f(r, "ms_round") for r in ao], [f(r, "ms_round") for r in av]), len(ao), len(av))) # time-detrended: residuals of ms/round on uptime over all vanilla runs xs = [f(r, "uptime_h") for r in van if f(r, "ms_round")]; ys = [f(r, "ms_round") for r in van if f(r, "ms_round")] mx, my = st.mean(xs), st.mean(ys); b = sum((x - mx) * (y - my) for x, y in zip(xs, ys)) / sum((x - mx) ** 2 for x in xs); a = my - b * mx print(" vanilla ms/round trend over uptime: %+.2f ms per hour (all vanilla runs, n=%d)" % (b, len(xs))) res = lambda rs: [f(r, "ms_round") - (a + b * f(r, "uptime_h")) for r in rs] print(" residual ms/round after removing that trend: after ours %+.2f (n=%d), after vanilla %+.2f (n=%d), Welch t %.2f" % (st.mean(res(ao)), len(ao), st.mean(res(av)), len(av), welch(res(ao), res(av)) or 0)) print("\nTHP coverage vs free 2 MiB blocks before the run (vanilla): AnonHugePages GiB against free>=2M GiB") for r in van: print(" %-12s pred=%-5s free>=2M %5s -> AnonHuge %5s GiB, thp fallback %5s, tok/s %6.1f ms/round %s" % ( r["name"], r["pred"], "%.1f" % f(r, "pre_buddy9_gib") if f(r, "pre_buddy9_gib") is not None else "-", "%.1f" % f(r, "proc_anonhuge_gib") if f(r, "proc_anonhuge_gib") is not None else "-", r.get("d_thp_fault_fallback", "-"), f(r, "mean"), r.get("ms_round"))) print("\nours by predecessor:") for pr in ("ours", "v1", "v2", "?", "start"): grp("after " + pr, [r for r in ours if r["pred"] == pr])