@marver-design/marver 0.26.1 → 0.27.0
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 +104 -0
- package/README.md +8 -3
- package/dist/{anchor-check-l-ny3UzH.mjs → anchor-check-ChdDqL5z.mjs} +1 -1
- package/dist/{bake-C-awKgLA.mjs → bake-DM_uWgAA.mjs} +1 -1
- package/dist/{boards-DYG22tOe.mjs → boards-DlTcpF47.mjs} +1 -1
- package/dist/{build-BDRiO_mP.mjs → build-DZnFysGU.mjs} +4 -4
- package/dist/cli.mjs +28 -16
- package/dist/{comments-BqXua-XL.mjs → comments-DxOkCSNE.mjs} +4 -4
- package/dist/{daemon-DL6Fwq6D.mjs → daemon-BSA0lV8d.mjs} +8 -6
- package/dist/detect-C0wpaePX.mjs +125 -0
- package/dist/dev-eQJhWsqg.mjs +1273 -0
- package/dist/dev-lock-C_FC70Mu.mjs +65 -0
- package/dist/exclusive-B1RtpeeP.mjs +150 -0
- package/dist/{init-D8DtrK_F.mjs → init-COD0x48i.mjs} +5 -3
- package/dist/{link-BNzLvdhI.mjs → link-DDXZVGtv.mjs} +20 -8
- package/dist/ls-D7O1G505.mjs +38 -0
- package/dist/{marks-DyWMv_Z1.mjs → marks-CWM3WJjc.mjs} +1 -1
- package/dist/perf-BWzQwZqj.mjs +369 -0
- package/dist/perf-BoDSkbEb.mjs +429 -0
- package/dist/{perf-jam-BU3TVrZu.mjs → perf-jam-D55U3FZK.mjs} +5 -2
- package/dist/{plugin-DkGmZs_r.mjs → plugin-C-E7omsh.mjs} +394 -55
- package/dist/{poster-BdtSKMDm.mjs → poster-Bx83ZYVK.mjs} +1 -1
- package/dist/{profile-WU9qcbIo.mjs → profile-Bh5Y5zpW.mjs} +1 -1
- package/dist/{publish-bakes-9RzRToXV.mjs → publish-bakes-aljgm45S.mjs} +2 -2
- package/dist/{queue-29ok5_eZ.mjs → queue-CAM_vNmX.mjs} +1 -1
- package/dist/recover-t9Pno3u9.mjs +66 -0
- package/dist/{share--oFJ1bCI.mjs → share-W5H3BNvP.mjs} +1 -1
- package/dist/{shot-XQV7HC9A.mjs → shot-DoHLl6ig.mjs} +1 -1
- package/dist/{shot-DQeR_Pfn.mjs → shot-LFhC-WYD.mjs} +9 -3
- package/dist/slots-DCDo3N0x.mjs +471 -0
- package/dist/{sync-DKk-yT1V.mjs → sync-BQVlHZpx.mjs} +4 -3
- package/dist/{work-F5u-twpJ.mjs → work-Bp1p39kq.mjs} +4 -2
- package/dist/{work-VvX_JIgl.mjs → work-BroFwnup.mjs} +4 -2
- package/docs/boards-and-folders.md +3 -1
- package/docs/jam-session.md +55 -1
- package/docs/performance.md +262 -0
- package/package.json +2 -2
- package/src/client/content/index.tsx +3 -0
- package/src/client/content/video.tsx +6 -2
- package/src/client/frame-host/bridge.js +22 -6
- package/src/client/frame-host/main.tsx +17 -5
- package/src/client/shell/App.tsx +180 -25
- package/src/client/shell/BoardList.tsx +5 -5
- package/src/client/shell/Comments.tsx +3 -2
- package/src/client/shell/JamSurface.tsx +4 -2
- package/src/client/shell/LockedApp.tsx +5 -5
- package/src/client/shell/Play.tsx +16 -8
- package/src/client/shell/Toolbar.tsx +12 -1
- package/src/client/shell/api.ts +206 -0
- package/src/client/shell/canvas/Canvas.tsx +30 -3
- package/src/client/shell/canvas/FrameNode.tsx +12 -3
- package/src/client/shell/canvas/admission.ts +8 -1
- package/src/client/shell/canvas/camera-broadcast.ts +15 -5
- package/src/client/shell/canvas/ctl.ts +2 -0
- package/src/client/shell/canvas/frame-registry.ts +28 -2
- package/src/client/shell/canvas/sleep.ts +4 -1
- package/src/client/shell/comments-store.ts +12 -4
- package/src/client/shell/goto.ts +22 -10
- package/src/client/shell/jam-capture.ts +22 -8
- package/src/client/shell/jam-keys.ts +4 -0
- package/src/client/shell/jam-panel.tsx +3 -0
- 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 +7 -5
- package/src/client/shell/legacy-links.ts +2 -2
- package/src/client/shell/main.tsx +4 -0
- package/src/client/shell/notes.ts +8 -1
- package/src/client/shell/perf.ts +69 -58
- package/src/client/shell/recorder-core.ts +183 -0
- package/src/client/shell/recorder.ts +565 -0
- package/src/client/shell/store.ts +254 -98
- package/src/client/shell/styles.css +26 -1
- package/templates/AGENTS-embedded.md +22 -4
- package/templates/AGENTS-studio.md +22 -4
- package/templates/demo/dark.tsx +1 -1
- package/templates/demo/welcome.tsx +1 -1
- package/templates/instructions/welcome.md +6 -3
- 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
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { u as humanize } from "./board-tree-DRioF94d.mjs";
|
|
2
|
+
import { a as readPage, o as readReloads } from "./perf-BWzQwZqj.mjs";
|
|
3
|
+
import { r as readJam } from "./perf-jam-D55U3FZK.mjs";
|
|
4
|
+
//#region src/cli/perf.ts
|
|
5
|
+
/**
|
|
6
|
+
* `marver perf` (spec 26 Part 1): the reload log read back - per edited file, the frames it reached
|
|
7
|
+
* and how; every page-wide reload (sent or dropped) and every time the canvas page itself booted,
|
|
8
|
+
* with what came just before; the slowest frames to settle; one line per board load. Reads
|
|
9
|
+
* design/.local/perf/reloads.jsonl, and page.jsonl for the loads (`--loads`: each load in full, spec 28 A1.8).
|
|
10
|
+
*/
|
|
11
|
+
function perfCommand(root, opts) {
|
|
12
|
+
if (opts.jam) return jamPerf(root, opts);
|
|
13
|
+
if (opts.loads) return loadsPerf(root, opts);
|
|
14
|
+
const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
|
|
15
|
+
const since = Date.now() - minutes * 6e4;
|
|
16
|
+
const log = readReloads(root, since);
|
|
17
|
+
const loads = loadsSummary(readPage(root, since));
|
|
18
|
+
const files = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const e of log) if (e.kind === "update") {
|
|
20
|
+
const f = files.get(e.file ?? "(no file)") ?? {
|
|
21
|
+
edits: 0,
|
|
22
|
+
reload: /* @__PURE__ */ new Set(),
|
|
23
|
+
inPlace: /* @__PURE__ */ new Set()
|
|
24
|
+
};
|
|
25
|
+
f.edits++;
|
|
26
|
+
for (const id of e.reload ?? []) f.reload.add(id);
|
|
27
|
+
for (const id of e.inPlace ?? []) f.inPlace.add(id);
|
|
28
|
+
files.set(e.file ?? "(no file)", f);
|
|
29
|
+
}
|
|
30
|
+
const reloads = log.filter((e) => e.kind === "full-reload");
|
|
31
|
+
const boots = log.flatMap((e, i) => e.kind === "shell-boot" ? [{
|
|
32
|
+
ts: e.ts,
|
|
33
|
+
before: log.slice(Math.max(0, i - 3), i).filter((x) => x.kind !== "ready" && x.kind !== "settled")
|
|
34
|
+
}] : []);
|
|
35
|
+
const slow = log.filter((e) => e.kind === "settled" && typeof e.ms === "number").sort((a, b) => b.ms - a.ms).slice(0, 5);
|
|
36
|
+
const booted = log.filter((e) => e.kind === "ready");
|
|
37
|
+
const by = (c) => booted.filter((e) => e.cause === c).length;
|
|
38
|
+
const reloaded = by("job");
|
|
39
|
+
if (opts.json) {
|
|
40
|
+
console.log(JSON.stringify({
|
|
41
|
+
minutes,
|
|
42
|
+
files: Object.fromEntries([...files].map(([k, v]) => [k, {
|
|
43
|
+
edits: v.edits,
|
|
44
|
+
reached: [...v.reload],
|
|
45
|
+
inPlace: [...v.inPlace]
|
|
46
|
+
}])),
|
|
47
|
+
documents: {
|
|
48
|
+
afterEdit: reloaded,
|
|
49
|
+
byHand: by("manual"),
|
|
50
|
+
retried: by("retry"),
|
|
51
|
+
self: by("self"),
|
|
52
|
+
first: by("first")
|
|
53
|
+
},
|
|
54
|
+
reloads,
|
|
55
|
+
boots,
|
|
56
|
+
slow,
|
|
57
|
+
loads: loads.map((l) => ({
|
|
58
|
+
at: l.at,
|
|
59
|
+
board: l.board,
|
|
60
|
+
cause: l.cause,
|
|
61
|
+
state: l.state,
|
|
62
|
+
settledMs: l.settledMs,
|
|
63
|
+
cut: l.cut,
|
|
64
|
+
...l.mountedAfterCut ? { mountedAfterCut: true } : {},
|
|
65
|
+
moves: l.moves.count,
|
|
66
|
+
late: l.moves.late.count,
|
|
67
|
+
errors: l.errors.length,
|
|
68
|
+
lateErrors: l.errors.filter((e) => e.late).length
|
|
69
|
+
}))
|
|
70
|
+
}, null, 2));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const t = (ts) => new Date(ts).toLocaleTimeString();
|
|
74
|
+
console.log(`last ${minutes} min - design/.local/perf/reloads.jsonl`);
|
|
75
|
+
console.log(`\nedits (${files.size} files)`);
|
|
76
|
+
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` : ""}`);
|
|
77
|
+
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`);
|
|
78
|
+
console.log(`\npage-wide reloads: ${reloads.filter((r) => r.passed).length} sent (dependency rebuilds), ${reloads.filter((r) => !r.passed).length} dropped`);
|
|
79
|
+
for (const r of reloads) console.log(` ${t(r.ts)} ${r.passed ? "sent " : "dropped"} ${r.triggeredBy ?? "no file named"}`);
|
|
80
|
+
console.log(`\ncanvas page loads: ${boots.length}`);
|
|
81
|
+
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(", ")}` : ""}`);
|
|
82
|
+
if (slow.length) {
|
|
83
|
+
console.log("\nslowest to settle");
|
|
84
|
+
for (const s of slow) console.log(` ${s.frame} ${s.ms} ms`);
|
|
85
|
+
}
|
|
86
|
+
if (loads.length) {
|
|
87
|
+
console.log(`\nboard loads: ${loads.length} (--loads: each in full)`);
|
|
88
|
+
const w = Math.max(...loads.map((l) => (l.board ?? "?").length));
|
|
89
|
+
for (const l of loads) {
|
|
90
|
+
const bits = [
|
|
91
|
+
endOf(l),
|
|
92
|
+
...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)` : ""}`] : [],
|
|
93
|
+
...l.errors.length ? [`${l.errors.length} error${l.errors.length === 1 ? "" : "s"}${lateErrors(l) ? ` (${lateErrors(l)} late)` : ""}`] : []
|
|
94
|
+
];
|
|
95
|
+
console.log(` ${t(l.at)} ${(l.board ?? "?").padEnd(w)} ${(l.cause ?? "").padEnd(11)} ${bits.join(" · ")}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Each record once: a send retried after its first attempt landed repeats its records - same ws, page and seq. */
|
|
100
|
+
function unique(records) {
|
|
101
|
+
const seen = /* @__PURE__ */ new Set();
|
|
102
|
+
return records.filter((r) => {
|
|
103
|
+
const k = `${r.ws}/${r.page}/${r.seq}`;
|
|
104
|
+
if (seen.has(k)) return false;
|
|
105
|
+
seen.add(k);
|
|
106
|
+
return true;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const ranked = (counts, n = 5) => [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, n);
|
|
110
|
+
const bump = (m, k) => m.set(k, (m.get(k) ?? 0) + 1);
|
|
111
|
+
/** Board loads (spec 28 A1.8): page.jsonl's records grouped by ws/page/load, each group in seq order; a node's last
|
|
112
|
+
* `frame` record is its outcome. A load whose `load` record fell before the window still shows what is in it.
|
|
113
|
+
* Records of no load (`load: '-'`, before the page's first board committed) are `unownedOf`'s. */
|
|
114
|
+
function loadsSummary(records) {
|
|
115
|
+
const groups = /* @__PURE__ */ new Map();
|
|
116
|
+
for (const r of unique(records)) {
|
|
117
|
+
if (typeof r.load !== "string" || r.load === "-" || typeof r.kind !== "string") continue;
|
|
118
|
+
const k = `${r.ws}/${r.page}/${r.load}`;
|
|
119
|
+
groups.set(k, [...groups.get(k) ?? [], r]);
|
|
120
|
+
}
|
|
121
|
+
const out = [];
|
|
122
|
+
for (const g of groups.values()) {
|
|
123
|
+
g.sort((a, b) => (a.seq ?? 0) - (b.seq ?? 0));
|
|
124
|
+
const of = (kind) => g.filter((r) => r.kind === kind);
|
|
125
|
+
const one = (kind) => g.find((r) => r.kind === kind);
|
|
126
|
+
const load = one("load"), commit = one("commit"), settled = one("settled"), cut = one("cut"), quiet = one("quiet"), visible = one("visible");
|
|
127
|
+
const moves = {
|
|
128
|
+
count: 0,
|
|
129
|
+
distance: 0,
|
|
130
|
+
causes: /* @__PURE__ */ new Map()
|
|
131
|
+
}, late = {
|
|
132
|
+
count: 0,
|
|
133
|
+
causes: /* @__PURE__ */ new Map()
|
|
134
|
+
};
|
|
135
|
+
for (const m of of("move")) {
|
|
136
|
+
const cause = typeof m.cause === "string" ? m.cause : "unknown";
|
|
137
|
+
if (m.late) {
|
|
138
|
+
late.count++;
|
|
139
|
+
bump(late.causes, cause);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
moves.count++;
|
|
143
|
+
bump(moves.causes, cause);
|
|
144
|
+
moves.distance += Math.hypot(m.dx ?? 0, m.dy ?? 0) + Math.abs(m.dw ?? 0) + Math.abs(m.dh ?? 0);
|
|
145
|
+
}
|
|
146
|
+
const last = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const f of of("frame")) if (typeof f.node === "string") last.set(f.node, f);
|
|
148
|
+
const frames = [...last.values()];
|
|
149
|
+
const name = (f) => String(f.frame ?? f.node);
|
|
150
|
+
const num = (v) => typeof v === "number";
|
|
151
|
+
const slowest = frames.filter((f) => f.outcome !== "cut").flatMap((f) => {
|
|
152
|
+
const ms = f.settled ?? f.ready;
|
|
153
|
+
return num(ms) ? [{
|
|
154
|
+
node: f.node,
|
|
155
|
+
...f.frame ? { frame: f.frame } : {},
|
|
156
|
+
ms,
|
|
157
|
+
outcome: f.outcome,
|
|
158
|
+
...num(f.admitted) ? { admittedMs: f.admitted } : {},
|
|
159
|
+
...num(f.ready) ? { readyMs: f.ready } : {}
|
|
160
|
+
}] : [];
|
|
161
|
+
}).sort((a, b) => b.ms - a.ms).slice(0, 5);
|
|
162
|
+
const started = frames.map((f) => f.admitted).filter(num);
|
|
163
|
+
const seenErr = /* @__PURE__ */ new Set();
|
|
164
|
+
const errors = of("error").flatMap((e) => {
|
|
165
|
+
const k = `${e.source}|${e.frame ?? ""}|${e.message}|${e.late ? "late" : ""}`;
|
|
166
|
+
if (seenErr.has(k)) return [];
|
|
167
|
+
seenErr.add(k);
|
|
168
|
+
return [{
|
|
169
|
+
source: e.source,
|
|
170
|
+
...e.frame ? { frame: e.frame } : {},
|
|
171
|
+
...e.component ? { component: e.component } : {},
|
|
172
|
+
message: String(e.message ?? ""),
|
|
173
|
+
...e.late ? { late: true } : {}
|
|
174
|
+
}];
|
|
175
|
+
});
|
|
176
|
+
const gs = of("gesture");
|
|
177
|
+
const cutFirst = !!cut && (typeof cut.request === "string" || !commit);
|
|
178
|
+
out.push({
|
|
179
|
+
ws: g[0].ws,
|
|
180
|
+
page: g[0].page,
|
|
181
|
+
load: g[0].load,
|
|
182
|
+
at: load?.ts ?? Math.min(...g.map((r) => r.ts)),
|
|
183
|
+
...load ? {
|
|
184
|
+
board: load.board,
|
|
185
|
+
cause: load.cause
|
|
186
|
+
} : {},
|
|
187
|
+
state: settled ? "settled" : cut ? "cut" : "open",
|
|
188
|
+
...cut && !settled ? { cut: {
|
|
189
|
+
reason: cut.reason,
|
|
190
|
+
...typeof cut.ms === "number" ? { ms: cut.ms } : {},
|
|
191
|
+
...cutFirst ? { request: true } : {}
|
|
192
|
+
} } : {},
|
|
193
|
+
committed: !!commit,
|
|
194
|
+
...commit && cutFirst ? { mountedAfterCut: true } : {},
|
|
195
|
+
...commit ? {
|
|
196
|
+
commitMs: commit.ms,
|
|
197
|
+
frames: commit.frames,
|
|
198
|
+
byKind: commit.byKind,
|
|
199
|
+
measuring: commit.measuring,
|
|
200
|
+
savedHeights: commit.savedHeights
|
|
201
|
+
} : {},
|
|
202
|
+
...visible ? {
|
|
203
|
+
visible: visible.nodes,
|
|
204
|
+
visibleMs: visible.ms,
|
|
205
|
+
...visible.assumed ? { visibleAssumed: true } : {}
|
|
206
|
+
} : {},
|
|
207
|
+
...settled ? {
|
|
208
|
+
visibleReadyMs: settled.visibleReadyMs,
|
|
209
|
+
allReadyMs: settled.allReadyMs,
|
|
210
|
+
settledMs: settled.ms,
|
|
211
|
+
weight: settled.weight
|
|
212
|
+
} : {},
|
|
213
|
+
...quiet ? { quietMs: quiet.ms } : {},
|
|
214
|
+
...typeof (settled ?? cut)?.lastMove === "number" ? { lastMoveMs: (settled ?? cut).lastMove } : {},
|
|
215
|
+
moves: {
|
|
216
|
+
count: moves.count,
|
|
217
|
+
distance: Math.round(moves.distance),
|
|
218
|
+
causes: ranked(moves.causes),
|
|
219
|
+
late: {
|
|
220
|
+
count: late.count,
|
|
221
|
+
causes: ranked(late.causes)
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
slowest,
|
|
225
|
+
...started.length ? { firstStartedMs: Math.min(...started) } : {},
|
|
226
|
+
...cut && !settled && commit && !cutFirst && typeof cut.frames === "number" && typeof cut.ready === "number" ? {
|
|
227
|
+
framesAtCut: cut.frames,
|
|
228
|
+
readyByCut: cut.ready
|
|
229
|
+
} : {},
|
|
230
|
+
errors,
|
|
231
|
+
errorsNotRecorded: notRecorded(g),
|
|
232
|
+
neverReady: frames.filter((f) => f.outcome === "never-ready").map(name),
|
|
233
|
+
missing: frames.filter((f) => f.outcome === "missing").map(name),
|
|
234
|
+
unfinished: frames.filter((f) => f.outcome === "cut").length,
|
|
235
|
+
...gs.length ? { gestures: {
|
|
236
|
+
n: gs.length,
|
|
237
|
+
worstP95: Math.max(...gs.map((x) => x.p95 ?? 0)),
|
|
238
|
+
over33ms: gs.reduce((n, x) => n + (x.over33ms ?? 0), 0)
|
|
239
|
+
} } : {}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return out.sort((a, b) => a.at - b.at);
|
|
243
|
+
}
|
|
244
|
+
/** Errors past a load's 50 (`dropped` records with reason `errors`): counted by the page, never recorded. */
|
|
245
|
+
const notRecorded = (g) => g.filter((r) => r.kind === "dropped" && r.reason === "errors").reduce((n, r) => n + (Number(r.n) || 0), 0);
|
|
246
|
+
/** What a page recorded before its first board committed: its errors (those past 50 counted), and how many gestures. */
|
|
247
|
+
function unownedOf(records) {
|
|
248
|
+
const mine = unique(records).filter((r) => r.load === "-");
|
|
249
|
+
return {
|
|
250
|
+
errors: mine.filter((r) => r.kind === "error").map((e) => ({
|
|
251
|
+
at: e.ts,
|
|
252
|
+
source: e.source,
|
|
253
|
+
...e.frame ? { frame: e.frame } : {},
|
|
254
|
+
message: e.message
|
|
255
|
+
})),
|
|
256
|
+
errorsNotRecorded: notRecorded(mine),
|
|
257
|
+
gestures: mine.filter((r) => r.kind === "gesture").length
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Records the pages lost before they reached the log - past a page's queue, or in a send that failed three times
|
|
261
|
+
* (`dropped` records without a reason; errors past a load's 50 are that load's). */
|
|
262
|
+
const droppedOf = (records) => unique(records).filter((r) => r.kind === "dropped" && r.reason === void 0).reduce((n, r) => n + (Number(r.n) || 0), 0);
|
|
263
|
+
const lateErrors = (l) => l.errors.filter((e) => e.late).length;
|
|
264
|
+
/** The errors `--loads` prints for a load, as examples: the rest are counted on a line of their own (--json has all). */
|
|
265
|
+
const ERRORS_SHOWN = 10;
|
|
266
|
+
const secs = (ms) => typeof ms === "number" ? `${(ms / 1e3).toFixed(1)} s` : "-";
|
|
267
|
+
/** a wait or a frame's own time, often under a second: to the hundredth */
|
|
268
|
+
const secs2 = (ms) => ms >= 1e4 ? secs(ms) : `${(Math.max(0, ms) / 1e3).toFixed(2)} s`;
|
|
269
|
+
const boardName = (b) => b === "~unplaced" ? "Not on a board" : b ? humanize(b) : "a board (its request is older)";
|
|
270
|
+
/** How a load ended, in a few words. */
|
|
271
|
+
function endOf(l) {
|
|
272
|
+
if (l.state === "settled") return `settled ${secs(l.settledMs)}`;
|
|
273
|
+
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)}`;
|
|
274
|
+
if (l.cut?.request) return `not committed (${l.cut.reason})`;
|
|
275
|
+
if (l.cut) return `cut (${l.cut.reason})${l.cut.ms !== void 0 ? ` at ${secs(l.cut.ms)}` : ""}`;
|
|
276
|
+
return "not settled yet";
|
|
277
|
+
}
|
|
278
|
+
/** `marver perf --loads` (spec 28 A1.8): each board load in full, from design/.local/perf/page.jsonl. */
|
|
279
|
+
function loadsPerf(root, opts) {
|
|
280
|
+
const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 60;
|
|
281
|
+
const records = readPage(root, Date.now() - minutes * 6e4);
|
|
282
|
+
const loads = loadsSummary(records);
|
|
283
|
+
const dropped = droppedOf(records);
|
|
284
|
+
if (opts.json) {
|
|
285
|
+
console.log(JSON.stringify({
|
|
286
|
+
minutes,
|
|
287
|
+
loads,
|
|
288
|
+
unowned: unownedOf(records),
|
|
289
|
+
dropped
|
|
290
|
+
}, null, 2));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
console.log(`board loads, last ${minutes} min - design/.local/perf/page.jsonl`);
|
|
294
|
+
if (!loads.length) {
|
|
295
|
+
console.log("\nnothing yet - open a board in the canvas");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const t = (ts) => new Date(ts).toLocaleTimeString();
|
|
299
|
+
const list = (r) => r.map(([k, n]) => `${k} ${n}`).join(", ");
|
|
300
|
+
const plural = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
301
|
+
for (const l of loads) {
|
|
302
|
+
const head = `${boardName(l.board)}${l.cause ? ` (${l.cause})` : ""}`;
|
|
303
|
+
console.log(`\n ${t(l.at)} ${head.padEnd(40)} ${endOf(l)}`);
|
|
304
|
+
if (!l.committed) continue;
|
|
305
|
+
const kinds = Object.entries(l.byKind ?? {}).filter(([, n]) => n).map(([k, n]) => `${n} ${k === "hifi" ? "hi-fi" : k}`);
|
|
306
|
+
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` : ""}`);
|
|
307
|
+
const times = [
|
|
308
|
+
...l.firstStartedMs !== void 0 ? [`first frame started ${secs2(l.firstStartedMs)}`] : [],
|
|
309
|
+
...l.readyByCut !== void 0 ? [`${l.readyByCut} of ${l.framesAtCut} ready`] : [],
|
|
310
|
+
...l.visibleReadyMs !== void 0 ? [`visible ready ${secs(l.visibleReadyMs)}${l.visible !== void 0 ? ` (${plural(l.visible, "frame")}${l.visibleAssumed ? ", no fit" : ""})` : ""}`] : [],
|
|
311
|
+
...l.allReadyMs !== void 0 ? [`all ready ${secs(l.allReadyMs)}`] : [],
|
|
312
|
+
...l.quietMs !== void 0 ? [`quiet ${secs(l.quietMs)}`] : [],
|
|
313
|
+
...l.lastMoveMs !== void 0 ? [`last move ${secs(l.lastMoveMs)}`] : [],
|
|
314
|
+
...l.settledMs !== void 0 ? [`settled ${secs(l.settledMs)}`] : []
|
|
315
|
+
];
|
|
316
|
+
if (times.length) console.log(` ${times.join(" · ")}`);
|
|
317
|
+
const m = l.moves;
|
|
318
|
+
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)})` : ""}`);
|
|
319
|
+
const took = (f) => `${f.frame ?? f.node} ${secs(f.ms)}${f.admittedMs !== void 0 ? ` (waited ${secs2(f.admittedMs)}, then ${secs2(f.ms - f.admittedMs)})` : ""}`;
|
|
320
|
+
const slow = [...l.slowest.length ? [`slowest: ${l.slowest.map(took).join(", ")}`] : [], ...l.unfinished ? [`${l.unfinished} never finished`] : []];
|
|
321
|
+
if (slow.length) console.log(` ${slow.join(" · ")}`);
|
|
322
|
+
const gone = [...l.neverReady.length ? [`never ready: ${l.neverReady.join(", ")}`] : [], ...l.missing.length ? [`missing: ${l.missing.join(", ")}`] : []];
|
|
323
|
+
if (gone.length) console.log(` ${gone.join(" · ")}`);
|
|
324
|
+
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}`);
|
|
325
|
+
if (l.errors.length > ERRORS_SHOWN) console.log(` ${plural(l.errors.length - ERRORS_SHOWN, "more error")} not shown (--json lists every one)`);
|
|
326
|
+
if (l.errorsNotRecorded) console.log(` ${plural(l.errorsNotRecorded, "more error")} past the first 50, not recorded`);
|
|
327
|
+
if (l.gestures) console.log(` ${plural(l.gestures.n, "gesture")} · worst p95 ${l.gestures.worstP95} ms · ${plural(l.gestures.over33ms, "frame")} over 33 ms`);
|
|
328
|
+
}
|
|
329
|
+
if (dropped) console.log(`\n ${plural(dropped, "record")} never reached this log: a page's queue was full, or its sends failed`);
|
|
330
|
+
}
|
|
331
|
+
/** Count, median, p90 and max of a list of ms. */
|
|
332
|
+
function spread(xs) {
|
|
333
|
+
if (!xs.length) return { n: 0 };
|
|
334
|
+
const v = [...xs].sort((a, b) => a - b);
|
|
335
|
+
const at = (q) => v[Math.min(v.length - 1, Math.ceil(q * v.length) - 1)];
|
|
336
|
+
return {
|
|
337
|
+
n: v.length,
|
|
338
|
+
median: at(.5),
|
|
339
|
+
p90: at(.9),
|
|
340
|
+
max: v[v.length - 1]
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/** `marver perf --jam`: each step of a capture and its run - count, median, p90, max - the runs by outcome, and the
|
|
344
|
+
* last problems, from design/.local/perf/jam.jsonl (numbers and codes only). */
|
|
345
|
+
function jamSummary(events) {
|
|
346
|
+
const of = (kind) => events.filter((e) => e.kind === kind);
|
|
347
|
+
const nums = (xs) => xs.filter((x) => typeof x === "number");
|
|
348
|
+
const caps = of("capture"), runs = of("run").filter((r) => !r.redelivered), shots = of("shot"), words = of("words");
|
|
349
|
+
const steps = {
|
|
350
|
+
"capture: E to sealed": spread(nums(caps.map((c) => c.sealMs))),
|
|
351
|
+
"capture: last words": spread(nums(caps.map((c) => c.wordsWaitMs))),
|
|
352
|
+
"capture: a picture": spread(nums(caps.flatMap((c) => c.pictures?.ms ?? []))),
|
|
353
|
+
"upload": spread(nums(of("upload").map((u) => u.ms))),
|
|
354
|
+
"naming": spread(nums(of("name").map((n) => n.ms))),
|
|
355
|
+
"words: wait": spread(nums(words.map((w) => w.waitMs))),
|
|
356
|
+
"words: transcription": spread(nums(words.map((w) => w.decodeMs))),
|
|
357
|
+
"words: model load": spread(nums(words.map((w) => w.modelLoadMs))),
|
|
358
|
+
"run: queued": spread(nums(runs.flatMap((r) => (r.members ?? []).map((m) => m.waitMs)))),
|
|
359
|
+
"run: pictures before": spread(nums(runs.map((r) => r.beforeMs))),
|
|
360
|
+
"run: agent": spread(nums(runs.flatMap((r) => r.agentMs ?? []))),
|
|
361
|
+
"run: pictures after": spread(nums(runs.map((r) => r.afterMs))),
|
|
362
|
+
"run: delivery": spread(nums(of("run").map((r) => r.deliverMs))),
|
|
363
|
+
"shot": spread(nums(shots.map((s) => s.ms)))
|
|
364
|
+
};
|
|
365
|
+
const outcomes = {};
|
|
366
|
+
for (const r of runs) for (const m of r.members ?? []) outcomes[m.outcome ?? "unknown"] = (outcomes[m.outcome ?? "unknown"] ?? 0) + 1;
|
|
367
|
+
return {
|
|
368
|
+
steps,
|
|
369
|
+
outcomes,
|
|
370
|
+
problems: [
|
|
371
|
+
...of("run").filter((r) => r.failure).map((r) => ({
|
|
372
|
+
ts: r.ts,
|
|
373
|
+
what: `run ${String(r.batch).slice(0, 8)} ${r.redelivered ? "could not post its replies" : `failed: ${r.failure}`}`
|
|
374
|
+
})),
|
|
375
|
+
...shots.filter((s) => s.outcome && s.outcome !== "ok").map((s) => ({
|
|
376
|
+
ts: s.ts,
|
|
377
|
+
what: `shot ${s.frame ?? "?"}: ${s.outcome}${s.recaptures ? ` after ${s.recaptures} retakes` : ""}`
|
|
378
|
+
})),
|
|
379
|
+
...caps.filter((c) => c.pictures?.late || c.pictures?.failed).map((c) => ({
|
|
380
|
+
ts: c.ts,
|
|
381
|
+
what: `capture ${c.capture}: ${c.pictures.late ?? 0} picture(s) too late, ${c.pictures.failed ?? 0} failed`
|
|
382
|
+
})),
|
|
383
|
+
...of("name").filter((n) => !n.ok).map((n) => ({
|
|
384
|
+
ts: n.ts,
|
|
385
|
+
what: `naming ${n.capture} gave no name`
|
|
386
|
+
})),
|
|
387
|
+
...of("dropped").map((d) => ({
|
|
388
|
+
ts: d.ts,
|
|
389
|
+
what: `${d.count} event(s) dropped (the log was busy)`
|
|
390
|
+
}))
|
|
391
|
+
].sort((a, b) => b.ts - a.ts).slice(0, 10),
|
|
392
|
+
retakes: shots.reduce((n, s) => n + (s.recaptures ?? 0), 0)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function jamPerf(root, opts) {
|
|
396
|
+
const minutes = Number(opts.minutes) > 0 ? Number(opts.minutes) : 1440;
|
|
397
|
+
const since = Date.now() - minutes * 6e4;
|
|
398
|
+
const { events, first } = readJam(root, since);
|
|
399
|
+
const sum = jamSummary(events);
|
|
400
|
+
const partial = first !== void 0 && first > since;
|
|
401
|
+
if (opts.json) {
|
|
402
|
+
console.log(JSON.stringify({
|
|
403
|
+
minutes,
|
|
404
|
+
...partial ? { startsAt: first } : {},
|
|
405
|
+
...sum
|
|
406
|
+
}, null, 2));
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const span = minutes >= 120 ? `${Math.round(minutes / 60)} h` : `${minutes} min`;
|
|
410
|
+
console.log(`Jam timings, last ${span} - design/.local/perf/jam.jsonl${partial ? ` (the log starts ${new Date(first).toLocaleString()})` : ""}`);
|
|
411
|
+
if (!events.length) {
|
|
412
|
+
console.log("\nnothing yet - captures, runs and shots log here as they happen");
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
console.log("");
|
|
416
|
+
const pad = (s, n) => s + " ".repeat(Math.max(1, n - s.length));
|
|
417
|
+
console.log(` ${pad("step", 24)}${pad("count", 7)}${pad("median", 9)}${pad("p90", 9)}max`);
|
|
418
|
+
const f = (v) => v === void 0 ? "-" : v >= 1e4 ? `${(v / 1e3).toFixed(0)} s` : v >= 1e3 ? `${(v / 1e3).toFixed(1)} s` : `${v} ms`;
|
|
419
|
+
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)}`);
|
|
420
|
+
const out = Object.entries(sum.outcomes);
|
|
421
|
+
if (out.length) console.log(`\nruns by outcome: ${out.map(([k, n]) => `${n} ${k}`).join(", ")}`);
|
|
422
|
+
if (sum.retakes) console.log(`pictures taken again (a stale surface): ${sum.retakes}`);
|
|
423
|
+
if (sum.problems.length) {
|
|
424
|
+
console.log("\nlately");
|
|
425
|
+
for (const p of sum.problems) console.log(` ${new Date(p.ts).toLocaleTimeString()} ${p.what}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
//#endregion
|
|
429
|
+
export { perfCommand };
|
|
@@ -189,7 +189,10 @@ function logJam(root, raw) {
|
|
|
189
189
|
async function drain(root, w) {
|
|
190
190
|
const file = jamLog(root);
|
|
191
191
|
try {
|
|
192
|
-
mkdirSync(join(file, ".."), {
|
|
192
|
+
mkdirSync(join(file, ".."), {
|
|
193
|
+
recursive: true,
|
|
194
|
+
mode: 448
|
|
195
|
+
});
|
|
193
196
|
} catch {}
|
|
194
197
|
while (w.queue.length || w.dropped) {
|
|
195
198
|
const lines = w.queue.splice(0);
|
|
@@ -205,7 +208,7 @@ async function drain(root, w) {
|
|
|
205
208
|
w.dropped = 0;
|
|
206
209
|
}
|
|
207
210
|
try {
|
|
208
|
-
await (jamSeams.append ?? appendFile)(file, lines.join(""));
|
|
211
|
+
await (jamSeams.append ?? ((f, d) => appendFile(f, d, { mode: 384 })))(file, lines.join(""));
|
|
209
212
|
if (++w.writes % 50 === 0 && (await stat(file)).size > MAX_FILE) {
|
|
210
213
|
const all = (await readFile(file, "utf8")).split("\n");
|
|
211
214
|
await writeFile(file, all.slice(Math.floor(all.length / 2)).join("\n"));
|