Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tools/bench/phase_table.mjs

3.9 KiB, 1 run, executable

created by r1870400018:66251, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#!/usr/bin/env node
2// Reads phase_runs.sh's JSONL and prints, for each document, the median over its runs (each run's last
3// attempt) of every phase: whole-run times, then the passes' phases summed over the passes, then each
4// pass's phases. A median is taken for each cell on its own, so a column need not add up to its total;
5// the `sum` line adds the medians of the run's own cells to show how close they come.
6//
7// Usage: phase_table.mjs FILE.jsonl
8import fs from 'node:fs';
9
10const RUN = ['load', 'eval', 'finish', 'write'];
11const PASS = ['realise', 'flow', 'place', 'decorate', 'sink', 'settle'];
12
13function median(xs) {
14 const s = [...xs].sort((a, b) => a - b);
15 const n = s.length;
16 return n ? (n % 2 ? s[(n - 1) / 2] : (s[n / 2 - 1] + s[n / 2]) / 2) : NaN;
17}
18
19const file = process.argv[2];
20const lines = fs.readFileSync(file, 'utf8').split('\n').filter(Boolean).map((l) => JSON.parse(l));
21// Each (doc, run)'s last attempt.
22const last = new Map();
23for (const r of lines) last.set(`${r.doc}#${r.run}`, r);
24const byDoc = new Map();
25for (const r of last.values()) {
26 if (!byDoc.has(r.doc)) byDoc.set(r.doc, []);
27 byDoc.get(r.doc).push(r);
28}
29const ms = (ns) => (ns / 1e6).toFixed(1);
30const out = [];
31for (const [doc, runs] of byDoc) {
32 const ok = runs.filter((r) => r.timings && r.exit_code === 0);
33 const passes = ok.map((r) => r.timings.passes);
34 out.push(`## ${doc}: ${runs.length} runs, ${ok.length} usable, fixpoint passes ${[...new Set(passes)].join('/')}, flagged ${runs.filter((r) => r.flagged).length}, PSI avg10 ${Math.min(...runs.map((r) => Math.min(r.psi_before, r.psi_after)))} to ${Math.max(...runs.map((r) => Math.max(r.psi_before, r.psi_after)))}`);
35 const total = median(ok.map((r) => r.timings.total));
36 const rows = [];
37 const cell = (name, f, n) => {
38 const v = median(ok.map(f));
39 rows.push({ name, v, n: n ? median(ok.map(n)) : null });
40 return v;
41 };
42 let sum = 0;
43 for (const p of RUN) sum += cell(p, (r) => r.timings.run[p].ns, (r) => r.timings.run[p].n);
44 for (const p of PASS) {
45 sum += cell(p, (r) => r.timings.pass.reduce((a, b) => a + b[p].ns, 0), (r) => r.timings.pass.reduce((a, b) => a + b[p].n, 0));
46 }
47 out.push(['phase', 'ms', '% of total', 'entries'].join(' | '));
48 for (const r of rows) out.push([r.name, ms(r.v), ((100 * r.v) / total).toFixed(1), r.n].join(' | '));
49 out.push(['sum of medians', ms(sum), ((100 * sum) / total).toFixed(1), ''].join(' | '));
50 out.push(['total (wall, in process)', ms(total), '100', ''].join(' | '));
51 const eval_ = median(ok.map((r) => r.timings.run.eval.ns + r.timings.run.load.ns));
52 const layout = median(ok.map((r) => r.timings.pass.reduce((a, b) => a + b.realise.ns + b.flow.ns + b.place.ns + b.decorate.ns, 0)));
53 out.push(`load+eval ${ms(eval_)} ms (${((100 * eval_) / total).toFixed(1)}%); realise+flow+place+decorate ${ms(layout)} ms (${((100 * layout) / total).toFixed(1)}%)`);
54 out.push(`cpu user ${median(ok.map((r) => r.user_s)).toFixed(2)} s, sys ${median(ok.map((r) => r.sys_s)).toFixed(2)} s, wall ${median(ok.map((r) => r.wall_s)).toFixed(2)} s, peak rss ${(median(ok.map((r) => r.rss_kb)) / 1024).toFixed(0)} MB, total spread ${ms(Math.min(...ok.map((r) => r.timings.total)))} to ${ms(Math.max(...ok.map((r) => r.timings.total)))} ms`);
55 const sh = ok.find((r) => r.timings.shape);
56 if (sh) {
57 const c = sh.timings.shape;
58 out.push(`shaped-run cache: ${c.entries} entries, ${(c.bytes / 1048576).toFixed(2)} of ${(c.budget / 1048576).toFixed(0)} MiB, ${c.hits} hits, ${c.misses} misses (${((100 * c.hits) / Math.max(1, c.hits + c.misses)).toFixed(1)}% hit), ${c.evictions} evictions`);
59 }
60 const maxPasses = Math.max(...passes);
61 if (maxPasses > 1) {
62 out.push('\nper pass (ms):');
63 out.push(['pass', ...PASS].join(' | '));
64 for (let i = 0; i < maxPasses; i++) {
65 const row = PASS.map((p) => ms(median(ok.filter((r) => r.timings.pass[i]).map((r) => r.timings.pass[i][p].ns))));
66 out.push([i + 1, ...row].join(' | '));
67 }
68 }
69 out.push('');
70}
71process.stdout.write(out.join('\n') + '\n');