tools/engine-test: per-second process-tree sampler (PSS, CPU, DRM fdinfo GPU), WebKitGTK 6.0 shell, drivers for Servo Nacre and old Nacre, run.sh, analyze.py. docs/engine/engine-comparison.md: method, per-site tables, side-by-side screenshots, caveats, conclusions and what Servo needs for parity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
6.4 KiB
Python
137 lines
6.4 KiB
Python
#!/usr/bin/env python3
|
||
"""Summarize engine comparison runs as Markdown tables.
|
||
|
||
Usage: analyze.py RUNDIR... (each RUNDIR is a run.sh outdir: samples.csv, check-*.json; its name is the engine)
|
||
|
||
Per site (rows whose mark is the site's label): PSS at the end of the settle and its growth over the previous step,
|
||
peak CPU, mean CPU over the last 10 s of the settle (the page has settled), the tree's own GPU (gfx engine busy %,
|
||
mean over the settle) and the tree's VRAM at the end. Then totals: every tab open (end of the last site), the
|
||
60 s idle (mean CPU and GPU of the idle phase, PSS at its end) and the background with no browser (baseline).
|
||
The check columns come from check-<label>.json: document state, element count, and for a page with video the
|
||
playback position (the video must have advanced to count as playing).
|
||
"""
|
||
import csv
|
||
import json
|
||
import os
|
||
import sys
|
||
|
||
|
||
def load(run):
|
||
rows = list(csv.DictReader(open(os.path.join(run, "samples.csv"))))
|
||
for r in rows:
|
||
for k in r:
|
||
if k != "mark":
|
||
r[k] = float(r[k])
|
||
return rows
|
||
|
||
|
||
def mean(xs):
|
||
xs = list(xs)
|
||
return sum(xs) / len(xs) if xs else 0.0
|
||
|
||
|
||
def check(run, label):
|
||
try:
|
||
c = json.load(open(os.path.join(run, f"check-{label}.json")))
|
||
except (OSError, ValueError):
|
||
return "no check"
|
||
if isinstance(c, str):
|
||
c = json.loads(c)
|
||
if "error" in c:
|
||
return "check failed"
|
||
s = f"{c.get('ready')}, {c.get('nodes')} el"
|
||
vids = [v for v in c.get("videos", []) if v.get("w")]
|
||
if vids:
|
||
v = max(vids, key=lambda v: v["t"])
|
||
s += f", video {v['t']:.0f} s" + (" err" if v.get("err") else "")
|
||
if not c.get("title"):
|
||
s += ", no title"
|
||
return s
|
||
|
||
|
||
def summarize(run):
|
||
rows = load(run)
|
||
labels = []
|
||
for r in rows:
|
||
m = r["mark"]
|
||
if m[:2].isdigit() and m not in labels:
|
||
labels.append(m)
|
||
sites = {}
|
||
launch = [r for r in rows if r["mark"] == "launch"]
|
||
prev = launch[-1]["pss_mb"] if launch else 0.0 # the empty browser: the first site's growth is its own
|
||
for label in labels:
|
||
rs = [r for r in rows if r["mark"] == label]
|
||
end = rs[-1]
|
||
sites[label] = dict(pss=end["pss_mb"], grow=end["pss_mb"] - prev, cpu_peak=max(r["cpu_pct"] for r in rs),
|
||
cpu_settled=mean(r["cpu_pct"] for r in rs[-10:]), gfx=mean(r["tree_gfx_pct"] for r in rs),
|
||
vram=end["tree_vram_mb"], procs=int(end["procs"]), check=check(run, label))
|
||
prev = end["pss_mb"]
|
||
idle = [r for r in rows if r["mark"] == "idle"]
|
||
base = [r for r in rows if r["mark"] == "baseline"]
|
||
last = [r for r in rows if r["mark"] == labels[-1]][-1] if labels else None
|
||
totals = dict(
|
||
start_pss=launch[-1]["pss_mb"] if launch else 0,
|
||
all_pss=last["pss_mb"] if last else 0, all_procs=int(last["procs"]) if last else 0,
|
||
all_vram=last["tree_vram_mb"] if last else 0, all_gtt=last["tree_gtt_mb"] if last else 0,
|
||
idle_pss=idle[-1]["pss_mb"] if idle else 0, idle_cpu=mean(r["cpu_pct"] for r in idle[10:]),
|
||
idle_gfx=mean(r["tree_gfx_pct"] for r in idle[10:]), idle_vram=idle[-1]["tree_vram_mb"] if idle else 0,
|
||
peak_pss=max(r["pss_mb"] for r in rows), peak_cpu=max(r["cpu_pct"] for r in rows),
|
||
cpu_s=sum(r["cpu_pct"] for r in rows if r["mark"] not in ("baseline", "done")) / 100,
|
||
base_gpu=mean(r["gpu_busy"] for r in base), base_vram=mean(r["vram_mb"] for r in base),
|
||
run_gpu=mean(r["gpu_busy"] for r in rows if r["mark"] not in ("baseline", "launch", "done")))
|
||
return labels, sites, totals
|
||
|
||
|
||
def main():
|
||
runs = sys.argv[1:]
|
||
data = {os.path.basename(os.path.normpath(r)): summarize(r) for r in runs}
|
||
names = list(data)
|
||
labels = data[names[0]][0]
|
||
for title, key, fmt in [("PSS after settle, MB (growth over the previous step)", None, None),
|
||
("Peak CPU while loading, % of one core", "cpu_peak", "{:.0f}"),
|
||
("Mean CPU over the last 10 s of the settle, % of one core", "cpu_settled", "{:.1f}"),
|
||
("Browser's own GPU (gfx engine busy, mean over the settle), %", "gfx", "{:.1f}"),
|
||
("Browser's VRAM after settle, MB", "vram", "{:.0f}"),
|
||
("Page check at the end of the settle", "check", "{}")]:
|
||
print(f"\n#### {title}\n")
|
||
print("| Site | " + " | ".join(names) + " |")
|
||
print("|---|" + "---|" * len(names))
|
||
for label in labels:
|
||
cells = []
|
||
for n in names:
|
||
s = data[n][1].get(label)
|
||
if s is None:
|
||
cells.append("–")
|
||
elif key is None:
|
||
cells.append(f"{s['pss']:.0f} (+{s['grow']:.0f})")
|
||
else:
|
||
cells.append(fmt.format(s[key]))
|
||
print(f"| {label} | " + " | ".join(cells) + " |")
|
||
print("\n#### Totals\n")
|
||
print("| | " + " | ".join(names) + " |")
|
||
print("|---|" + "---|" * len(names))
|
||
for title, key, fmt in [("PSS of the started browser before the first site (MB)", "start_pss", "{:.0f}"),
|
||
("PSS, all 10 tabs open (MB)", "all_pss", "{:.0f}"),
|
||
("Processes, all tabs open", "all_procs", "{}"),
|
||
("VRAM / GTT of the browser, all tabs open (MB)", None, None),
|
||
("PSS after 60 s idle (MB)", "idle_pss", "{:.0f}"),
|
||
("Mean CPU, idle s 10-60 (% of one core)", "idle_cpu", "{:.1f}"),
|
||
("Browser's GPU, idle s 10-60 (%)", "idle_gfx", "{:.1f}"),
|
||
("Peak PSS (MB)", "peak_pss", "{:.0f}"),
|
||
("Peak CPU (% of one core)", "peak_cpu", "{:.0f}"),
|
||
("CPU time over the whole run (core-seconds)", "cpu_s", "{:.0f}"),
|
||
("Whole card busy: baseline without browser / during run (%)", None, None)]:
|
||
cells = []
|
||
for n in names:
|
||
t = data[n][2]
|
||
if title.startswith("VRAM"):
|
||
cells.append(f"{t['all_vram']:.0f} / {t['all_gtt']:.0f}")
|
||
elif title.startswith("Whole card"):
|
||
cells.append(f"{t['base_gpu']:.0f} / {t['run_gpu']:.0f}")
|
||
else:
|
||
cells.append(fmt.format(t[key]))
|
||
print(f"| {title} | " + " | ".join(cells) + " |")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|