@marver-design/marver 0.26.1 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +198 -0
- package/README.md +12 -4
- package/dist/{anchor-check-l-ny3UzH.mjs → anchor-check-gkxkPAIv.mjs} +1 -1
- package/dist/{board-tree-DRioF94d.mjs → board-tree-BXR8dw4b.mjs} +3 -1
- package/dist/{boards-CGg6piKF.mjs → boards-BHKP5yhI.mjs} +1 -1
- package/dist/{boards-DYG22tOe.mjs → boards-BqUqKNW8.mjs} +4 -4
- package/dist/{build-BDRiO_mP.mjs → build-VgNg4rr8.mjs} +8 -23
- package/dist/cli.mjs +45 -19
- package/dist/{collab-Dxg2trOK.mjs → collab-BEAcXrBb.mjs} +1 -1
- package/dist/{comments-BqXua-XL.mjs → comments-YEU1Zhv9.mjs} +4 -4
- package/dist/{context-HQ4Giw58.mjs → context-Ccjrhr1J.mjs} +3 -3
- package/dist/{daemon-DL6Fwq6D.mjs → daemon-Dc9AH0M3.mjs} +9 -7
- package/dist/detect-C0wpaePX.mjs +125 -0
- package/dist/dev-lock-C_FC70Mu.mjs +65 -0
- package/dist/dev-ri6nAlRp.mjs +1273 -0
- package/dist/exclusive-B1RtpeeP.mjs +150 -0
- package/dist/{init-D8DtrK_F.mjs → init-W0nxR1OY.mjs} +8 -6
- package/dist/{link-BNzLvdhI.mjs → link-CdTgn94Y.mjs} +23 -11
- package/dist/ls-BZ5TAtd5.mjs +38 -0
- package/dist/{manifest-Nl3KSVOk.mjs → manifest-aFyDmL8C.mjs} +2 -2
- package/dist/{marks-DyWMv_Z1.mjs → marks-BF9pNEgH.mjs} +3 -3
- package/dist/{marks-CKgzucHZ.mjs → marks-CnCCfAbD.mjs} +3 -3
- package/dist/{marver-id-gate-BjF6v4bT.mjs → marver-id-gate-D-R0hSt_.mjs} +1 -1
- package/dist/perf-DkAUFT6W.mjs +1319 -0
- package/dist/perf-jam-BaH3Lg0m.mjs +635 -0
- package/dist/plugin-B8UghYuF.mjs +5242 -0
- package/dist/{poster-BdtSKMDm.mjs → poster-BNgafWMK.mjs} +1 -1
- package/dist/{profile-WU9qcbIo.mjs → profile-jIS6BcAs.mjs} +1 -1
- package/dist/{publish-bakes-9RzRToXV.mjs → publish-bakes-38Nja78p.mjs} +3 -3
- package/dist/{queue-29ok5_eZ.mjs → queue-CAM_vNmX.mjs} +1 -1
- package/dist/recover-B8AiI29B.mjs +66 -0
- package/dist/{serve-C8rVheYk.mjs → serve-Dp3nHstu.mjs} +3 -3
- package/dist/{share--oFJ1bCI.mjs → share-Ce4tP7ji.mjs} +1 -1
- package/dist/{shot-XQV7HC9A.mjs → shot-CMQgMVZm.mjs} +1 -1
- package/dist/{shot-DQeR_Pfn.mjs → shot-Ch24tiMO.mjs} +36 -5
- package/dist/slots-CFNnegCc.mjs +478 -0
- package/dist/{sync-DKk-yT1V.mjs → sync-CQdGARJ9.mjs} +4 -3
- package/dist/{work-VvX_JIgl.mjs → work-Bxz-ObF3.mjs} +4 -2
- package/dist/{work-F5u-twpJ.mjs → work-CNhFF9pU.mjs} +5 -3
- package/docs/boards-and-folders.md +3 -1
- package/docs/jam-session.md +57 -2
- package/docs/performance.md +424 -0
- package/package.json +2 -2
- package/src/client/content/index.tsx +3 -0
- package/src/client/content/video.tsx +16 -4
- package/src/client/frame-host/bridge.js +22 -6
- package/src/client/frame-host/main.tsx +17 -5
- package/src/client/shell/App.tsx +188 -26
- package/src/client/shell/BoardList.tsx +5 -5
- package/src/client/shell/Comments.tsx +8 -5
- package/src/client/shell/ContextMenu.tsx +5 -3
- package/src/client/shell/JamSurface.tsx +4 -2
- package/src/client/shell/LockedApp.tsx +8 -5
- package/src/client/shell/Play.tsx +20 -10
- package/src/client/shell/Tip.tsx +3 -1
- package/src/client/shell/Toolbar.tsx +12 -1
- package/src/client/shell/api.ts +233 -0
- package/src/client/shell/app-bridge.ts +254 -0
- package/src/client/shell/app-perf.ts +92 -0
- package/src/client/shell/canvas/Canvas.tsx +141 -21
- package/src/client/shell/canvas/FrameNode.tsx +22 -9
- package/src/client/shell/canvas/admission.ts +31 -9
- package/src/client/shell/canvas/camera-broadcast.ts +15 -5
- package/src/client/shell/canvas/ctl.ts +8 -0
- package/src/client/shell/canvas/frame-registry.ts +28 -2
- package/src/client/shell/canvas/sleep.ts +60 -17
- package/src/client/shell/canvas/updates.ts +2 -1
- package/src/client/shell/comments-store.ts +12 -4
- package/src/client/shell/goto.ts +22 -10
- package/src/client/shell/inset.ts +44 -0
- package/src/client/shell/jam-capture.ts +41 -22
- package/src/client/shell/jam-keys.ts +12 -3
- package/src/client/shell/jam-panel.tsx +9 -3
- package/src/client/shell/jam-queue.ts +3 -3
- package/src/client/shell/jam-session.tsx +14 -8
- package/src/client/shell/jam-voice.ts +55 -15
- package/src/client/shell/legacy-links.ts +2 -2
- package/src/client/shell/main.tsx +18 -1
- package/src/client/shell/marks-ui.tsx +5 -3
- package/src/client/shell/marver-app.ts +21 -0
- package/src/client/shell/notes.ts +8 -1
- package/src/client/shell/perf-run-probe.ts +34 -0
- package/src/client/shell/perf-run.ts +70 -0
- package/src/client/shell/perf.ts +80 -58
- package/src/client/shell/recorder-core.ts +183 -0
- package/src/client/shell/recorder.ts +607 -0
- package/src/client/shell/store.ts +294 -110
- package/src/client/shell/styles.css +72 -15
- package/src/client/shell/unsaved.ts +81 -0
- package/src/client/shell/whiteout-probes.ts +141 -0
- package/src/shared/app-api.ts +205 -0
- package/src/shared/app-perf.ts +308 -0
- package/src/shared/logo-sniff.ts +86 -0
- package/src/shared/machine.ts +132 -0
- package/src/shared/perf-run.ts +177 -0
- package/templates/AGENTS-embedded.md +25 -4
- package/templates/AGENTS-studio.md +25 -4
- package/templates/demo/dark.tsx +1 -1
- package/templates/demo/welcome.tsx +1 -1
- package/templates/instructions/boards.md +3 -1
- package/templates/instructions/welcome.md +6 -3
- package/dist/bake-C-awKgLA.mjs +0 -786
- package/dist/config-Cf7EjAMf.mjs +0 -292
- package/dist/dev-Bw_qYWWq.mjs +0 -755
- package/dist/dev-lock-DWSpa6nj.mjs +0 -179
- package/dist/perf-C75MZ73h.mjs +0 -167
- package/dist/perf-DPbLGhhO.mjs +0 -49
- package/dist/perf-jam-BU3TVrZu.mjs +0 -239
- package/dist/plugin-DkGmZs_r.mjs +0 -2423
|
@@ -0,0 +1,1319 @@
|
|
|
1
|
+
import { i as checkBoardsDir, r as boardFields, s as listBoardFiles } from "./boards-BHKP5yhI.mjs";
|
|
2
|
+
import { f as isBoardName, p as labelOf } from "./board-tree-BXR8dw4b.mjs";
|
|
3
|
+
import { i as readDevInfo } from "./work-CNhFF9pU.mjs";
|
|
4
|
+
import { h as workspaceId, i as marverHome } from "./slots-CFNnegCc.mjs";
|
|
5
|
+
import { d as readRuns, l as readPage, r as readJam, u as readReloads } from "./perf-jam-BaH3Lg0m.mjs";
|
|
6
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
//#region src/shared/app-perf.ts
|
|
10
|
+
/** The file each flavour writes, under `<MARVER_HOME>/perf/`. */
|
|
11
|
+
const APP_LOG = {
|
|
12
|
+
release: "app.jsonl",
|
|
13
|
+
dev: "app-dev.jsonl"
|
|
14
|
+
};
|
|
15
|
+
const KINDS = /* @__PURE__ */ new Set([
|
|
16
|
+
"start",
|
|
17
|
+
"sample",
|
|
18
|
+
"agx",
|
|
19
|
+
"gone",
|
|
20
|
+
"child-gone",
|
|
21
|
+
"gpu-restart",
|
|
22
|
+
"unresponsive",
|
|
23
|
+
"responsive",
|
|
24
|
+
"gpu",
|
|
25
|
+
"power",
|
|
26
|
+
"tab",
|
|
27
|
+
"shown",
|
|
28
|
+
"pressure",
|
|
29
|
+
"unload",
|
|
30
|
+
"unload-skip",
|
|
31
|
+
"unload-effect",
|
|
32
|
+
"reopen",
|
|
33
|
+
"cover",
|
|
34
|
+
"flash",
|
|
35
|
+
"whiteout-candidate",
|
|
36
|
+
"dropped",
|
|
37
|
+
"main-error"
|
|
38
|
+
]);
|
|
39
|
+
const isInt = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
|
|
40
|
+
/**
|
|
41
|
+
* One line of app.jsonl, or null (A3.5): the envelope checked - `v: 1`, a finite `ts`, a known `kind`, an `app` id,
|
|
42
|
+
* a whole `seq`, a `flavour`, a `machine` hash or null. The body is the writer's and is passed on as it is: a
|
|
43
|
+
* reader takes the fields it knows. A line without the envelope (app 0.1's main-error lines) is null.
|
|
44
|
+
*/
|
|
45
|
+
function parseAppLine(line) {
|
|
46
|
+
let r;
|
|
47
|
+
try {
|
|
48
|
+
r = JSON.parse(line);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (!r || typeof r !== "object" || Array.isArray(r)) return null;
|
|
53
|
+
const o = r;
|
|
54
|
+
if (o.v !== 1 || typeof o.ts !== "number" || !Number.isFinite(o.ts)) return null;
|
|
55
|
+
if (typeof o.kind !== "string" || !KINDS.has(o.kind)) return null;
|
|
56
|
+
if (typeof o.app !== "string" || !/^[0-9a-f]{12}$/.test(o.app) || !isInt(o.seq)) return null;
|
|
57
|
+
if (o.flavour !== "release" && o.flavour !== "dev") return null;
|
|
58
|
+
if (o.machine !== null && (typeof o.machine !== "string" || !/^[0-9a-f]{16}$/.test(o.machine))) return null;
|
|
59
|
+
return o;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/cli/perf-app.ts
|
|
63
|
+
/**
|
|
64
|
+
* `marver perf --crashes`, `--flashes`, `--machine` and `--runs` (spec 28 A3.5, A3.8 #22, #23): the app's records
|
|
65
|
+
* (`~/.marver/perf/app.jsonl` and Marver Dev's `app-dev.jsonl`), the repo's `page.jsonl` and `runs.jsonl`, joined by
|
|
66
|
+
* `page` and by workspace; time only for records that cannot carry a page (machine-wide samples), and the output says
|
|
67
|
+
* so. Owners: the recorder stream (`--crashes`, `--flashes`, `--machine`), the headless stream (`--runs`).
|
|
68
|
+
*
|
|
69
|
+
* FROZEN signatures (A3.8 #53). Joins: a repo's workspaces are `workspaceId(root)` and every `ws` in its page.jsonl
|
|
70
|
+
* (a `--recover` run's); a tab record with no page joins by `ws` and time; A1's dedup by `ws/page/seq` stays.
|
|
71
|
+
* `--crashes`, `--flashes` and `--machine` cover 14 days by default; `--flashes` shows marks on this repo's canvases
|
|
72
|
+
* and how many others (`--all` adds them); automatic candidates are their own section, "automatic, not verified".
|
|
73
|
+
*
|
|
74
|
+
* As built: every joined item says how it was joined (`join`): `page` (the app record carries the page id its
|
|
75
|
+
* document's hello sent, and page.jsonl has that page), `page-unrecorded` (it carries a page id and page.jsonl has
|
|
76
|
+
* nothing of that page - a renderer that ended before its first 2 s batch: never another document's page, A3.8 #8),
|
|
77
|
+
* `ws+time` (no page id at all: a 0.27.0 canvas, or none said hello yet - the page of that workspace whose records
|
|
78
|
+
* were the latest before it, within 2 minutes) or `none`. What is machine-wide (the GPU process, a utility process,
|
|
79
|
+
* an app page, the minute before a crash) is joined by time alone and is labelled so. Records of one launch are
|
|
80
|
+
* deduplicated by `flavour/app/seq`. A flash is dated by its mark (`now.ts`, `markTime`), not by its line's `ts`,
|
|
81
|
+
* which is when it was written, about mark + 2 s (A3.8 #13).
|
|
82
|
+
*
|
|
83
|
+
* A gesture record is written at the gesture's end, `ms` long: it spans `[ts - ms, ts]`. A moment inside that span
|
|
84
|
+
* was *during* the gesture (a flash during a zoom, a white-out candidate, a hang); else the gesture is the last one
|
|
85
|
+
* that ended before the moment (a flash: the nearest end within 2 s, before or after it). Every offset is signed,
|
|
86
|
+
* never clamped.
|
|
87
|
+
*
|
|
88
|
+
* The flashes' and candidates' "GPU process events" are the GPU process's alone (`child-gone` of type GPU,
|
|
89
|
+
* `gpu-restart`, `gpu`), whatever a line holds: a renderer's end or a utility process's is not one. A flash's pressure
|
|
90
|
+
* is the reading at the mark only when it was at most 10 s old then (two samples); older, it is unknown.
|
|
91
|
+
*/
|
|
92
|
+
/** Both flavours' app records from `since` (epoch ms), in file order per flavour; a line without the envelope skipped; a line written twice (its launch, flavour and seq) once. */
|
|
93
|
+
function readAppLog(home, since = 0) {
|
|
94
|
+
const out = [];
|
|
95
|
+
const seen = /* @__PURE__ */ new Set();
|
|
96
|
+
for (const f of Object.keys(APP_LOG)) {
|
|
97
|
+
let text = "";
|
|
98
|
+
try {
|
|
99
|
+
text = readFileSync(join(home, "perf", APP_LOG[f]), "utf8");
|
|
100
|
+
} catch {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
for (const l of text.split("\n")) {
|
|
104
|
+
const r = l ? parseAppLine(l) : null;
|
|
105
|
+
if (!r || r.ts < since) continue;
|
|
106
|
+
const k = `${r.flavour}/${r.app}/${r.seq}`;
|
|
107
|
+
if (seen.has(k)) continue;
|
|
108
|
+
seen.add(k);
|
|
109
|
+
out.push(r);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
/** A repo's workspaces (A3.8 #23): its own id and every `ws` its page.jsonl holds - a `--recover` run's effective one among them. */
|
|
115
|
+
function repoWorkspaces(root, page) {
|
|
116
|
+
const out = /* @__PURE__ */ new Set([workspaceId(root)]);
|
|
117
|
+
for (const r of page) if (typeof r.ws === "string") out.add(r.ws);
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
const WS_TIME_MS = 12e4;
|
|
121
|
+
/** A flash joins the gesture it fell in, else the one whose end is nearest within this, before or after (A3.3). */
|
|
122
|
+
const FLASH_GESTURE_MS = 2e3;
|
|
123
|
+
/**
|
|
124
|
+
* The page records of the moment's page. A record with a page id joins that page or nothing: a document never gets
|
|
125
|
+
* another document's records (A3.8 #8) - with none of its own (it ended before its first batch) it is
|
|
126
|
+
* `page-unrecorded`. Only a record with no page id joins by workspace and time: that workspace's page whose records
|
|
127
|
+
* were the latest before `ts`, within 2 minutes.
|
|
128
|
+
*/
|
|
129
|
+
function pageOf(rec, page, ts) {
|
|
130
|
+
if (typeof rec.page === "string") {
|
|
131
|
+
const records = page.filter((r) => r.page === rec.page);
|
|
132
|
+
return {
|
|
133
|
+
join: records.length ? "page" : "page-unrecorded",
|
|
134
|
+
records,
|
|
135
|
+
page: rec.page
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (typeof rec.ws === "string") {
|
|
139
|
+
let best = null;
|
|
140
|
+
for (const r of page) {
|
|
141
|
+
if (r.ws !== rec.ws || typeof r.ts !== "number" || r.ts > ts || ts - r.ts > WS_TIME_MS) continue;
|
|
142
|
+
if (!best || r.ts > best.ts) best = {
|
|
143
|
+
page: r.page,
|
|
144
|
+
ts: r.ts
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (best) return {
|
|
148
|
+
join: "ws+time",
|
|
149
|
+
records: page.filter((r) => r.page === best.page),
|
|
150
|
+
page: best.page
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
join: "none",
|
|
155
|
+
records: []
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* When a flash was marked: its `now` sample's `ts`, taken in the mark's turn (A3.8 #13 step 2). The line's own `ts`
|
|
160
|
+
* is when it was written - after the +1 s GPU window, the AGX read and the picture, so about mark + 2 s - and is
|
|
161
|
+
* used only for a record with no `now`.
|
|
162
|
+
*/
|
|
163
|
+
function markTime(x) {
|
|
164
|
+
const t = x.now?.ts;
|
|
165
|
+
return typeof t === "number" && Number.isFinite(t) && t > 0 ? t : x.ts;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The gesture a moment fell in - the latest to start, should two hold it - else the last that ended before it, or
|
|
169
|
+
* with `withinMs` the one whose end is nearest the moment within that, before or after.
|
|
170
|
+
*/
|
|
171
|
+
function gestureAt(records, ts, withinMs) {
|
|
172
|
+
const gs = records.filter((r) => r.kind === "gesture" && typeof r.ts === "number");
|
|
173
|
+
const start = (g) => typeof g.ms === "number" && g.ms >= 0 ? g.ts - g.ms : g.ts;
|
|
174
|
+
const inside = gs.filter((g) => start(g) <= ts && ts <= g.ts).sort((a, b) => start(a) - start(b)).at(-1);
|
|
175
|
+
const near = (withinMs === void 0 ? gs.filter((g) => g.ts <= ts) : gs.filter((g) => Math.abs(g.ts - ts) <= withinMs)).sort((a, b) => Math.abs(a.ts - ts) - Math.abs(b.ts - ts))[0];
|
|
176
|
+
const g = inside ?? near;
|
|
177
|
+
if (!g) return void 0;
|
|
178
|
+
return {
|
|
179
|
+
type: g.type,
|
|
180
|
+
...typeof g.ms === "number" ? { ms: g.ms } : {},
|
|
181
|
+
...typeof g.p95 === "number" ? { p95: g.p95 } : {},
|
|
182
|
+
during: g === inside,
|
|
183
|
+
...typeof g.ms === "number" && g.ms >= 0 ? { startedMsBefore: ts - start(g) } : {},
|
|
184
|
+
endedMsBefore: ts - g.ts
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** The page half at `ts`: the load whose commit came last before it (it owned the geometry), settled or not then; the gesture it fell in, or the last before it (`gestureWithinMs`: the nearest end within that, either side). */
|
|
188
|
+
function momentOf(rec, page, ts = rec.ts, o = {}) {
|
|
189
|
+
const { join, records, page: id } = pageOf(rec, page, ts);
|
|
190
|
+
if (join === "none" || join === "page-unrecorded") return {
|
|
191
|
+
join,
|
|
192
|
+
...id ? { page: id } : {}
|
|
193
|
+
};
|
|
194
|
+
const out = {
|
|
195
|
+
join,
|
|
196
|
+
...id ? { page: id } : {}
|
|
197
|
+
};
|
|
198
|
+
const owning = records.filter((r) => r.kind === "commit" && r.ts <= ts).sort((a, b) => a.ts - b.ts).at(-1);
|
|
199
|
+
if (owning) {
|
|
200
|
+
const l = loadsSummary(records).find((x) => x.load === owning.load);
|
|
201
|
+
const settled = records.find((r) => r.load === owning.load && r.kind === "settled" && r.ts <= ts);
|
|
202
|
+
if (l) out.load = {
|
|
203
|
+
id: l.load,
|
|
204
|
+
...l.cause ? { cause: l.cause } : {},
|
|
205
|
+
settled: !!settled,
|
|
206
|
+
...settled ? { settledMs: settled.ms } : {},
|
|
207
|
+
state: l.state
|
|
208
|
+
};
|
|
209
|
+
if (l?.board) out.board = l.board;
|
|
210
|
+
}
|
|
211
|
+
const g = gestureAt(records, ts, o.gestureWithinMs);
|
|
212
|
+
if (g) out.gesture = g;
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
/** The GPU process's own events (A3.3, A3.8 #13): its end, its silent replacement, a feature change - never a renderer's or a utility process's. */
|
|
216
|
+
const isGpuProcessEvent = (e) => e?.kind === "gpu-restart" || e?.kind === "gpu" || e?.kind === "child-gone" && e.type === "GPU";
|
|
217
|
+
/** The minute before a moment, from the same launch (by time: machine-wide). */
|
|
218
|
+
function minuteBefore(app, rec, pid) {
|
|
219
|
+
const s = app.filter((r) => r.kind === "sample" && r.app === rec.app && r.flavour === rec.flavour && r.ts <= rec.ts).at(-1);
|
|
220
|
+
if (!s) return void 0;
|
|
221
|
+
const p = typeof pid === "number" ? s.procs.find((x) => x.pid === pid) : void 0;
|
|
222
|
+
return {
|
|
223
|
+
join: "time",
|
|
224
|
+
ts: s.ts,
|
|
225
|
+
msBefore: rec.ts - s.ts,
|
|
226
|
+
pressure: s.pressure.last,
|
|
227
|
+
pressureMax: s.pressure.max,
|
|
228
|
+
thermal: s.thermal,
|
|
229
|
+
canvasMB: s.canvases.memMB.last,
|
|
230
|
+
gpuProcessRssMB: s.gpu?.gpuProcessRssMB.last ?? null,
|
|
231
|
+
...p ? {
|
|
232
|
+
procMB: p.footprintMB.last ?? p.rssMB.last,
|
|
233
|
+
procCpu: p.cpu.last
|
|
234
|
+
} : {}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const ofWs = (r, ws) => typeof r.ws === "string" && ws.has(r.ws);
|
|
238
|
+
/** `--crashes`: gone (not ours) and unresponsive on this repo's canvases, joined by page; child-gone and gpu-restart by time. */
|
|
239
|
+
function crashesSummary(app, page, workspaces, home) {
|
|
240
|
+
const crashes = [];
|
|
241
|
+
const hangs = [];
|
|
242
|
+
const byTime = [];
|
|
243
|
+
for (const r of app) {
|
|
244
|
+
const x = r;
|
|
245
|
+
if (r.kind === "gone") {
|
|
246
|
+
if (x.role !== "canvas") {
|
|
247
|
+
byTime.push({
|
|
248
|
+
at: r.ts,
|
|
249
|
+
flavour: r.flavour,
|
|
250
|
+
join: "time",
|
|
251
|
+
what: "app-page-gone",
|
|
252
|
+
text: `the app's ${x.role} page's renderer ended: ${x.reason}${typeof x.exitCode === "number" ? ` (exit ${x.exitCode})` : ""}`,
|
|
253
|
+
record: x
|
|
254
|
+
});
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (x.ours === true || !ofWs(x, workspaces)) continue;
|
|
258
|
+
crashes.push({
|
|
259
|
+
at: r.ts,
|
|
260
|
+
flavour: r.flavour,
|
|
261
|
+
app: r.app,
|
|
262
|
+
...x.tab ? { tab: x.tab } : {},
|
|
263
|
+
...x.ws ? { ws: x.ws } : {},
|
|
264
|
+
...typeof x.commit === "number" ? { commit: x.commit } : {},
|
|
265
|
+
pid: x.pid,
|
|
266
|
+
born: x.born,
|
|
267
|
+
reason: x.reason,
|
|
268
|
+
exitCode: x.exitCode,
|
|
269
|
+
pressure: x.pressure ?? null,
|
|
270
|
+
...momentOf(x, page),
|
|
271
|
+
before: minuteBefore(app, r, x.pid)
|
|
272
|
+
});
|
|
273
|
+
} else if (r.kind === "unresponsive") {
|
|
274
|
+
if (x.role !== "canvas" || !ofWs(x, workspaces)) continue;
|
|
275
|
+
const back = app.find((y) => y.kind === "responsive" && y.app === r.app && y.flavour === r.flavour && y.tab === x.tab && y.pid === x.pid && y.ts >= r.ts);
|
|
276
|
+
hangs.push({
|
|
277
|
+
at: r.ts,
|
|
278
|
+
flavour: r.flavour,
|
|
279
|
+
...x.tab ? { tab: x.tab } : {},
|
|
280
|
+
...x.ws ? { ws: x.ws } : {},
|
|
281
|
+
pid: x.pid,
|
|
282
|
+
role: x.role,
|
|
283
|
+
...back ? { respondedAfterMs: back.ts - r.ts } : {},
|
|
284
|
+
...momentOf(x, page)
|
|
285
|
+
});
|
|
286
|
+
} else if (r.kind === "child-gone") byTime.push({
|
|
287
|
+
at: r.ts,
|
|
288
|
+
flavour: r.flavour,
|
|
289
|
+
join: "time",
|
|
290
|
+
what: "child-gone",
|
|
291
|
+
text: `${x.type === "GPU" ? "the GPU process" : `a ${x.name ?? x.type} process`} ended: ${x.reason}${typeof x.exitCode === "number" ? ` (exit ${x.exitCode})` : ""}`,
|
|
292
|
+
record: x
|
|
293
|
+
});
|
|
294
|
+
else if (r.kind === "gpu-restart") byTime.push({
|
|
295
|
+
at: r.ts,
|
|
296
|
+
flavour: r.flavour,
|
|
297
|
+
join: "time",
|
|
298
|
+
what: "gpu-restart",
|
|
299
|
+
text: `a new GPU process (pid ${x.pid}) with no ending reported${x.was ? `, after pid ${x.was.pid}` : ""}`,
|
|
300
|
+
record: x
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
let dumps = 0;
|
|
304
|
+
try {
|
|
305
|
+
dumps = readdirSync(join(home, "perf", "crashpad", "completed")).filter((n) => n.endsWith(".dmp")).length;
|
|
306
|
+
} catch {}
|
|
307
|
+
const byAt = (a, b) => a.at - b.at;
|
|
308
|
+
return {
|
|
309
|
+
crashes: crashes.sort(byAt),
|
|
310
|
+
hangs: hangs.sort(byAt),
|
|
311
|
+
byTime: byTime.sort(byAt),
|
|
312
|
+
dumps
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** `--flashes`: marks on this repo's canvases (all with `all`), joined by page to the board and the gesture the mark fell in or ended within 2 s of it; candidates apart. */
|
|
316
|
+
function flashesSummary(app, page, workspaces, o = {}) {
|
|
317
|
+
const marks = [];
|
|
318
|
+
const candidates = [];
|
|
319
|
+
let others = 0;
|
|
320
|
+
for (const r of app) {
|
|
321
|
+
const x = r;
|
|
322
|
+
if (r.kind === "flash") {
|
|
323
|
+
const mine = ofWs(x, workspaces);
|
|
324
|
+
if (!mine) {
|
|
325
|
+
others++;
|
|
326
|
+
if (!o.all) continue;
|
|
327
|
+
}
|
|
328
|
+
const at = markTime(x);
|
|
329
|
+
const p = x.pressure;
|
|
330
|
+
const age = typeof p?.at === "number" && p.at > 0 ? at - p.at : void 0;
|
|
331
|
+
const fresh = age === void 0 || age <= 1e4;
|
|
332
|
+
const picture = typeof x.picture === "string" ? o.home ? join(o.home, "perf", x.picture) : x.picture : null;
|
|
333
|
+
marks.push({
|
|
334
|
+
at,
|
|
335
|
+
id: x.id,
|
|
336
|
+
via: x.via,
|
|
337
|
+
flavour: r.flavour,
|
|
338
|
+
...x.tab ? { tab: x.tab } : {},
|
|
339
|
+
...x.ws ? { ws: x.ws } : {},
|
|
340
|
+
mine,
|
|
341
|
+
recorder: !!x.recorder,
|
|
342
|
+
gpuEvents: Array.isArray(x.gpuEvents) ? x.gpuEvents.filter(isGpuProcessEvent).map((e) => ({
|
|
343
|
+
kind: e.kind,
|
|
344
|
+
ts: e.ts
|
|
345
|
+
})) : [],
|
|
346
|
+
pressure: fresh ? p?.level ?? null : null,
|
|
347
|
+
...age !== void 0 ? { pressureAgeMs: age } : {},
|
|
348
|
+
thermal: x.thermal ?? "unknown",
|
|
349
|
+
gpuProcessRssMB: x.now?.gpu?.gpuProcessRssMB ?? null,
|
|
350
|
+
agx: x.agx ?? {},
|
|
351
|
+
picture,
|
|
352
|
+
...x.pictureWhy ? { pictureWhy: x.pictureWhy } : {},
|
|
353
|
+
...picture && o.home && !existsSync(picture) ? { picturePruned: true } : {},
|
|
354
|
+
...momentOf(x, page, at, { gestureWithinMs: FLASH_GESTURE_MS })
|
|
355
|
+
});
|
|
356
|
+
} else if (r.kind === "whiteout-candidate") {
|
|
357
|
+
if (!ofWs(x, workspaces) && !o.all) continue;
|
|
358
|
+
const observedAt = Array.isArray(x.observedAt) ? x.observedAt : [];
|
|
359
|
+
candidates.push({
|
|
360
|
+
at: observedAt[0] ?? r.ts,
|
|
361
|
+
flavour: r.flavour,
|
|
362
|
+
...x.tab ? { tab: x.tab } : {},
|
|
363
|
+
...x.ws ? { ws: x.ws } : {},
|
|
364
|
+
...typeof x.gesture === "number" ? { gestureSeq: x.gesture } : {},
|
|
365
|
+
observedAt,
|
|
366
|
+
rateHz: x.rateHz,
|
|
367
|
+
samples: x.samples,
|
|
368
|
+
skipped: x.skipped,
|
|
369
|
+
inconclusive: x.inconclusive,
|
|
370
|
+
gpuEvents: Array.isArray(x.gpuEvents) ? x.gpuEvents.filter(isGpuProcessEvent).length : 0,
|
|
371
|
+
...momentOf(x, page, observedAt[0] ?? r.ts)
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const byAt = (a, b) => a.at - b.at;
|
|
376
|
+
return {
|
|
377
|
+
marks: marks.sort(byAt),
|
|
378
|
+
others,
|
|
379
|
+
candidates: candidates.sort(byAt)
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
/** `--machine`: the profiles under perf/machine, by hostHash, which is current, and how many records and runs name each. */
|
|
383
|
+
function machineSummary(home, app, runs) {
|
|
384
|
+
const dir = join(home, "perf", "machine");
|
|
385
|
+
let names = [];
|
|
386
|
+
try {
|
|
387
|
+
names = readdirSync(dir).filter((n) => /^[0-9a-f]{16}\.json$/.test(n));
|
|
388
|
+
} catch {}
|
|
389
|
+
const named = /* @__PURE__ */ new Map();
|
|
390
|
+
for (const r of app) if (r.machine) named.set(r.machine, (named.get(r.machine) ?? 0) + 1);
|
|
391
|
+
const ran = /* @__PURE__ */ new Map();
|
|
392
|
+
for (const l of runs) if (typeof l.machine === "string") ran.set(l.machine, (ran.get(l.machine) ?? 0) + 1);
|
|
393
|
+
const current = /* @__PURE__ */ new Set();
|
|
394
|
+
for (const f of Object.keys(APP_LOG)) {
|
|
395
|
+
const last = app.filter((r) => r.flavour === f && r.machine).at(-1);
|
|
396
|
+
if (last?.machine) current.add(last.machine);
|
|
397
|
+
}
|
|
398
|
+
const lastRun = [...runs].sort((a, b) => a.ts - b.ts).at(-1);
|
|
399
|
+
if (lastRun?.machine) current.add(lastRun.machine);
|
|
400
|
+
const profiles = [];
|
|
401
|
+
for (const n of names) {
|
|
402
|
+
const hash = n.slice(0, 16);
|
|
403
|
+
let p = {};
|
|
404
|
+
let mtime = 0;
|
|
405
|
+
try {
|
|
406
|
+
p = JSON.parse(readFileSync(join(dir, n), "utf8"));
|
|
407
|
+
mtime = statSync(join(dir, n)).mtimeMs;
|
|
408
|
+
} catch {}
|
|
409
|
+
const kind = p.kind === "app" || p.kind === "headless" ? p.kind : "unknown";
|
|
410
|
+
const host = p.host ?? {};
|
|
411
|
+
profiles.push({
|
|
412
|
+
hash,
|
|
413
|
+
kind,
|
|
414
|
+
hostHash: typeof p.hostHash === "string" ? p.hostHash : null,
|
|
415
|
+
current: current.has(hash),
|
|
416
|
+
records: named.get(hash) ?? 0,
|
|
417
|
+
runs: ran.get(hash) ?? 0,
|
|
418
|
+
mtime,
|
|
419
|
+
...host.chip ? { chip: host.chip } : {},
|
|
420
|
+
...host.model ? { model: host.model } : {},
|
|
421
|
+
...host.os ? { os: host.os } : {},
|
|
422
|
+
...p.electron ? { electron: `Electron ${p.electron}, Chrome ${p.chrome}` } : {},
|
|
423
|
+
...Array.isArray(p.displays) ? { displays: p.displays.map((d) => `${d.internal ? "built-in" : "external"} ${d.pixels?.[0]}x${d.pixels?.[1]} @ ${d.hz} Hz`).join(", ") } : {},
|
|
424
|
+
...p.gpu ? { gpu: `${p.gpu.renderer}${p.gpu.gpuCores !== "unknown" ? `, ${p.gpu.gpuCores} cores` : ""}` } : {},
|
|
425
|
+
...p.power ? { power: typeof p.power === "string" ? p.power : p.power.source } : {}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
profiles.sort((a, b) => Number(b.current) - Number(a.current) || b.mtime - a.mtime);
|
|
429
|
+
const byHost = /* @__PURE__ */ new Map();
|
|
430
|
+
for (const p of profiles) byHost.set(p.hostHash, [...byHost.get(p.hostHash) ?? [], p.hash]);
|
|
431
|
+
return {
|
|
432
|
+
profiles,
|
|
433
|
+
byHost: [...byHost].map(([hostHash, ps]) => ({
|
|
434
|
+
hostHash,
|
|
435
|
+
profiles: ps
|
|
436
|
+
}))
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
/** `--runs`: comparisons inside one cohort (script, board, chrome, flags, machine, power, slow, bakes), by inputs; `against` two runs of one cohort. */
|
|
440
|
+
function runsSummary(runs, o = {}) {
|
|
441
|
+
const ordered = [...runs].sort((a, b) => a.ts - b.ts);
|
|
442
|
+
const comparable = (r) => r.valid && !r.overlapped;
|
|
443
|
+
const cohorts = /* @__PURE__ */ new Map();
|
|
444
|
+
for (const r of ordered.filter(comparable)) {
|
|
445
|
+
const k = cohortKey(r);
|
|
446
|
+
cohorts.set(k, [...cohorts.get(k) ?? [], r]);
|
|
447
|
+
}
|
|
448
|
+
const boards = [];
|
|
449
|
+
for (const list of cohorts.values()) {
|
|
450
|
+
const latest = list[list.length - 1];
|
|
451
|
+
const before = list.slice(0, -1).reverse();
|
|
452
|
+
const same = before.find((r) => r.inputs?.hash === latest.inputs?.hash);
|
|
453
|
+
const other = before.find((r) => r.inputs?.hash !== latest.inputs?.hash);
|
|
454
|
+
boards.push({
|
|
455
|
+
board: latest.board,
|
|
456
|
+
cohort: cohortOf(latest),
|
|
457
|
+
runs: list.length,
|
|
458
|
+
latest: brief(latest),
|
|
459
|
+
...same ? { sameInputs: {
|
|
460
|
+
...compare(same, latest),
|
|
461
|
+
within10: within(same, latest)
|
|
462
|
+
} } : {},
|
|
463
|
+
...other ? { afterChange: compare(other, latest) } : {}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
boards.sort((a, b) => a.board.localeCompare(b.board) || b.latest.ts - a.latest.ts);
|
|
467
|
+
const out = {
|
|
468
|
+
boards,
|
|
469
|
+
invalid: ordered.filter((r) => !r.valid),
|
|
470
|
+
overlapped: ordered.filter((r) => r.valid && r.overlapped)
|
|
471
|
+
};
|
|
472
|
+
if (o.against) {
|
|
473
|
+
const base = ordered.find((r) => r.run === o.against);
|
|
474
|
+
if (!base) out.against = {
|
|
475
|
+
run: o.against,
|
|
476
|
+
error: "no such run in the window"
|
|
477
|
+
};
|
|
478
|
+
else {
|
|
479
|
+
const latest = [...ordered].reverse().find((r) => r.run !== base.run && r.ts > base.ts && cohortKey(r) === cohortKey(base) && comparable(r));
|
|
480
|
+
out.against = latest && comparable(base) ? {
|
|
481
|
+
run: base.run,
|
|
482
|
+
...compare(base, latest),
|
|
483
|
+
within10: within(base, latest)
|
|
484
|
+
} : {
|
|
485
|
+
run: base.run,
|
|
486
|
+
error: !comparable(base) ? `run ${base.run} is ${base.valid ? "overlapped" : `invalid (${base.invalidReason})`}: never compared` : "no later valid run of its cohort (script, board, Chrome, flags, machine, power, --slow, bakes) - pass the earlier run"
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return out;
|
|
491
|
+
}
|
|
492
|
+
/** Runs compare only inside one cohort (A3.8 #22). */
|
|
493
|
+
const cohortOf = (r) => ({
|
|
494
|
+
script: r.script,
|
|
495
|
+
board: r.board,
|
|
496
|
+
chrome: r.chrome,
|
|
497
|
+
flags: r.flags,
|
|
498
|
+
machine: r.machine,
|
|
499
|
+
power: r.power,
|
|
500
|
+
slow: r.slow,
|
|
501
|
+
bakes: r.bakes
|
|
502
|
+
});
|
|
503
|
+
const cohortKey = (r) => JSON.stringify(cohortOf(r));
|
|
504
|
+
const brief = (r) => ({
|
|
505
|
+
run: r.run,
|
|
506
|
+
ts: r.ts,
|
|
507
|
+
inputs: r.inputs?.hash ?? null,
|
|
508
|
+
loadToSettledMs: r.loadToSettledMs,
|
|
509
|
+
p50: r.p50,
|
|
510
|
+
p95: r.p95,
|
|
511
|
+
over33ms: r.over33ms,
|
|
512
|
+
heapPeakMB: r.heapPeakMB,
|
|
513
|
+
moves: r.moves
|
|
514
|
+
});
|
|
515
|
+
const diff = (a, b) => a === null || b === null ? null : Math.round((b - a) * 10) / 10;
|
|
516
|
+
function compare(a, b) {
|
|
517
|
+
return {
|
|
518
|
+
from: brief(a),
|
|
519
|
+
to: brief(b),
|
|
520
|
+
deltas: {
|
|
521
|
+
loadToSettledMs: diff(a.loadToSettledMs, b.loadToSettledMs),
|
|
522
|
+
p95: diff(a.p95, b.p95),
|
|
523
|
+
over33ms: diff(a.over33ms, b.over33ms),
|
|
524
|
+
heapPeakMB: diff(a.heapPeakMB, b.heapPeakMB)
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
/** Two runs agree: `loadToSettledMs` and `p95` each within 10 % of the earlier one's (A3.7). */
|
|
529
|
+
function within(a, b, pct = 10) {
|
|
530
|
+
const ok = (x, y) => x !== null && y !== null && Math.abs(y - x) <= Math.max(Math.abs(x), 1) * pct / 100;
|
|
531
|
+
return ok(a.loadToSettledMs, b.loadToSettledMs) && ok(a.p95, b.p95);
|
|
532
|
+
}
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/cli/perf.ts
|
|
535
|
+
/**
|
|
536
|
+
* `marver perf` (spec 26 Part 1): the reload log read back - per edited file, the frames it reached
|
|
537
|
+
* and how; every page-wide reload (sent or dropped) and every time the canvas page itself booted,
|
|
538
|
+
* with what came just before; the slowest frames to settle; one line per board load. Reads
|
|
539
|
+
* design/.local/perf/reloads.jsonl, and page.jsonl for the loads (`--loads`: each load in full, spec 28 A1.8).
|
|
540
|
+
*/
|
|
541
|
+
function perfCommand(root, opts) {
|
|
542
|
+
if (opts.jam) return jamPerf(root, opts);
|
|
543
|
+
if (opts.loads) return loadsPerf(root, opts);
|
|
544
|
+
if (opts.runs) return runsPerf(root, opts);
|
|
545
|
+
if (opts.crashes) return crashesPerf(root, opts);
|
|
546
|
+
if (opts.flashes) return flashesPerf(root, opts);
|
|
547
|
+
if (opts.machine) return machinePerf(root, opts);
|
|
548
|
+
const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
|
|
549
|
+
const since = Date.now() - minutes * 6e4;
|
|
550
|
+
const log = readReloads(root, since);
|
|
551
|
+
const { records: pageRecords, runLoads } = ownLoads(readPage(root, since));
|
|
552
|
+
const loads = loadsSummary(pageRecords);
|
|
553
|
+
const files = /* @__PURE__ */ new Map();
|
|
554
|
+
for (const e of log) if (e.kind === "update") {
|
|
555
|
+
const f = files.get(e.file ?? "(no file)") ?? {
|
|
556
|
+
edits: 0,
|
|
557
|
+
reload: /* @__PURE__ */ new Set(),
|
|
558
|
+
inPlace: /* @__PURE__ */ new Set()
|
|
559
|
+
};
|
|
560
|
+
f.edits++;
|
|
561
|
+
for (const id of e.reload ?? []) f.reload.add(id);
|
|
562
|
+
for (const id of e.inPlace ?? []) f.inPlace.add(id);
|
|
563
|
+
files.set(e.file ?? "(no file)", f);
|
|
564
|
+
}
|
|
565
|
+
const reloads = log.filter((e) => e.kind === "full-reload");
|
|
566
|
+
const boots = log.flatMap((e, i) => e.kind === "shell-boot" ? [{
|
|
567
|
+
ts: e.ts,
|
|
568
|
+
before: log.slice(Math.max(0, i - 3), i).filter((x) => x.kind !== "ready" && x.kind !== "settled")
|
|
569
|
+
}] : []);
|
|
570
|
+
const slow = log.filter((e) => e.kind === "settled" && typeof e.ms === "number").sort((a, b) => b.ms - a.ms).slice(0, 5);
|
|
571
|
+
const booted = log.filter((e) => e.kind === "ready");
|
|
572
|
+
const by = (c) => booted.filter((e) => e.cause === c).length;
|
|
573
|
+
const reloaded = by("job");
|
|
574
|
+
if (opts.json) {
|
|
575
|
+
console.log(JSON.stringify({
|
|
576
|
+
minutes,
|
|
577
|
+
files: Object.fromEntries([...files].map(([k, v]) => [k, {
|
|
578
|
+
edits: v.edits,
|
|
579
|
+
reached: [...v.reload],
|
|
580
|
+
inPlace: [...v.inPlace]
|
|
581
|
+
}])),
|
|
582
|
+
documents: {
|
|
583
|
+
afterEdit: reloaded,
|
|
584
|
+
byHand: by("manual"),
|
|
585
|
+
retried: by("retry"),
|
|
586
|
+
self: by("self"),
|
|
587
|
+
first: by("first")
|
|
588
|
+
},
|
|
589
|
+
reloads,
|
|
590
|
+
boots,
|
|
591
|
+
slow,
|
|
592
|
+
loads: loads.map((l) => ({
|
|
593
|
+
at: l.at,
|
|
594
|
+
board: l.board,
|
|
595
|
+
cause: l.cause,
|
|
596
|
+
state: l.state,
|
|
597
|
+
settledMs: l.settledMs,
|
|
598
|
+
cut: l.cut,
|
|
599
|
+
...l.mountedAfterCut ? { mountedAfterCut: true } : {},
|
|
600
|
+
moves: l.moves.count,
|
|
601
|
+
late: l.moves.late.count,
|
|
602
|
+
errors: l.errors.length,
|
|
603
|
+
lateErrors: l.errors.filter((e) => e.late).length
|
|
604
|
+
})),
|
|
605
|
+
runLoads
|
|
606
|
+
}, null, 2));
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const t = (ts) => new Date(ts).toLocaleTimeString();
|
|
610
|
+
console.log(`last ${minutes} min - design/.local/perf/reloads.jsonl`);
|
|
611
|
+
console.log(`\nedits (${files.size} files)`);
|
|
612
|
+
for (const [file, f] of [...files].sort((a, b) => b[1].edits - a[1].edits)) console.log(` ${file} ${f.edits}x reached ${f.reload.size} frame${f.reload.size === 1 ? "" : "s"}${f.inPlace.size ? `, ${f.inPlace.size} updated in place` : ""}`);
|
|
613
|
+
console.log(`\nframe documents booted: ${reloaded} after an edit (a frame off screen reloads when it comes into view), ${by("first")} first loads, ${by("manual")} by hand, ${by("retry")} watchdog retries, ${by("self")} reloaded themselves`);
|
|
614
|
+
console.log(`\npage-wide reloads: ${reloads.filter((r) => r.passed).length} sent (dependency rebuilds), ${reloads.filter((r) => !r.passed).length} dropped`);
|
|
615
|
+
for (const r of reloads) console.log(` ${t(r.ts)} ${r.passed ? "sent " : "dropped"} ${r.triggeredBy ?? "no file named"}`);
|
|
616
|
+
console.log(`\ncanvas page loads: ${boots.length}`);
|
|
617
|
+
for (const b of boots) console.log(` ${t(b.ts)}${b.before.length ? ` after: ${b.before.map((x) => x.kind + (x.file ? ` ${x.file}` : "")).join(", ")}` : ""}`);
|
|
618
|
+
if (slow.length) {
|
|
619
|
+
console.log("\nslowest to settle");
|
|
620
|
+
for (const s of slow) console.log(` ${s.frame} ${s.ms} ms`);
|
|
621
|
+
}
|
|
622
|
+
if (loads.length || runLoads) console.log(`\nboard loads: ${loads.length} (--loads: each in full)`);
|
|
623
|
+
if (runLoads) console.log(`(${runLoads} headless run load${runLoads === 1 ? "" : "s"} not shown: npx marver perf --runs)`);
|
|
624
|
+
if (loads.length) {
|
|
625
|
+
const name = namer(root);
|
|
626
|
+
const w = Math.max(...loads.map((l) => name(l.board).length));
|
|
627
|
+
for (const l of loads) {
|
|
628
|
+
const bits = [
|
|
629
|
+
endOf(l),
|
|
630
|
+
...l.moves.count || l.moves.late.count ? [`${l.moves.count} move${l.moves.count === 1 ? "" : "s"}${l.moves.late.count ? ` (${l.moves.late.count} late)` : ""}`] : [],
|
|
631
|
+
...l.errors.length ? [`${l.errors.length} error${l.errors.length === 1 ? "" : "s"}${lateErrors(l) ? ` (${lateErrors(l)} late)` : ""}`] : []
|
|
632
|
+
];
|
|
633
|
+
console.log(` ${t(l.at)} ${name(l.board).padEnd(w)} ${(l.cause ?? "").padEnd(11)} ${bits.join(" · ")}`);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
/** Each record once: a send retried after its first attempt landed repeats its records - same ws, page and seq. */
|
|
638
|
+
function unique(records) {
|
|
639
|
+
const seen = /* @__PURE__ */ new Set();
|
|
640
|
+
return records.filter((r) => {
|
|
641
|
+
const k = `${r.ws}/${r.page}/${r.seq}`;
|
|
642
|
+
if (seen.has(k)) return false;
|
|
643
|
+
seen.add(k);
|
|
644
|
+
return true;
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
const ranked = (counts, n = 5) => [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, n);
|
|
648
|
+
const bump = (m, k) => m.set(k, (m.get(k) ?? 0) + 1);
|
|
649
|
+
/** Board loads (spec 28 A1.8): page.jsonl's records grouped by ws/page/load, each group in seq order; a node's last
|
|
650
|
+
* `frame` record is its outcome. A load whose `load` record fell before the window still shows what is in it.
|
|
651
|
+
* Records of no load (`load: '-'`, before the page's first board committed) are `unownedOf`'s. */
|
|
652
|
+
function loadsSummary(records) {
|
|
653
|
+
const groups = /* @__PURE__ */ new Map();
|
|
654
|
+
for (const r of unique(records)) {
|
|
655
|
+
if (typeof r.load !== "string" || r.load === "-" || typeof r.kind !== "string") continue;
|
|
656
|
+
const k = `${r.ws}/${r.page}/${r.load}`;
|
|
657
|
+
groups.set(k, [...groups.get(k) ?? [], r]);
|
|
658
|
+
}
|
|
659
|
+
const out = [];
|
|
660
|
+
for (const g of groups.values()) {
|
|
661
|
+
g.sort((a, b) => (a.seq ?? 0) - (b.seq ?? 0));
|
|
662
|
+
const of = (kind) => g.filter((r) => r.kind === kind);
|
|
663
|
+
const one = (kind) => g.find((r) => r.kind === kind);
|
|
664
|
+
const load = one("load"), commit = one("commit"), settled = one("settled"), cut = one("cut"), quiet = one("quiet"), visible = one("visible");
|
|
665
|
+
const moves = {
|
|
666
|
+
count: 0,
|
|
667
|
+
distance: 0,
|
|
668
|
+
causes: /* @__PURE__ */ new Map()
|
|
669
|
+
}, late = {
|
|
670
|
+
count: 0,
|
|
671
|
+
causes: /* @__PURE__ */ new Map()
|
|
672
|
+
};
|
|
673
|
+
for (const m of of("move")) {
|
|
674
|
+
const cause = typeof m.cause === "string" ? m.cause : "unknown";
|
|
675
|
+
if (m.late) {
|
|
676
|
+
late.count++;
|
|
677
|
+
bump(late.causes, cause);
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
moves.count++;
|
|
681
|
+
bump(moves.causes, cause);
|
|
682
|
+
moves.distance += Math.hypot(m.dx ?? 0, m.dy ?? 0) + Math.abs(m.dw ?? 0) + Math.abs(m.dh ?? 0);
|
|
683
|
+
}
|
|
684
|
+
const last = /* @__PURE__ */ new Map();
|
|
685
|
+
for (const f of of("frame")) if (typeof f.node === "string") last.set(f.node, f);
|
|
686
|
+
const frames = [...last.values()];
|
|
687
|
+
const name = (f) => String(f.frame ?? f.node);
|
|
688
|
+
const num = (v) => typeof v === "number";
|
|
689
|
+
const slowest = frames.filter((f) => f.outcome !== "cut").flatMap((f) => {
|
|
690
|
+
const ms = f.settled ?? f.ready;
|
|
691
|
+
return num(ms) ? [{
|
|
692
|
+
node: f.node,
|
|
693
|
+
...f.frame ? { frame: f.frame } : {},
|
|
694
|
+
ms,
|
|
695
|
+
outcome: f.outcome,
|
|
696
|
+
...num(f.admitted) ? { admittedMs: f.admitted } : {},
|
|
697
|
+
...num(f.ready) ? { readyMs: f.ready } : {}
|
|
698
|
+
}] : [];
|
|
699
|
+
}).sort((a, b) => b.ms - a.ms).slice(0, 5);
|
|
700
|
+
const started = frames.map((f) => f.admitted).filter(num);
|
|
701
|
+
const seenErr = /* @__PURE__ */ new Set();
|
|
702
|
+
const errors = of("error").flatMap((e) => {
|
|
703
|
+
const k = `${e.source}|${e.frame ?? ""}|${e.message}|${e.late ? "late" : ""}`;
|
|
704
|
+
if (seenErr.has(k)) return [];
|
|
705
|
+
seenErr.add(k);
|
|
706
|
+
return [{
|
|
707
|
+
source: e.source,
|
|
708
|
+
...e.frame ? { frame: e.frame } : {},
|
|
709
|
+
...e.component ? { component: e.component } : {},
|
|
710
|
+
message: String(e.message ?? ""),
|
|
711
|
+
...e.late ? { late: true } : {}
|
|
712
|
+
}];
|
|
713
|
+
});
|
|
714
|
+
const gs = of("gesture");
|
|
715
|
+
const cutFirst = !!cut && (typeof cut.request === "string" || !commit);
|
|
716
|
+
out.push({
|
|
717
|
+
ws: g[0].ws,
|
|
718
|
+
page: g[0].page,
|
|
719
|
+
load: g[0].load,
|
|
720
|
+
at: load?.ts ?? Math.min(...g.map((r) => r.ts)),
|
|
721
|
+
...load ? {
|
|
722
|
+
board: load.board,
|
|
723
|
+
cause: load.cause
|
|
724
|
+
} : {},
|
|
725
|
+
state: settled ? "settled" : cut ? "cut" : "open",
|
|
726
|
+
...cut && !settled ? { cut: {
|
|
727
|
+
reason: cut.reason,
|
|
728
|
+
...typeof cut.ms === "number" ? { ms: cut.ms } : {},
|
|
729
|
+
...cutFirst ? { request: true } : {}
|
|
730
|
+
} } : {},
|
|
731
|
+
committed: !!commit,
|
|
732
|
+
...commit && cutFirst ? { mountedAfterCut: true } : {},
|
|
733
|
+
...commit ? {
|
|
734
|
+
commitMs: commit.ms,
|
|
735
|
+
frames: commit.frames,
|
|
736
|
+
byKind: commit.byKind,
|
|
737
|
+
measuring: commit.measuring,
|
|
738
|
+
savedHeights: commit.savedHeights
|
|
739
|
+
} : {},
|
|
740
|
+
...visible ? {
|
|
741
|
+
visible: visible.nodes,
|
|
742
|
+
visibleMs: visible.ms,
|
|
743
|
+
...visible.assumed ? { visibleAssumed: true } : {}
|
|
744
|
+
} : {},
|
|
745
|
+
...settled ? {
|
|
746
|
+
visibleReadyMs: settled.visibleReadyMs,
|
|
747
|
+
allReadyMs: settled.allReadyMs,
|
|
748
|
+
settledMs: settled.ms,
|
|
749
|
+
weight: settled.weight
|
|
750
|
+
} : {},
|
|
751
|
+
...quiet ? { quietMs: quiet.ms } : {},
|
|
752
|
+
...typeof (settled ?? cut)?.lastMove === "number" ? { lastMoveMs: (settled ?? cut).lastMove } : {},
|
|
753
|
+
moves: {
|
|
754
|
+
count: moves.count,
|
|
755
|
+
distance: Math.round(moves.distance),
|
|
756
|
+
causes: ranked(moves.causes),
|
|
757
|
+
late: {
|
|
758
|
+
count: late.count,
|
|
759
|
+
causes: ranked(late.causes)
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
slowest,
|
|
763
|
+
...started.length ? { firstStartedMs: Math.min(...started) } : {},
|
|
764
|
+
...cut && !settled && commit && !cutFirst && typeof cut.frames === "number" && typeof cut.ready === "number" ? {
|
|
765
|
+
framesAtCut: cut.frames,
|
|
766
|
+
readyByCut: cut.ready
|
|
767
|
+
} : {},
|
|
768
|
+
errors,
|
|
769
|
+
errorsNotRecorded: notRecorded(g),
|
|
770
|
+
neverReady: frames.filter((f) => f.outcome === "never-ready").map(name),
|
|
771
|
+
missing: frames.filter((f) => f.outcome === "missing").map(name),
|
|
772
|
+
unfinished: frames.filter((f) => f.outcome === "cut").length,
|
|
773
|
+
...gs.length ? { gestures: {
|
|
774
|
+
n: gs.length,
|
|
775
|
+
worstP95: Math.max(...gs.map((x) => x.p95 ?? 0)),
|
|
776
|
+
over33ms: gs.reduce((n, x) => n + (x.over33ms ?? 0), 0)
|
|
777
|
+
} } : {}
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
return out.sort((a, b) => a.at - b.at);
|
|
781
|
+
}
|
|
782
|
+
/** Errors past a load's 50 (`dropped` records with reason `errors`): counted by the page, never recorded. */
|
|
783
|
+
const notRecorded = (g) => g.filter((r) => r.kind === "dropped" && r.reason === "errors").reduce((n, r) => n + (Number(r.n) || 0), 0);
|
|
784
|
+
/** What a page recorded before its first board committed: its errors (those past 50 counted), and how many gestures. */
|
|
785
|
+
function unownedOf(records) {
|
|
786
|
+
const mine = unique(records).filter((r) => r.load === "-");
|
|
787
|
+
return {
|
|
788
|
+
errors: mine.filter((r) => r.kind === "error").map((e) => ({
|
|
789
|
+
at: e.ts,
|
|
790
|
+
source: e.source,
|
|
791
|
+
...e.frame ? { frame: e.frame } : {},
|
|
792
|
+
message: e.message
|
|
793
|
+
})),
|
|
794
|
+
errorsNotRecorded: notRecorded(mine),
|
|
795
|
+
gestures: mine.filter((r) => r.kind === "gesture").length
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
/** Records the pages lost before they reached the log - past a page's queue, or in a send that failed three times
|
|
799
|
+
* (`dropped` records without a reason; errors past a load's 50 are that load's). */
|
|
800
|
+
const droppedOf = (records) => unique(records).filter((r) => r.kind === "dropped" && r.reason === void 0).reduce((n, r) => n + (Number(r.n) || 0), 0);
|
|
801
|
+
const lateErrors = (l) => l.errors.filter((e) => e.late).length;
|
|
802
|
+
/** The errors `--loads` prints for a load, as examples: the rest are counted on a line of their own (--json has all). */
|
|
803
|
+
const ERRORS_SHOWN = 10;
|
|
804
|
+
const secs = (ms) => typeof ms === "number" ? `${(ms / 1e3).toFixed(1)} s` : "-";
|
|
805
|
+
/** a wait or a frame's own time, often under a second: to the hundredth */
|
|
806
|
+
const secs2 = (ms) => ms >= 1e4 ? secs(ms) : `${(Math.max(0, ms) / 1e3).toFixed(2)} s`;
|
|
807
|
+
/** Each board by the name the sidebar shows it under - its title, else its name Title-Cased (board-tree's labelOf) - read
|
|
808
|
+
* from design/boards/ now; `--json` keeps the board's id. */
|
|
809
|
+
function namer(root) {
|
|
810
|
+
const titles = /* @__PURE__ */ new Map();
|
|
811
|
+
try {
|
|
812
|
+
const dir = join(root, "design", "boards");
|
|
813
|
+
if (!checkBoardsDir(root, dir)) for (const b of listBoardFiles(dir).boards) {
|
|
814
|
+
const t = boardFields(b.json, isBoardName).title;
|
|
815
|
+
if (t) titles.set(b.name, t);
|
|
816
|
+
}
|
|
817
|
+
} catch {}
|
|
818
|
+
return (b) => b === "~unplaced" ? "Not on a board" : b ? labelOf(b, titles.get(b)) : "a board (its request is older)";
|
|
819
|
+
}
|
|
820
|
+
/** How a load ended, in a few words. */
|
|
821
|
+
function endOf(l) {
|
|
822
|
+
if (l.state === "settled") return `settled ${secs(l.settledMs)}`;
|
|
823
|
+
if (l.cut?.request && l.mountedAfterCut) return `cut (${l.cut.reason})${l.cut.ms !== void 0 ? ` at ${secs(l.cut.ms)}` : ""} before it mounted · mounted ${secs(l.commitMs)}`;
|
|
824
|
+
if (l.cut?.request) return `not committed (${l.cut.reason})`;
|
|
825
|
+
if (l.cut) return `cut (${l.cut.reason})${l.cut.ms !== void 0 ? ` at ${secs(l.cut.ms)}` : ""}`;
|
|
826
|
+
return "not settled yet";
|
|
827
|
+
}
|
|
828
|
+
/** A page's records without a headless run's (spec 28 A3.8 #17: the server stamps them `run`; `--runs` is theirs),
|
|
829
|
+
* and how many run loads that hid. */
|
|
830
|
+
function ownLoads(records) {
|
|
831
|
+
const loads = /* @__PURE__ */ new Set();
|
|
832
|
+
return {
|
|
833
|
+
records: records.filter((r) => {
|
|
834
|
+
if (typeof r.run !== "string") return true;
|
|
835
|
+
if (r.kind === "load") loads.add(`${r.ws}/${r.page}/${r.load}`);
|
|
836
|
+
return false;
|
|
837
|
+
}),
|
|
838
|
+
runLoads: loads.size
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
/** `marver perf --loads` (spec 28 A1.8): each board load in full, from design/.local/perf/page.jsonl. */
|
|
842
|
+
function loadsPerf(root, opts) {
|
|
843
|
+
const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
|
|
844
|
+
const { records, runLoads } = ownLoads(readPage(root, Date.now() - minutes * 6e4));
|
|
845
|
+
const loads = loadsSummary(records);
|
|
846
|
+
const dropped = droppedOf(records);
|
|
847
|
+
if (opts.json) {
|
|
848
|
+
console.log(JSON.stringify({
|
|
849
|
+
minutes,
|
|
850
|
+
loads,
|
|
851
|
+
unowned: unownedOf(records),
|
|
852
|
+
dropped,
|
|
853
|
+
runLoads
|
|
854
|
+
}, null, 2));
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
console.log(`board loads, last ${minutes} min - design/.local/perf/page.jsonl`);
|
|
858
|
+
const hidden = runLoads ? `${runLoads} headless run load${runLoads === 1 ? "" : "s"} not shown: npx marver perf --runs` : "";
|
|
859
|
+
if (!loads.length) {
|
|
860
|
+
console.log(`\nnothing yet - open a board in the canvas${hidden ? `\n ${hidden}` : ""}`);
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
const t = (ts) => new Date(ts).toLocaleTimeString();
|
|
864
|
+
const list = (r) => r.map(([k, n]) => `${k} ${n}`).join(", ");
|
|
865
|
+
const plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
866
|
+
const boardName = namer(root);
|
|
867
|
+
for (const l of loads) {
|
|
868
|
+
const head = `${boardName(l.board)}${l.cause ? ` (${l.cause})` : ""}`;
|
|
869
|
+
console.log(`\n ${t(l.at)} ${head.padEnd(40)} ${endOf(l)}`);
|
|
870
|
+
if (!l.committed) continue;
|
|
871
|
+
const kinds = Object.entries(l.byKind ?? {}).filter(([, n]) => n).map(([k, n]) => `${n} ${k === "hifi" ? "hi-fi" : k}`);
|
|
872
|
+
console.log(` ${l.mountedAfterCut ? "mounted after its cut" : "committed"} ${secs(l.commitMs)} · ${plural(l.frames ?? 0, "frame")}${kinds.length ? ` (${kinds.join(", ")})` : ""}${l.measuring ? ` · ${l.measuring} measure, ${l.savedHeights ?? 0} opened at a known height` : ""}`);
|
|
873
|
+
const times = [
|
|
874
|
+
...l.firstStartedMs !== void 0 ? [`first frame started ${secs2(l.firstStartedMs)}`] : [],
|
|
875
|
+
...l.readyByCut !== void 0 ? [`${l.readyByCut} of ${l.framesAtCut} ready`] : [],
|
|
876
|
+
...l.visibleReadyMs !== void 0 ? [`visible ready ${secs(l.visibleReadyMs)}${l.visible !== void 0 ? ` (${plural(l.visible, "frame")}${l.visibleAssumed ? ", no fit" : ""})` : ""}`] : [],
|
|
877
|
+
...l.allReadyMs !== void 0 ? [`all ready ${secs(l.allReadyMs)}`] : [],
|
|
878
|
+
...l.state === "settled" ? [`still from ${secs(l.lastMoveMs ?? l.commitMs)}`] : l.lastMoveMs !== void 0 ? [`last move ${secs(l.lastMoveMs)}`] : [],
|
|
879
|
+
...l.settledMs !== void 0 ? [`settled ${secs(l.settledMs)}`] : []
|
|
880
|
+
];
|
|
881
|
+
if (times.length) console.log(` ${times.join(" · ")}`);
|
|
882
|
+
const m = l.moves;
|
|
883
|
+
console.log(` ${plural(m.count, "move")}${m.count ? `, ${m.distance} px: ${list(m.causes)}` : ""}${m.late.count ? ` · late, after it ${l.state === "settled" ? "settled" : l.state === "cut" ? "was cut" : "ended"}: ${m.late.count} (${list(m.late.causes)})` : ""}`);
|
|
884
|
+
const took = (f) => `${f.frame ?? f.node} ${secs(f.ms)}${f.admittedMs !== void 0 ? ` (waited ${secs2(f.admittedMs)}, then ${secs2(f.ms - f.admittedMs)})` : ""}`;
|
|
885
|
+
const slow = [...l.slowest.length ? [`slowest to settle: ${l.slowest.map(took).join(", ")}`] : [], ...l.unfinished ? [`${l.unfinished} never finished`] : []];
|
|
886
|
+
if (slow.length) console.log(` ${slow.join(" · ")}`);
|
|
887
|
+
const gone = [...l.neverReady.length ? [`never ready: ${l.neverReady.join(", ")}`] : [], ...l.missing.length ? [`missing: ${l.missing.join(", ")}`] : []];
|
|
888
|
+
if (gone.length) console.log(` ${gone.join(" · ")}`);
|
|
889
|
+
for (const e of l.errors.slice(0, ERRORS_SHOWN)) console.log(` ${e.late ? "late error" : "error"} (${e.source}${e.frame ? ` ${e.frame}` : ""}${e.component ? `, in ${e.component}` : ""}): ${e.message}`);
|
|
890
|
+
if (l.errors.length > ERRORS_SHOWN) console.log(` ${plural(l.errors.length - ERRORS_SHOWN, "more error")} not shown (--json lists every one)`);
|
|
891
|
+
if (l.errorsNotRecorded) console.log(` ${plural(l.errorsNotRecorded, "more error")} past the first 50, not recorded`);
|
|
892
|
+
if (l.gestures) console.log(` ${plural(l.gestures.n, "gesture")} · worst p95 ${l.gestures.worstP95} ms · ${plural(l.gestures.over33ms, "frame")} over 33 ms`);
|
|
893
|
+
}
|
|
894
|
+
if (dropped) console.log(`\n ${plural(dropped, "record")} never reached this log: a page's queue was full, or its sends failed`);
|
|
895
|
+
if (hidden) console.log(`\n ${hidden}`);
|
|
896
|
+
}
|
|
897
|
+
/** Count, median, p90 and max of a list of ms. */
|
|
898
|
+
function spread(xs) {
|
|
899
|
+
if (!xs.length) return { n: 0 };
|
|
900
|
+
const v = [...xs].sort((a, b) => a - b);
|
|
901
|
+
const at = (q) => v[Math.min(v.length - 1, Math.ceil(q * v.length) - 1)];
|
|
902
|
+
return {
|
|
903
|
+
n: v.length,
|
|
904
|
+
median: at(.5),
|
|
905
|
+
p90: at(.9),
|
|
906
|
+
max: v[v.length - 1]
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
/** `marver perf --jam`: each step of a capture and its run - count, median, p90, max - the runs by outcome, and the
|
|
910
|
+
* last problems, from design/.local/perf/jam.jsonl (numbers and codes only). */
|
|
911
|
+
function jamSummary(events) {
|
|
912
|
+
const of = (kind) => events.filter((e) => e.kind === kind);
|
|
913
|
+
const nums = (xs) => xs.filter((x) => typeof x === "number");
|
|
914
|
+
const caps = of("capture"), runs = of("run").filter((r) => !r.redelivered), shots = of("shot"), words = of("words");
|
|
915
|
+
const steps = {
|
|
916
|
+
"capture: E to sealed": spread(nums(caps.map((c) => c.sealMs))),
|
|
917
|
+
"capture: last words": spread(nums(caps.map((c) => c.wordsWaitMs))),
|
|
918
|
+
"capture: a picture": spread(nums(caps.flatMap((c) => c.pictures?.ms ?? []))),
|
|
919
|
+
"upload": spread(nums(of("upload").map((u) => u.ms))),
|
|
920
|
+
"naming": spread(nums(of("name").map((n) => n.ms))),
|
|
921
|
+
"words: wait": spread(nums(words.map((w) => w.waitMs))),
|
|
922
|
+
"words: transcription": spread(nums(words.map((w) => w.decodeMs))),
|
|
923
|
+
"words: model load": spread(nums(words.map((w) => w.modelLoadMs))),
|
|
924
|
+
"run: queued": spread(nums(runs.flatMap((r) => (r.members ?? []).map((m) => m.waitMs)))),
|
|
925
|
+
"run: pictures before": spread(nums(runs.map((r) => r.beforeMs))),
|
|
926
|
+
"run: agent": spread(nums(runs.flatMap((r) => r.agentMs ?? []))),
|
|
927
|
+
"run: pictures after": spread(nums(runs.map((r) => r.afterMs))),
|
|
928
|
+
"run: delivery": spread(nums(of("run").map((r) => r.deliverMs))),
|
|
929
|
+
"shot": spread(nums(shots.map((s) => s.ms)))
|
|
930
|
+
};
|
|
931
|
+
const outcomes = {};
|
|
932
|
+
for (const r of runs) for (const m of r.members ?? []) outcomes[m.outcome ?? "unknown"] = (outcomes[m.outcome ?? "unknown"] ?? 0) + 1;
|
|
933
|
+
return {
|
|
934
|
+
steps,
|
|
935
|
+
outcomes,
|
|
936
|
+
problems: [
|
|
937
|
+
...of("run").filter((r) => r.failure).map((r) => ({
|
|
938
|
+
ts: r.ts,
|
|
939
|
+
what: `run ${String(r.batch).slice(0, 8)} ${r.redelivered ? "could not post its replies" : `failed: ${r.failure}`}`
|
|
940
|
+
})),
|
|
941
|
+
...shots.filter((s) => s.outcome && s.outcome !== "ok").map((s) => ({
|
|
942
|
+
ts: s.ts,
|
|
943
|
+
what: `shot ${s.frame ?? "?"}: ${s.outcome}${s.recaptures ? ` after ${s.recaptures} retakes` : ""}`
|
|
944
|
+
})),
|
|
945
|
+
...caps.filter((c) => c.pictures?.late || c.pictures?.failed).map((c) => ({
|
|
946
|
+
ts: c.ts,
|
|
947
|
+
what: `capture ${c.capture}: ${c.pictures.late ?? 0} picture(s) too late, ${c.pictures.failed ?? 0} failed`
|
|
948
|
+
})),
|
|
949
|
+
...of("name").filter((n) => !n.ok).map((n) => ({
|
|
950
|
+
ts: n.ts,
|
|
951
|
+
what: `naming ${n.capture} gave no name`
|
|
952
|
+
})),
|
|
953
|
+
...of("dropped").map((d) => ({
|
|
954
|
+
ts: d.ts,
|
|
955
|
+
what: `${d.count} event(s) dropped (the log was busy)`
|
|
956
|
+
}))
|
|
957
|
+
].sort((a, b) => b.ts - a.ts).slice(0, 10),
|
|
958
|
+
retakes: shots.reduce((n, s) => n + (s.recaptures ?? 0), 0)
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
function jamPerf(root, opts) {
|
|
962
|
+
const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 1440;
|
|
963
|
+
const since = Date.now() - minutes * 6e4;
|
|
964
|
+
const { events, first } = readJam(root, since);
|
|
965
|
+
const sum = jamSummary(events);
|
|
966
|
+
const partial = first !== void 0 && first > since;
|
|
967
|
+
if (opts.json) {
|
|
968
|
+
console.log(JSON.stringify({
|
|
969
|
+
minutes,
|
|
970
|
+
...partial ? { startsAt: first } : {},
|
|
971
|
+
...sum
|
|
972
|
+
}, null, 2));
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
const span = minutes >= 120 ? `${Math.round(minutes / 60)} h` : `${minutes} min`;
|
|
976
|
+
console.log(`Jam timings, last ${span} - design/.local/perf/jam.jsonl${partial ? ` (the log starts ${new Date(first).toLocaleString()})` : ""}`);
|
|
977
|
+
if (!events.length) {
|
|
978
|
+
console.log("\nnothing yet - captures, runs and shots log here as they happen");
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
console.log("");
|
|
982
|
+
const pad = (s, n) => s + " ".repeat(Math.max(1, n - s.length));
|
|
983
|
+
console.log(` ${pad("step", 24)}${pad("count", 7)}${pad("median", 9)}${pad("p90", 9)}max`);
|
|
984
|
+
const f = (v) => v === void 0 ? "-" : v >= 1e4 ? `${(v / 1e3).toFixed(0)} s` : v >= 1e3 ? `${(v / 1e3).toFixed(1)} s` : `${v} ms`;
|
|
985
|
+
for (const [name, x] of Object.entries(sum.steps)) if (x.n) console.log(` ${pad(name, 24)}${pad(String(x.n), 7)}${pad(f(x.median), 9)}${pad(f(x.p90), 9)}${f(x.max)}`);
|
|
986
|
+
const out = Object.entries(sum.outcomes);
|
|
987
|
+
if (out.length) console.log(`\nruns by outcome: ${out.map(([k, n]) => `${n} ${k}`).join(", ")}`);
|
|
988
|
+
if (sum.retakes) console.log(`pictures taken again (a stale surface): ${sum.retakes}`);
|
|
989
|
+
if (sum.problems.length) {
|
|
990
|
+
console.log("\nlately");
|
|
991
|
+
for (const p of sum.problems) console.log(` ${new Date(p.ts).toLocaleTimeString()} ${p.what}`);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
/** What the app's half and the repo's page half read, over `--days` (14 by default). */
|
|
995
|
+
function appInputs(root, opts) {
|
|
996
|
+
const days = Number(opts.days) > 0 ? Math.min(90, Number(opts.days)) : 14;
|
|
997
|
+
const since = Date.now() - days * 864e5;
|
|
998
|
+
const home = marverHome();
|
|
999
|
+
const page = ownLoads(readPage(root, since)).records;
|
|
1000
|
+
return {
|
|
1001
|
+
days,
|
|
1002
|
+
since,
|
|
1003
|
+
home,
|
|
1004
|
+
page,
|
|
1005
|
+
app: readAppLog(home, since),
|
|
1006
|
+
workspaces: repoWorkspaces(root, page)
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
const when = (ts) => new Date(ts).toLocaleString([], {
|
|
1010
|
+
month: "short",
|
|
1011
|
+
day: "numeric",
|
|
1012
|
+
hour: "2-digit",
|
|
1013
|
+
minute: "2-digit",
|
|
1014
|
+
second: "2-digit"
|
|
1015
|
+
});
|
|
1016
|
+
const LEVEL = {
|
|
1017
|
+
1: "normal",
|
|
1018
|
+
2: "warn",
|
|
1019
|
+
4: "critical"
|
|
1020
|
+
};
|
|
1021
|
+
const level = (n) => typeof n === "number" ? LEVEL[n] ?? String(n) : "unknown";
|
|
1022
|
+
const tilde = (p) => {
|
|
1023
|
+
const h = homedir();
|
|
1024
|
+
return p.startsWith(h + "/") ? `~${p.slice(h.length)}` : p;
|
|
1025
|
+
};
|
|
1026
|
+
/** A long wait in words: seconds, then minutes, then hours. */
|
|
1027
|
+
const long = (ms) => ms < 12e4 ? `${Math.round(ms / 1e3)} s` : ms < 72e5 ? `${Math.round(ms / 6e4)} min` : `${Math.round(ms / 36e5)} h`;
|
|
1028
|
+
/** An offset from a moment, signed (positive = before it), in words: never clamped. */
|
|
1029
|
+
const offset = (ms) => ms === 0 ? "at it" : `${secs2(Math.abs(ms))} ${ms > 0 ? "before" : "after"}`;
|
|
1030
|
+
const gestureName = (t) => t === "layout" ? "layout animation" : t;
|
|
1031
|
+
/** A gesture against the moment: the one it fell in, else the last before it (a flash's may end after it). */
|
|
1032
|
+
function gestureWords(g) {
|
|
1033
|
+
const n = gestureName(g.type);
|
|
1034
|
+
if (g.during) return `during a ${n}${g.startedMsBefore !== void 0 ? ` (started ${offset(g.startedMsBefore)}, ended ${offset(g.endedMsBefore)})` : ""}`;
|
|
1035
|
+
if (g.endedMsBefore < 0) return `a ${n} ${g.startedMsBefore !== void 0 ? `started ${offset(g.startedMsBefore)}, ` : ""}ended ${offset(g.endedMsBefore)}`;
|
|
1036
|
+
return `last gesture a ${n}, ended ${offset(g.endedMsBefore)}`;
|
|
1037
|
+
}
|
|
1038
|
+
/** The page half at a moment, in a few words, with how it was joined. `ended`: the moment is the document's end (a crash). */
|
|
1039
|
+
function momentWords(m, name, o = {}) {
|
|
1040
|
+
if (m.join === "none") return "no page record of it (its canvas recorded nothing here)";
|
|
1041
|
+
if (m.join === "page-unrecorded") return o.ended ? `its page ${m.page} recorded nothing before it ended (it ended before its first batch of records, 2 s?)` : `its page ${m.page} has no record in page.jsonl`;
|
|
1042
|
+
const bits = [name(m.board)];
|
|
1043
|
+
if (m.load) bits.push(m.load.settled ? `its load settled${m.load.settledMs !== void 0 ? ` in ${secs(m.load.settledMs)}` : ""}` : "its load had not settled");
|
|
1044
|
+
if (m.gesture) bits.push(gestureWords(m.gesture));
|
|
1045
|
+
return bits.join(" · ") + (m.join === "ws+time" ? " (joined by workspace and time: the record has no page id)" : "");
|
|
1046
|
+
}
|
|
1047
|
+
/** `marver perf --crashes`: the app's canvas crashes and hangs for this repo, joined to the page half; the machine-wide ends by time. */
|
|
1048
|
+
function crashesPerf(root, opts) {
|
|
1049
|
+
const i = appInputs(root, opts);
|
|
1050
|
+
const sum = crashesSummary(i.app, i.page, i.workspaces, i.home);
|
|
1051
|
+
if (opts.json) {
|
|
1052
|
+
console.log(JSON.stringify({
|
|
1053
|
+
days: i.days,
|
|
1054
|
+
workspaces: [...i.workspaces],
|
|
1055
|
+
...sum
|
|
1056
|
+
}, null, 2));
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
const name = namer(root);
|
|
1060
|
+
console.log(`crashes, last ${i.days} days - ${tilde(join(i.home, "perf"))}/app.jsonl and app-dev.jsonl, joined to design/.local/perf/page.jsonl by page`);
|
|
1061
|
+
console.log(`\ncanvas crashes: ${sum.crashes.length}`);
|
|
1062
|
+
for (const c of sum.crashes) {
|
|
1063
|
+
console.log(` ${when(c.at)} ${c.reason}${typeof c.exitCode === "number" ? ` (exit ${c.exitCode})` : ""} · pid ${c.pid} · pressure ${level(c.pressure)}${c.flavour === "dev" ? " · Marver Dev" : ""}`);
|
|
1064
|
+
console.log(` ${momentWords(c, name, { ended: true })}`);
|
|
1065
|
+
const b = c.before;
|
|
1066
|
+
if (b) console.log(` the minute before (by time, machine-wide): pressure ${level(b.pressure)}, thermal ${b.thermal}, canvases ${b.canvasMB != null ? Math.round(b.canvasMB) : "-"} MB, the GPU process ${b.gpuProcessRssMB != null ? Math.round(b.gpuProcessRssMB) : "-"} MB${b.procMB != null ? `, this renderer ${Math.round(b.procMB)} MB` : ""}`);
|
|
1067
|
+
}
|
|
1068
|
+
if (sum.hangs.length) {
|
|
1069
|
+
console.log(`\nnot responding: ${sum.hangs.length}`);
|
|
1070
|
+
for (const h of sum.hangs) console.log(` ${when(h.at)} pid ${h.pid}${h.respondedAfterMs !== void 0 ? `, answered again after ${secs(h.respondedAfterMs)}` : ", never answered again"} · ${momentWords(h, name)}`);
|
|
1071
|
+
}
|
|
1072
|
+
console.log(`\nby time (machine-wide): ${sum.byTime.length}`);
|
|
1073
|
+
for (const m of sum.byTime) console.log(` ${when(m.at)} ${m.text}${m.flavour === "dev" ? " (Marver Dev)" : ""}`);
|
|
1074
|
+
console.log(`\ncrash reports: ${sum.dumps} in ${tilde(join(i.home, "perf", "crashpad", "completed"))}`);
|
|
1075
|
+
}
|
|
1076
|
+
/** `marver perf --flashes`: the marks made on this repo's canvases (`--all`: every one), and the detector's candidates apart. */
|
|
1077
|
+
function flashesPerf(root, opts) {
|
|
1078
|
+
const i = appInputs(root, opts);
|
|
1079
|
+
const sum = flashesSummary(i.app, i.page, i.workspaces, {
|
|
1080
|
+
all: !!opts.all,
|
|
1081
|
+
home: i.home
|
|
1082
|
+
});
|
|
1083
|
+
if (opts.json) {
|
|
1084
|
+
console.log(JSON.stringify({
|
|
1085
|
+
days: i.days,
|
|
1086
|
+
workspaces: [...i.workspaces],
|
|
1087
|
+
...sum
|
|
1088
|
+
}, null, 2));
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
const name = namer(root);
|
|
1092
|
+
console.log(`flashes marked (⌃⌥F), last ${i.days} days - ${tilde(join(i.home, "perf"))}, joined to design/.local/perf/page.jsonl by page`);
|
|
1093
|
+
if (!sum.marks.length) console.log("\nnone on this repo's canvases");
|
|
1094
|
+
for (const m of sum.marks) {
|
|
1095
|
+
const where = !m.tab ? "Home or Settings" : !m.ws ? "a canvas (no workspace recorded)" : !m.mine ? "a canvas of another repo" : m.join === "none" ? "this repo's canvas (no page record near it)" : momentWords(m, name);
|
|
1096
|
+
console.log(`\n ${when(m.at)} ${where}`);
|
|
1097
|
+
const agx = m.agx;
|
|
1098
|
+
const age = m.pressureAgeMs;
|
|
1099
|
+
const pressure = m.pressure !== null ? `pressure ${level(m.pressure)}${age !== void 0 ? ` (read ${offset(age)})` : ""}` : age !== void 0 && age > 1e4 ? `pressure unknown (the last reading was ${long(age)} old at the mark)` : "pressure unknown";
|
|
1100
|
+
console.log(` ${pressure} · thermal ${m.thermal} · the GPU process ${m.gpuProcessRssMB !== null ? `${Math.round(m.gpuProcessRssMB)} MB` : "unknown"} · GPU in use ${agx.gpuSystemMemoryMB ?? "unknown"} MB, ${agx.utilPct ?? "unknown"} % (machine-wide)`);
|
|
1101
|
+
if (m.gpuEvents.length) console.log(` GPU process events within 1 s: ${m.gpuEvents.map((e) => `${e.kind} ${e.ts >= m.at ? "+" : "-"}${secs2(Math.abs(e.ts - m.at))}`).join(", ")}`);
|
|
1102
|
+
if (!m.recorder) console.log(" the recorder was off: no samples before it");
|
|
1103
|
+
console.log(` ${m.picturePruned ? "no picture: pruned since (at most 50 are kept, none older than keepPerfDays)" : m.picture ? `picture (the app's views, not the screen): ${m.picture}` : `no picture: ${m.pictureWhy ?? "unknown"}`}`);
|
|
1104
|
+
}
|
|
1105
|
+
if (!opts.all && sum.others) console.log(`\n${sum.others} more mark${sum.others === 1 ? "" : "s"} on other canvases or on Home (--all shows them)`);
|
|
1106
|
+
console.log(`\nwhite-out candidates (automatic, not verified): ${sum.candidates.length}`);
|
|
1107
|
+
for (const c of sum.candidates) console.log(` ${when(c.at)} white at ${c.observedAt.length} samples ${c.rateHz ? `at ${c.rateHz} Hz ` : ""}(${c.observedAt.map((t) => secs2(t - c.at)).join(", ")}) · ${momentWords(c, name)}`);
|
|
1108
|
+
}
|
|
1109
|
+
/** `marver perf --machine`: the machine profiles, by host, which is current, and how many records and runs name each. */
|
|
1110
|
+
function machinePerf(root, opts) {
|
|
1111
|
+
const i = appInputs(root, opts);
|
|
1112
|
+
const runs = readRuns(root, i.since);
|
|
1113
|
+
const sum = machineSummary(i.home, i.app, runs);
|
|
1114
|
+
if (opts.json) {
|
|
1115
|
+
console.log(JSON.stringify({
|
|
1116
|
+
days: i.days,
|
|
1117
|
+
...sum
|
|
1118
|
+
}, null, 2));
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
console.log(`machine profiles - ${tilde(join(i.home, "perf", "machine"))} (records of the last ${i.days} days)`);
|
|
1122
|
+
if (!sum.profiles.length) {
|
|
1123
|
+
console.log("\nnone yet - the Mac app and `marver perf run` write them");
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
const by = new Map(sum.profiles.map((p) => [p.hash, p]));
|
|
1127
|
+
for (const g of sum.byHost) {
|
|
1128
|
+
const first = by.get(g.profiles[0]);
|
|
1129
|
+
console.log(`\nhost ${g.hostHash ?? "unknown"}: ${[
|
|
1130
|
+
first.chip,
|
|
1131
|
+
first.model,
|
|
1132
|
+
first.os ? `macOS ${first.os}` : void 0
|
|
1133
|
+
].filter(Boolean).join(" · ")}`);
|
|
1134
|
+
for (const h of g.profiles) {
|
|
1135
|
+
const p = by.get(h);
|
|
1136
|
+
console.log(` ${p.hash} ${p.kind}${p.current ? " (current)" : ""} · ${p.records} app record${p.records === 1 ? "" : "s"}, ${p.runs} run${p.runs === 1 ? "" : "s"}`);
|
|
1137
|
+
const more = [
|
|
1138
|
+
p.electron,
|
|
1139
|
+
p.gpu,
|
|
1140
|
+
p.displays,
|
|
1141
|
+
p.power ? `power ${p.power}` : void 0
|
|
1142
|
+
].filter(Boolean);
|
|
1143
|
+
if (more.length) console.log(` ${more.join(" · ")}`);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
const ms2 = (v) => typeof v === "number" ? v >= 1e3 ? `${(v / 1e3).toFixed(2)} s` : `${Math.round(v)} ms` : "-";
|
|
1148
|
+
const mms = (v) => typeof v === "number" ? `${v} ms` : "-";
|
|
1149
|
+
const why = (l) => `invalid: ${l.invalidReason}${l.restarted ? " (the dev server restarted)" : l.cut ? ` (${l.cut})` : ""}`;
|
|
1150
|
+
const over33 = (n) => n === null ? "frames over 33 ms not measured" : `${n} frame${n === 1 ? "" : "s"} over 33 ms`;
|
|
1151
|
+
/** What a run asks of the agent, when its reason alone does not say it - an invalid run's, or a compile it left running. */
|
|
1152
|
+
const hint = (l) => l.restarted ? "the dev server restarted during the run (an .env or config edit): its inputs changed - run it again" : l.cut === "unresponsive" ? "the page stopped answering for 15 s: a frame's script that never returns (an endless loop) - open the board and see which frame hangs" : l.invalidReason === "gesture" && l.over33ms === null ? "no frame was timed: requestAnimationFrame never ran in the gestures (the page read as hidden?)" : l.invalidReason === "gesture" && l.gestures < 3 ? `the canvas ended ${l.gestures} of the 3 gestures within 5 s: the camera kept moving (an animation that never ends?)` : l.bakesPending ? "a compile of this run was still running 50 s after it: the next run is overlapped" : null;
|
|
1153
|
+
/** One run, as `perf run` and `perf --runs` print it: three lines, and a fourth when it has a hint. */
|
|
1154
|
+
function runBlock(l, name) {
|
|
1155
|
+
const h = hint(l);
|
|
1156
|
+
return [
|
|
1157
|
+
`run ${l.run} · ${name(l.board)} · Chrome ${l.chrome.split(".")[0]} · bakes ${l.bakes}${l.slow ? " · --slow" : ""}${l.overlapped ? " · overlapped" : ""}`,
|
|
1158
|
+
`load to settled ${ms2(l.loadToSettledMs)} · ${l.moves} move${l.moves === 1 ? "" : "s"}${l.lateMoves ? ` (${l.lateMoves} late)` : ""} · p50 ${mms(l.p50)} p95 ${mms(l.p95)} · ${over33(l.over33ms)} · heap peak ${l.heapPeakMB ?? "-"} MB${l.postersMissing ? ` · ${l.postersMissing} without a poster` : ""}`,
|
|
1159
|
+
`${l.valid ? "valid" : why(l)} · inputs ${l.inputs ? `${l.inputs.hash.slice(0, 8)}… (${l.inputs.files.toLocaleString("en-US")} files)` : "unknown"}${l.forbidden ? ` · ${l.forbidden} write${l.forbidden === 1 ? "" : "s"} refused` : ""}`,
|
|
1160
|
+
...h ? [h] : []
|
|
1161
|
+
];
|
|
1162
|
+
}
|
|
1163
|
+
/**
|
|
1164
|
+
* The stream broke before its end with a run under way: the dev server restarted in place (an .env or config edit) or
|
|
1165
|
+
* stopped. The run's line reaches runs.jsonl once its end has run - its pages closed, its compiles awaited, 50 s at
|
|
1166
|
+
* most - so it is waited for, 90 s at most, and no longer once the dev server has not answered for 5 s (it stopped).
|
|
1167
|
+
*/
|
|
1168
|
+
async function lineAfterDrop(root, run, port) {
|
|
1169
|
+
const by = Date.now() + 9e4;
|
|
1170
|
+
let downSince = null;
|
|
1171
|
+
for (let n = 0; Date.now() < by; n++) {
|
|
1172
|
+
const l = readRuns(root, Date.now() - 36e5).find((x) => x.run === run);
|
|
1173
|
+
if (l) return l;
|
|
1174
|
+
if (n % 4 === 0) {
|
|
1175
|
+
if (await fetch(`http://localhost:${port}/`, { signal: AbortSignal.timeout(1e3) }).then(() => true, () => false)) downSince = null;
|
|
1176
|
+
else if ((downSince ??= Date.now()) < Date.now() - 5e3) return null;
|
|
1177
|
+
}
|
|
1178
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
1179
|
+
}
|
|
1180
|
+
return null;
|
|
1181
|
+
}
|
|
1182
|
+
/** The dev server's own `{ error }` stream line: the run failed there before it had a line (no Chrome, a launch that
|
|
1183
|
+
* failed) - the server said so and ended the stream, so no line will come and none is waited for (the review of
|
|
1184
|
+
* a3-runs' fixes, major #1). */
|
|
1185
|
+
var ServerSaid = class extends Error {};
|
|
1186
|
+
/**
|
|
1187
|
+
* `marver perf run <board> [--slow] [--repeat n] [--json]`: the board's script in the canvas's own headless Chrome
|
|
1188
|
+
* (`marver dev` must be running), read-only - one line per run in design/.local/perf/runs.jsonl. Ctrl-C closes the
|
|
1189
|
+
* request, which cancels the run (its line says `cancelled`). A failure the server reports ends the command at once,
|
|
1190
|
+
* with the lines of the runs before it (`--json`: `{ runs, error }`); only a stream that breaks, or ends before its
|
|
1191
|
+
* `done`, under a run waits for that run's line.
|
|
1192
|
+
*/
|
|
1193
|
+
async function perfRunCommand(root, board, opts) {
|
|
1194
|
+
if (!board) throw new Error("name the board: marver perf run <board> [--slow] [--repeat 1-5] [--json]");
|
|
1195
|
+
const info = readDevInfo(root);
|
|
1196
|
+
if (!info) throw new Error("`marver dev` is not running in this repo (design/.local/dev.json not found) - start it first.");
|
|
1197
|
+
const repeat = opts.repeat === void 0 ? 1 : Number(opts.repeat);
|
|
1198
|
+
if (!(Number.isInteger(repeat) && repeat >= 1 && repeat <= 5)) throw new Error("--repeat must be 1-5");
|
|
1199
|
+
const ac = new AbortController();
|
|
1200
|
+
const stop = () => ac.abort();
|
|
1201
|
+
process.once("SIGINT", stop);
|
|
1202
|
+
const name = namer(root);
|
|
1203
|
+
const lines = [];
|
|
1204
|
+
let under = null;
|
|
1205
|
+
try {
|
|
1206
|
+
const res = await fetch(`http://localhost:${info.port}/__mv/api/perf/run`, {
|
|
1207
|
+
method: "POST",
|
|
1208
|
+
signal: ac.signal,
|
|
1209
|
+
headers: {
|
|
1210
|
+
"x-mv-work": info.token,
|
|
1211
|
+
"content-type": "application/json"
|
|
1212
|
+
},
|
|
1213
|
+
body: JSON.stringify({
|
|
1214
|
+
board,
|
|
1215
|
+
slow: !!opts.slow,
|
|
1216
|
+
repeat
|
|
1217
|
+
})
|
|
1218
|
+
});
|
|
1219
|
+
if (!res.ok || !res.body) {
|
|
1220
|
+
const b = await res.json().catch(() => ({}));
|
|
1221
|
+
throw new Error(b.error ?? `the run could not start (${res.status})`);
|
|
1222
|
+
}
|
|
1223
|
+
let buf = "", finished = false;
|
|
1224
|
+
const dec = new TextDecoder();
|
|
1225
|
+
for await (const chunk of res.body) {
|
|
1226
|
+
buf += dec.decode(chunk, { stream: true });
|
|
1227
|
+
let nl;
|
|
1228
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
1229
|
+
const text = buf.slice(0, nl);
|
|
1230
|
+
buf = buf.slice(nl + 1);
|
|
1231
|
+
let m;
|
|
1232
|
+
try {
|
|
1233
|
+
m = JSON.parse(text);
|
|
1234
|
+
} catch {
|
|
1235
|
+
continue;
|
|
1236
|
+
}
|
|
1237
|
+
if ("error" in m) {
|
|
1238
|
+
under = null;
|
|
1239
|
+
throw new ServerSaid(`the run failed in the dev server: ${m.error}`);
|
|
1240
|
+
}
|
|
1241
|
+
if ("phase" in m) {
|
|
1242
|
+
under = m.run;
|
|
1243
|
+
if (!opts.json) console.log(m.phase === "warm" ? `run ${m.run}: warming up` : m.phase === "measured" ? " measuring" : " closing");
|
|
1244
|
+
}
|
|
1245
|
+
if ("line" in m) {
|
|
1246
|
+
under = null;
|
|
1247
|
+
lines.push(m.line);
|
|
1248
|
+
if (!opts.json) for (const l of runBlock(m.line, name)) console.log(` ${l}`);
|
|
1249
|
+
}
|
|
1250
|
+
if ("done" in m) finished = true;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (!finished) throw new Error("the dev server ended the stream before the runs did");
|
|
1254
|
+
} catch (err) {
|
|
1255
|
+
if (ac.signal.aborted) {
|
|
1256
|
+
if (!opts.json) console.log(" cancelled - the run's line says so");
|
|
1257
|
+
return 130;
|
|
1258
|
+
}
|
|
1259
|
+
if (err instanceof ServerSaid) {
|
|
1260
|
+
if (!opts.json) throw err;
|
|
1261
|
+
console.log(JSON.stringify({
|
|
1262
|
+
runs: lines,
|
|
1263
|
+
error: err.message
|
|
1264
|
+
}, null, 2));
|
|
1265
|
+
return 1;
|
|
1266
|
+
}
|
|
1267
|
+
if (!under) throw err;
|
|
1268
|
+
if (!opts.json) console.log(" the connection to the dev server dropped - waiting for the run's line");
|
|
1269
|
+
const line = await lineAfterDrop(root, under, info.port);
|
|
1270
|
+
if (!line) throw new Error(`the connection to the dev server dropped during run ${under}, and no line came for it - did \`marver dev\` stop? (${err.message})`);
|
|
1271
|
+
lines.push(line);
|
|
1272
|
+
if (!opts.json) for (const l of runBlock(line, name)) console.log(` ${l}`);
|
|
1273
|
+
} finally {
|
|
1274
|
+
process.off("SIGINT", stop);
|
|
1275
|
+
}
|
|
1276
|
+
if (opts.json) console.log(JSON.stringify({ runs: lines }, null, 2));
|
|
1277
|
+
else console.log(`\n design/.local/perf/runs.jsonl · compare: npx marver perf --runs`);
|
|
1278
|
+
return lines.length && lines.every((l) => l.valid) ? 0 : 1;
|
|
1279
|
+
}
|
|
1280
|
+
/** `marver perf --runs [--against <run>] [--days n]`: the headless runs, compared inside their cohorts. */
|
|
1281
|
+
function runsPerf(root, opts) {
|
|
1282
|
+
const days = Number(opts.days) > 0 ? Number(opts.days) : 14;
|
|
1283
|
+
const lines = readRuns(root, Date.now() - days * 864e5);
|
|
1284
|
+
const sum = runsSummary(lines, { against: opts.against });
|
|
1285
|
+
if (opts.json) {
|
|
1286
|
+
console.log(JSON.stringify({
|
|
1287
|
+
days,
|
|
1288
|
+
runs: lines,
|
|
1289
|
+
...sum
|
|
1290
|
+
}, null, 2));
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
const name = namer(root);
|
|
1294
|
+
console.log(`headless runs, last ${days} days - design/.local/perf/runs.jsonl`);
|
|
1295
|
+
if (!lines.length) {
|
|
1296
|
+
console.log("\nnone yet - npx marver perf run <board>");
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const pct = (a, b) => a && b !== null ? `${b >= a ? "+" : ""}${Math.round((b - a) / a * 100)} %` : "-";
|
|
1300
|
+
for (const b of sum.boards) {
|
|
1301
|
+
console.log(`\n ${name(b.board)} · Chrome ${String(b.cohort.chrome).split(".")[0]} · bakes ${b.cohort.bakes}${b.cohort.slow ? " · --slow" : ""} · ${b.runs} valid run${b.runs === 1 ? "" : "s"}`);
|
|
1302
|
+
const d33 = b.afterChange?.deltas.over33ms ?? null;
|
|
1303
|
+
console.log(` latest ${b.latest.run}: load to settled ${ms2(b.latest.loadToSettledMs)} · p95 ${mms(b.latest.p95)} · ${b.latest.over33ms ?? "-"} over 33 ms · inputs ${b.latest.inputs?.slice(0, 8) ?? "unknown"}…`);
|
|
1304
|
+
if (b.sameInputs) console.log(` against ${b.sameInputs.from.run} (same inputs): ${b.sameInputs.within10 ? "within 10 %" : "NOT within 10 %"} - load ${pct(b.sameInputs.from.loadToSettledMs, b.latest.loadToSettledMs)}, p95 ${pct(b.sameInputs.from.p95, b.latest.p95)}`);
|
|
1305
|
+
if (b.afterChange) console.log(` after a change, against ${b.afterChange.from.run}: load ${pct(b.afterChange.from.loadToSettledMs, b.latest.loadToSettledMs)}, p95 ${pct(b.afterChange.from.p95, b.latest.p95)}, over 33 ms ${d33 === null ? "-" : `${d33 >= 0 ? "+" : ""}${d33}`}`);
|
|
1306
|
+
}
|
|
1307
|
+
if (sum.against) {
|
|
1308
|
+
const a = sum.against;
|
|
1309
|
+
if ("error" in a) console.log(`\n --against ${a.run}: ${a.error}`);
|
|
1310
|
+
else console.log(`\n --against ${a.run}: ${a.to.run} ${a.within10 ? "within 10 %" : "differs"} - load ${pct(a.from.loadToSettledMs, a.to.loadToSettledMs)}, p95 ${pct(a.from.p95, a.to.p95)}`);
|
|
1311
|
+
}
|
|
1312
|
+
if (sum.overlapped.length) console.log(`\n ${sum.overlapped.length} overlapped (another run at the same time): never compared - ${sum.overlapped.map((r) => r.run).join(", ")}`);
|
|
1313
|
+
if (sum.invalid.length) {
|
|
1314
|
+
console.log(`\n invalid (${sum.invalid.length})`);
|
|
1315
|
+
for (const r of sum.invalid.slice(-10)) console.log(` ${new Date(r.ts).toLocaleString()} ${r.run} ${name(r.board)} ${why(r)}`);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
//#endregion
|
|
1319
|
+
export { perfCommand, perfRunCommand };
|