Repository navigation
Expand file tree
/
Copy pathapp.mjs
More file actions
143 lines (123 loc) · 4.89 KB
/
Copy pathapp.mjs
File metadata and controls
143 lines (123 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { summarizeRuns } from './lib/stats.mjs';
const RUNS = [
{ key: 'chrome152', file: 'fixtures/chrome152-small.json' },
{ key: 'firefox155-idle', file: 'fixtures/firefox155-small.json' },
{ key: 'firefox155-kick', file: 'fixtures/firefox155-kick-small.json' },
{ key: 'firefox155-kick20', file: 'fixtures/firefox155-kick20-fixed.json' },
];
const SCALE_MAX_MS = 100;
// Truncate to 2 decimals for display; raw fixture values carry
// float noise (e.g. 3.850000001490116) that must never reach the DOM.
export function formatMs(ms) {
return `${Number(ms.toFixed(2))} ms`;
}
function pct(ms) {
return `${Math.min(100, (ms / SCALE_MAX_MS) * 100).toFixed(1)}%`;
}
const RUN_LABELS = {
chrome152: 'Chrome 152',
'firefox155-idle': 'Firefox 155 idle',
'firefox155-kick': 'Firefox + fast kicks',
'firefox155-kick20': 'Firefox + 20 ms kick',
};
// GPU display is median-only everywhere in this artifact. Kick-mode
// captures interleave empty diagnostic submissions with the real workload
// dispatch, so their raw gpu.min/gpu.mean are contaminated (see LB-1) and
// must never be rendered as if they described the 65536-item workload.
export function buildDistributionRow(key, summary) {
return {
key,
label: RUN_LABELS[key],
gpuMedian: formatMs(summary.gpu.median),
hostMin: formatMs(summary.wall.min),
hostMedian: formatMs(summary.wall.median),
hostMax: formatMs(summary.wall.max),
};
}
function setMetric(scope, name, text) {
scope.querySelectorAll(`[data-metric="${name}"]`).forEach((el) => {
el.textContent = text;
});
}
async function loadRun({ file }) {
const response = await fetch(file);
const payload = await response.json();
return summarizeRuns(payload);
}
function wireReproDialog() {
const trigger = document.getElementById('cta-run-trigger');
const reproDialog = document.getElementById('repro-dialog');
const reproFrame = document.getElementById('repro-frame');
const reproClose = document.getElementById('repro-close');
if (!trigger || !reproDialog || !reproFrame || !reproClose) return;
const openRepro = () => {
if (!reproFrame.getAttribute('src') || reproFrame.src === 'about:blank') {
reproFrame.src = reproFrame.dataset.src;
}
if (!reproDialog.open) reproDialog.showModal();
};
const closeRepro = () => {
if (reproDialog.open) reproDialog.close();
};
trigger.addEventListener('click', openRepro);
reproClose.addEventListener('click', closeRepro);
reproDialog.addEventListener('click', (event) => {
if (event.target === reproDialog) closeRepro();
});
reproDialog.addEventListener('close', () => {
reproFrame.src = 'about:blank';
});
}
async function render() {
const summaries = {};
for (const run of RUNS) {
summaries[run.key] = await loadRun(run);
}
for (const [key, summary] of Object.entries(summaries)) {
document.querySelectorAll(`[data-run="${key}"]`).forEach((scope) => {
setMetric(scope, 'host-median', formatMs(summary.wall.median));
setMetric(scope, 'host-median-inline', formatMs(summary.wall.median));
setMetric(scope, 'gpu-median', formatMs(summary.gpu.median));
setMetric(scope, 'kicks-median', `${summary.kicks.median}`);
const bar = scope.querySelector('[data-bar]');
if (bar) bar.style.width = pct(summary.wall.median);
const gpuMarker = scope.querySelector('[data-marker="gpu"]');
if (gpuMarker) gpuMarker.style.left = pct(summary.gpu.median);
const hostMarker = scope.querySelector('[data-marker="host"]');
if (hostMarker) hostMarker.style.left = pct(summary.wall.median);
});
}
// Sample/warmup counts are identical across every canonical fixture
// (verified in tests/presentation-guard.test.mjs); read from data rather
// than typed as copy so a fixture swap cannot silently go stale (LB-A3).
const canonical = Object.values(summaries)[0];
setMetric(document, 'samples', `${canonical.samples}`);
setMetric(document, 'warmups', `${canonical.warmups}`);
const distributionBody = document.querySelector('[data-distribution-body]');
if (distributionBody) {
distributionBody.innerHTML = RUNS.map(({ key }) => {
const row = buildDistributionRow(key, summaries[key]);
return `<tr>
<td>${row.label}</td>
<td>${row.gpuMedian}</td>
<td>${row.hostMin}</td>
<td class="dist-median">${row.hostMedian}</td>
<td>${row.hostMax}</td>
</tr>`;
}).join('');
}
}
// Guarded so this module can be imported under Node (no `document`) for
// unit tests of formatMs/buildDistributionRow without triggering a browser render.
if (typeof document !== 'undefined') {
wireReproDialog();
render().catch((err) => {
const main = document.querySelector('main');
if (main) {
const notice = document.createElement('p');
notice.textContent = `Failed to load fixture data: ${err.message}`;
notice.style.color = '#ffffff';
main.prepend(notice);
}
});
}