@drupflare/spool 0.3.0 → 1.0.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/README.md +279 -1607
- package/dist/angular/index.d.ts +13 -0
- package/dist/angular/index.js +25 -0
- package/dist/angular/pages.d.ts +28 -0
- package/dist/angular/pages.js +85 -0
- package/dist/cdn/client.js +1 -1
- package/dist/cdn/location.d.ts +6 -0
- package/dist/cdn/location.js +8 -0
- package/dist/cdn/manifest.json +7 -7
- package/dist/cdn/spool-sw.js +1 -1
- package/dist/client/bootstrap.d.ts +57 -0
- package/dist/client/bootstrap.js +307 -0
- package/dist/client/contact.d.ts +24 -0
- package/dist/client/contact.js +66 -0
- package/dist/client/declared.d.ts +23 -0
- package/dist/client/declared.js +68 -0
- package/dist/client/entry.js +123 -2
- package/dist/client/gate.d.ts +1 -0
- package/dist/client/gate.js +148 -0
- package/dist/client/index.d.ts +25 -0
- package/dist/client/index.js +1 -0
- package/dist/client/live.d.ts +66 -0
- package/dist/client/live.js +225 -0
- package/dist/client/navigate-entry.d.ts +1 -0
- package/dist/client/navigate-entry.js +4 -0
- package/dist/client/navigate.d.ts +54 -0
- package/dist/client/navigate.js +272 -0
- package/dist/client/persist.d.ts +2 -0
- package/dist/client/persist.js +9 -0
- package/dist/client/register.d.ts +34 -2
- package/dist/client/register.js +64 -7
- package/dist/express/index.d.ts +11 -0
- package/dist/express/index.js +209 -0
- package/dist/hono/index.d.ts +19 -0
- package/dist/hono/index.js +49 -0
- package/dist/next/index.d.ts +33 -0
- package/dist/next/index.js +41 -0
- package/dist/next/pages.d.ts +22 -0
- package/dist/next/pages.js +39 -0
- package/dist/node/listener.d.ts +3 -0
- package/dist/node/listener.js +57 -2
- package/dist/nuxt/index.d.ts +22 -0
- package/dist/nuxt/index.js +104 -0
- package/dist/nuxt/pages.d.ts +26 -0
- package/dist/nuxt/pages.js +48 -0
- package/dist/nuxt/runtime/index.d.ts +24 -0
- package/dist/nuxt/runtime/index.js +58 -0
- package/dist/plugins/coverage.d.ts +14 -0
- package/dist/plugins/coverage.js +27 -0
- package/dist/plugins/mode.d.ts +19 -0
- package/dist/plugins/mode.js +20 -0
- package/dist/plugins/path.d.ts +16 -0
- package/dist/plugins/path.js +139 -0
- package/dist/plugins/report.d.ts +22 -0
- package/dist/plugins/report.js +18 -0
- package/dist/plugins/routes.d.ts +38 -0
- package/dist/plugins/routes.js +52 -0
- package/dist/plugins/static.d.ts +42 -0
- package/dist/plugins/static.js +97 -0
- package/dist/protocol/bundle.d.ts +111 -0
- package/dist/protocol/bundle.js +428 -0
- package/dist/protocol/config.d.ts +80 -1
- package/dist/protocol/config.js +31 -1
- package/dist/protocol/dataset.d.ts +189 -0
- package/dist/protocol/dataset.js +212 -0
- package/dist/protocol/envelope.d.ts +34 -1
- package/dist/protocol/envelope.js +16 -1
- package/dist/protocol/errors.d.ts +1 -1
- package/dist/protocol/graph.d.ts +23 -4
- package/dist/protocol/graph.js +34 -3
- package/dist/protocol/index-rows.d.ts +22 -0
- package/dist/protocol/index-rows.js +53 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.js +5 -0
- package/dist/protocol/normalise.d.ts +4 -4
- package/dist/protocol/normalise.js +9 -5
- package/dist/protocol/plan.d.ts +100 -0
- package/dist/protocol/plan.js +661 -0
- package/dist/protocol/provision.d.ts +46 -0
- package/dist/protocol/provision.js +38 -0
- package/dist/protocol/query.d.ts +66 -5
- package/dist/protocol/query.js +103 -4
- package/dist/protocol/ring.d.ts +58 -0
- package/dist/protocol/ring.js +6 -0
- package/dist/protocol/route.d.ts +63 -13
- package/dist/protocol/route.js +126 -6
- package/dist/protocol/tag.d.ts +22 -2
- package/dist/protocol/tag.js +25 -4
- package/dist/protocol/view.d.ts +2 -0
- package/dist/protocol/view.js +8 -2
- package/dist/protocol/views.d.ts +6 -0
- package/dist/protocol/views.js +15 -0
- package/dist/protocol/write.d.ts +234 -0
- package/dist/protocol/write.js +343 -0
- package/dist/proxy/eligible.d.ts +22 -1
- package/dist/proxy/eligible.js +62 -15
- package/dist/proxy/proxy.js +28 -18
- package/dist/react-router/index.d.ts +20 -0
- package/dist/react-router/index.js +60 -0
- package/dist/react-router/pages.d.ts +34 -0
- package/dist/react-router/pages.js +83 -0
- package/dist/report/dataset.d.ts +48 -0
- package/dist/report/dataset.js +93 -0
- package/dist/report/demand.d.ts +49 -0
- package/dist/report/demand.js +60 -0
- package/dist/report/derive.d.ts +285 -0
- package/dist/report/derive.js +676 -1
- package/dist/report/economics.d.ts +66 -1
- package/dist/report/economics.js +208 -1
- package/dist/report/headline.d.ts +158 -0
- package/dist/report/headline.js +473 -0
- package/dist/report/index.d.ts +4 -0
- package/dist/report/index.js +4 -0
- package/dist/report/inputs.d.ts +176 -0
- package/dist/report/inputs.js +248 -0
- package/dist/report/institution.d.ts +188 -1
- package/dist/report/institution.js +146 -0
- package/dist/report/loops.d.ts +73 -0
- package/dist/report/loops.js +101 -0
- package/dist/report/measurement.d.ts +1 -1
- package/dist/report/measurement.js +7 -1
- package/dist/report/model.d.ts +2 -0
- package/dist/report/model.js +4 -0
- package/dist/report/thirdparty.d.ts +57 -0
- package/dist/report/thirdparty.js +111 -0
- package/dist/report/traffic.d.ts +8 -0
- package/dist/report/traffic.js +7 -0
- package/dist/report/trim.d.ts +56 -0
- package/dist/report/trim.js +83 -1
- package/dist/server/bundle.d.ts +55 -0
- package/dist/server/bundle.js +172 -0
- package/dist/server/dataset.d.ts +54 -0
- package/dist/server/dataset.js +355 -0
- package/dist/server/embedded.d.ts +7 -3
- package/dist/server/embedded.js +7 -3
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +6 -0
- package/dist/server/live-sockets.d.ts +54 -0
- package/dist/server/live-sockets.js +131 -0
- package/dist/server/live.d.ts +146 -0
- package/dist/server/live.js +228 -0
- package/dist/server/ring.d.ts +77 -0
- package/dist/server/ring.js +311 -0
- package/dist/server/spool.d.ts +158 -3
- package/dist/server/spool.js +578 -41
- package/dist/server/static.d.ts +42 -0
- package/dist/server/static.js +29 -0
- package/dist/server/stub.d.ts +43 -5
- package/dist/server/stub.js +126 -8
- package/dist/server/write.d.ts +49 -0
- package/dist/server/write.js +223 -0
- package/dist/stores/durable-object.d.ts +46 -0
- package/dist/stores/durable-object.js +114 -0
- package/dist/sw/analytics.d.ts +7 -1
- package/dist/sw/analytics.js +16 -2
- package/dist/sw/coverage.d.ts +6 -0
- package/dist/sw/coverage.js +34 -0
- package/dist/sw/dataset-sync.d.ts +76 -0
- package/dist/sw/dataset-sync.js +149 -0
- package/dist/sw/dataset.d.ts +91 -0
- package/dist/sw/dataset.js +318 -0
- package/dist/sw/family.d.ts +15 -0
- package/dist/sw/family.js +48 -0
- package/dist/sw/graph/index.d.ts +31 -1
- package/dist/sw/graph/index.js +57 -5
- package/dist/sw/graph/invalidate.d.ts +15 -3
- package/dist/sw/graph/invalidate.js +42 -4
- package/dist/sw/idb.d.ts +2 -0
- package/dist/sw/idb.js +80 -11
- package/dist/sw/index.d.ts +2 -0
- package/dist/sw/index.js +1 -0
- package/dist/sw/pack/store.d.ts +128 -0
- package/dist/sw/pack/store.js +737 -0
- package/dist/sw/partition.d.ts +6 -1
- package/dist/sw/partition.js +21 -2
- package/dist/sw/policy.d.ts +2 -0
- package/dist/sw/policy.js +11 -0
- package/dist/sw/principal-dataset.d.ts +64 -0
- package/dist/sw/principal-dataset.js +254 -0
- package/dist/sw/probe.d.ts +16 -0
- package/dist/sw/probe.js +25 -0
- package/dist/sw/render.d.ts +7 -2
- package/dist/sw/render.js +19 -5
- package/dist/sw/replica.d.ts +12 -3
- package/dist/sw/replica.js +40 -5
- package/dist/sw/router.d.ts +3 -2
- package/dist/sw/router.js +15 -2
- package/dist/sw/runtime.d.ts +90 -2
- package/dist/sw/runtime.js +857 -61
- package/dist/sw/scheduler.d.ts +6 -1
- package/dist/sw/scheduler.js +22 -5
- package/dist/sw/seal.d.ts +13 -0
- package/dist/sw/seal.js +13 -4
- package/dist/sw/static.d.ts +18 -0
- package/dist/sw/static.js +84 -1
- package/dist/sw/storage.d.ts +51 -1
- package/dist/sw/storage.js +33 -1
- package/dist/sw/write.d.ts +147 -0
- package/dist/sw/write.js +625 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -2
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.js +66 -0
- package/dist/vue/index.d.ts +36 -0
- package/dist/vue/index.js +53 -0
- package/package.json +65 -4
package/dist/report/derive.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { attributionalJoules } from './model.js';
|
|
1
2
|
import { classifyOrigin } from './thirdparty.js';
|
|
2
3
|
/** a window is dropped when the other containers on the host used more CPU than this, per second */
|
|
3
4
|
export const CONTAMINATION_MS_PER_S = 100;
|
|
@@ -122,6 +123,77 @@ export function raplRun(rows, options = {}) {
|
|
|
122
123
|
export function saving(a, b) {
|
|
123
124
|
return a.joules.median - b.joules.median;
|
|
124
125
|
}
|
|
126
|
+
const THREE_TAB_ARMS = ['tabs-3-poll', 'tabs-3-leader'];
|
|
127
|
+
/**
|
|
128
|
+
* Joules per minute above the idle draw of each kept window of an idle-activity-tabs run, per arm.
|
|
129
|
+
* A window is dropped over the contamination limit. The idle draw is the median of the kept idle
|
|
130
|
+
* windows of its round. The two three-tab polling arms are netted against the tabs-3-quiet window
|
|
131
|
+
* of the same round, and a window whose round has none is left out. The one-tab and hidden arms
|
|
132
|
+
* are not netted against a quiet arm: the rig has no quiet arm for them.
|
|
133
|
+
*/
|
|
134
|
+
export function tabsFigures(rows) {
|
|
135
|
+
const seconds = (row) => num(row, 'elapsedMs') / 1000;
|
|
136
|
+
const kept = rows.filter((row) => !isContaminated(row));
|
|
137
|
+
const dropped = rows.length - kept.length;
|
|
138
|
+
const watts = (row) => num(row, 'pkgJ') / seconds(row);
|
|
139
|
+
const idleByRound = new Map();
|
|
140
|
+
for (const row of kept) {
|
|
141
|
+
if (str(row, 'arm') !== 'idle')
|
|
142
|
+
continue;
|
|
143
|
+
const round = num(row, 'round');
|
|
144
|
+
idleByRound.set(round, [...(idleByRound.get(round) ?? []), watts(row)]);
|
|
145
|
+
}
|
|
146
|
+
const idleRound = new Map([...idleByRound].map(([round, w]) => [round, median(w)]));
|
|
147
|
+
if (idleRound.size === 0) {
|
|
148
|
+
return { idleWatts: null, dropped, unmatched: 0, arms: {}, ratio: {} };
|
|
149
|
+
}
|
|
150
|
+
const idleWatts = spread([...idleRound.values()]);
|
|
151
|
+
const perMinute = (row) => (watts(row) - (idleRound.get(num(row, 'round')) ?? idleWatts.median)) * 60;
|
|
152
|
+
const pingsPerMinute = (row) => (num(row, 'originPings') / seconds(row)) * 60;
|
|
153
|
+
const floor = new Map();
|
|
154
|
+
const byArm = {};
|
|
155
|
+
for (const row of kept) {
|
|
156
|
+
const arm = str(row, 'arm');
|
|
157
|
+
if (arm === 'tabs-3-quiet')
|
|
158
|
+
floor.set(num(row, 'round'), perMinute(row));
|
|
159
|
+
if (arm !== 'idle')
|
|
160
|
+
(byArm[arm] ??= []).push(row);
|
|
161
|
+
}
|
|
162
|
+
let unmatched = 0;
|
|
163
|
+
const arms = {};
|
|
164
|
+
for (const [arm, windows] of Object.entries(byArm)) {
|
|
165
|
+
const threeTab = THREE_TAB_ARMS.includes(arm);
|
|
166
|
+
const net = windows.flatMap((row) => {
|
|
167
|
+
const base = threeTab ? floor.get(num(row, 'round')) : 0;
|
|
168
|
+
if (base === undefined) {
|
|
169
|
+
unmatched++;
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
return [{ joules: perMinute(row) - base, pings: pingsPerMinute(row) }];
|
|
173
|
+
});
|
|
174
|
+
if (net.length === 0)
|
|
175
|
+
continue;
|
|
176
|
+
arms[arm] = {
|
|
177
|
+
windows: net.length,
|
|
178
|
+
floor: threeTab ? 'tabs-3-quiet' : 'idle',
|
|
179
|
+
joulesPerMinute: spread(net.map((n) => n.joules)),
|
|
180
|
+
pingsPerMinute: spread(net.map((n) => n.pings))
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const poll3 = arms['tabs-3-poll']?.joulesPerMinute.median;
|
|
184
|
+
const leader = arms['tabs-3-leader']?.joulesPerMinute.median;
|
|
185
|
+
const poll1 = arms['tabs-1-poll']?.joulesPerMinute.median;
|
|
186
|
+
return {
|
|
187
|
+
idleWatts,
|
|
188
|
+
dropped,
|
|
189
|
+
unmatched,
|
|
190
|
+
arms,
|
|
191
|
+
ratio: {
|
|
192
|
+
...(poll3 !== undefined && leader !== undefined && { poll3ToLeader: poll3 / leader }),
|
|
193
|
+
...(poll3 !== undefined && poll1 !== undefined && { poll3ToPoll1: poll3 / poll1 })
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
125
197
|
/**
|
|
126
198
|
* {@link InferenceFigures} from the rows of an inference run. A round needs its unloaded and
|
|
127
199
|
* loaded idle windows and its recompute window; rounds over the contamination limit are dropped.
|
|
@@ -311,7 +383,7 @@ export function runtimeRun(rows) {
|
|
|
311
383
|
return out;
|
|
312
384
|
}
|
|
313
385
|
/** a navigation that loaded the site's page; a 4xx or 5xx document is a block page, not the site */
|
|
314
|
-
function loaded(nav) {
|
|
386
|
+
export function loaded(nav) {
|
|
315
387
|
return nav.ok === true && (num(nav, 'docStatus') ?? 200) < 400;
|
|
316
388
|
}
|
|
317
389
|
/** bytes and request counts by navigation kind, over the navigations that loaded */
|
|
@@ -492,3 +564,606 @@ export function onWireFigures(rows) {
|
|
|
492
564
|
}
|
|
493
565
|
return out;
|
|
494
566
|
}
|
|
567
|
+
/** ordinary least squares by the normal equations; `X` rows must each hold every column */
|
|
568
|
+
export function leastSquares(X, y) {
|
|
569
|
+
const n = X.length;
|
|
570
|
+
const p = X[0]?.length ?? 0;
|
|
571
|
+
if (p === 0 || n <= p)
|
|
572
|
+
throw new RangeError('a fit needs more points than coefficients');
|
|
573
|
+
const a = Array.from({ length: p }, () => new Array(p + 1).fill(0));
|
|
574
|
+
for (let i = 0; i < n; i++) {
|
|
575
|
+
const row = X[i];
|
|
576
|
+
for (let r = 0; r < p; r++) {
|
|
577
|
+
for (let c = 0; c < p; c++) {
|
|
578
|
+
const ar = a[r];
|
|
579
|
+
ar[c] = ar[c] + row[r] * row[c];
|
|
580
|
+
}
|
|
581
|
+
const last = a[r];
|
|
582
|
+
last[p] = last[p] + row[r] * y[i];
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
for (let col = 0; col < p; col++) {
|
|
586
|
+
let pivot = col;
|
|
587
|
+
for (let r = col + 1; r < p; r++) {
|
|
588
|
+
if (Math.abs(a[r][col]) >
|
|
589
|
+
Math.abs(a[pivot][col]))
|
|
590
|
+
pivot = r;
|
|
591
|
+
}
|
|
592
|
+
[a[col], a[pivot]] = [a[pivot], a[col]];
|
|
593
|
+
const head = a[col];
|
|
594
|
+
if (Math.abs(head[col]) < 1e-12)
|
|
595
|
+
throw new RangeError('the columns are collinear');
|
|
596
|
+
for (let r = 0; r < p; r++) {
|
|
597
|
+
if (r === col)
|
|
598
|
+
continue;
|
|
599
|
+
const row = a[r];
|
|
600
|
+
const factor = row[col] / head[col];
|
|
601
|
+
for (let c = col; c <= p; c++)
|
|
602
|
+
row[c] = row[c] - factor * head[c];
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const coef = a.map((row, i) => row[p] / row[i]);
|
|
606
|
+
let rss = 0;
|
|
607
|
+
for (let i = 0; i < n; i++) {
|
|
608
|
+
const fitted = coef.reduce((s, b, j) => s + b * X[i][j], 0);
|
|
609
|
+
rss += (y[i] - fitted) ** 2;
|
|
610
|
+
}
|
|
611
|
+
return { coef, rss, residualSe: Math.sqrt(rss / (n - p)), n };
|
|
612
|
+
}
|
|
613
|
+
/** the key of the null route in a `drupal-render` reading: arm, URL class and phase */
|
|
614
|
+
export const DRUPAL_NULL_KEY = 'null/null/steady';
|
|
615
|
+
const counts = (value) => typeof value === 'object' && value !== null ? value : {};
|
|
616
|
+
const addCounts = (into, from) => {
|
|
617
|
+
for (const [key, n] of Object.entries(from))
|
|
618
|
+
into[key] = (into[key] ?? 0) + n;
|
|
619
|
+
};
|
|
620
|
+
/**
|
|
621
|
+
* Joules per request of a `drupal-render` reading. A window's energy less its round's idle draw
|
|
622
|
+
* times its length, over its requests. Each round pairs an arm's window with the null route's
|
|
623
|
+
* window of the same round, so the net figure is paired per round, not a difference of medians.
|
|
624
|
+
*/
|
|
625
|
+
export function drupalRenderFigures(rows) {
|
|
626
|
+
const kept = rows.filter((row) => !isContaminated(row));
|
|
627
|
+
const dropped = rows.length - kept.length;
|
|
628
|
+
const seconds = (row) => num(row, 'elapsedMs') / 1000;
|
|
629
|
+
const idleByRound = new Map();
|
|
630
|
+
for (const row of kept) {
|
|
631
|
+
if (str(row, 'arm') !== 'idle')
|
|
632
|
+
continue;
|
|
633
|
+
const round = num(row, 'round');
|
|
634
|
+
idleByRound.set(round, [
|
|
635
|
+
...(idleByRound.get(round) ?? []),
|
|
636
|
+
num(row, 'pkgJ') / seconds(row)
|
|
637
|
+
]);
|
|
638
|
+
}
|
|
639
|
+
const idle = new Map([...idleByRound].map(([round, w]) => [round, mean(w)]));
|
|
640
|
+
const idleWatts = spread([...idle.values()]);
|
|
641
|
+
const cells = new Map();
|
|
642
|
+
for (const row of kept) {
|
|
643
|
+
const arm = str(row, 'arm');
|
|
644
|
+
if (arm === 'idle')
|
|
645
|
+
continue;
|
|
646
|
+
const key = `${arm}/${str(row, 'url')}/${str(row, 'phase')}`;
|
|
647
|
+
const round = num(row, 'round');
|
|
648
|
+
const watts = idle.get(round) ?? idleWatts.median;
|
|
649
|
+
const n = num(row, 'n');
|
|
650
|
+
const cell = cells.get(key) ?? {
|
|
651
|
+
joules: new Map(),
|
|
652
|
+
status: {},
|
|
653
|
+
cache: { page: {}, dynamic: {} }
|
|
654
|
+
};
|
|
655
|
+
cell.joules.set(round, [
|
|
656
|
+
...(cell.joules.get(round) ?? []),
|
|
657
|
+
(num(row, 'pkgJ') - watts * seconds(row)) / n
|
|
658
|
+
]);
|
|
659
|
+
addCounts(cell.status, counts(row.status));
|
|
660
|
+
addCounts(cell.cache.page, counts(row.pageCache));
|
|
661
|
+
addCounts(cell.cache.dynamic, counts(row.dynamicCache));
|
|
662
|
+
cells.set(key, cell);
|
|
663
|
+
}
|
|
664
|
+
const perRound = (cell) => new Map([...cell.joules].map(([r, js]) => [r, mean(js)]));
|
|
665
|
+
const nullCell = cells.get(DRUPAL_NULL_KEY);
|
|
666
|
+
const nullRounds = nullCell ? perRound(nullCell) : new Map();
|
|
667
|
+
const arms = {};
|
|
668
|
+
for (const [key, cell] of cells) {
|
|
669
|
+
const rounds = perRound(cell);
|
|
670
|
+
const paired = [...rounds]
|
|
671
|
+
.filter(([round]) => nullRounds.has(round))
|
|
672
|
+
.map(([round, g]) => g - nullRounds.get(round));
|
|
673
|
+
arms[key] = {
|
|
674
|
+
rounds: rounds.size,
|
|
675
|
+
gross: spread([...rounds.values()]),
|
|
676
|
+
net: key === DRUPAL_NULL_KEY || paired.length === 0 ? null : spread(paired),
|
|
677
|
+
status: cell.status,
|
|
678
|
+
cache: cell.cache
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
rounds: new Set(kept.map((row) => num(row, 'round'))).size,
|
|
683
|
+
dropped,
|
|
684
|
+
idleWatts,
|
|
685
|
+
arms
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const MB = 1e6;
|
|
689
|
+
/** the mean of a non-empty list */
|
|
690
|
+
const mean = (values) => values.reduce((s, v) => s + v, 0) / values.length;
|
|
691
|
+
/**
|
|
692
|
+
* The first-view figures of a `rapl first-view` reading. A window's joules are its package energy
|
|
693
|
+
* less the idle draw of its round times its length, over its navigations. Each page's figure is the
|
|
694
|
+
* median over the rounds of its original arm; the facade arm is compared with the same page's
|
|
695
|
+
* original arm. The fit is ordinary least squares of each page's joules on its image, script and
|
|
696
|
+
* other bytes, so its coefficients and shares are indicative at this many pages.
|
|
697
|
+
*/
|
|
698
|
+
export function firstViewFigures(measurement) {
|
|
699
|
+
const pages = measurement.method['corpus pages'];
|
|
700
|
+
const kept = measurement.rows.filter((r) => !isContaminated(r));
|
|
701
|
+
const dropped = measurement.rows.length - kept.length;
|
|
702
|
+
const idle = new Map();
|
|
703
|
+
for (const row of kept) {
|
|
704
|
+
if (str(row, 'arm') === 'idle') {
|
|
705
|
+
const seconds = num(row, 'elapsedMs') / 1000;
|
|
706
|
+
idle.set(num(row, 'round'), num(row, 'pkgJ') / seconds);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const idleWatts = spread([...idle.values()]);
|
|
710
|
+
const cells = new Map();
|
|
711
|
+
for (const row of kept) {
|
|
712
|
+
const arm = str(row, 'arm');
|
|
713
|
+
if (arm !== 'original' && arm !== 'facade')
|
|
714
|
+
continue;
|
|
715
|
+
const page = str(row, 'page');
|
|
716
|
+
const entry = cells.get(page) ?? {
|
|
717
|
+
original: { joules: [], bytes: [], missed: 0 },
|
|
718
|
+
facade: { joules: [], bytes: [], missed: 0 }
|
|
719
|
+
};
|
|
720
|
+
const cell = entry[arm];
|
|
721
|
+
const seconds = num(row, 'elapsedMs') / 1000;
|
|
722
|
+
const navs = num(row, 'navs');
|
|
723
|
+
const watts = idle.get(num(row, 'round')) ?? idleWatts.median;
|
|
724
|
+
cell.joules.push((num(row, 'pkgJ') - watts * seconds) / navs);
|
|
725
|
+
cell.bytes.push(num(row, 'servedTotal') / navs);
|
|
726
|
+
cell.missed += num(row, 'missed') ?? 0;
|
|
727
|
+
cells.set(page, entry);
|
|
728
|
+
}
|
|
729
|
+
const measured = pages
|
|
730
|
+
.filter((p) => cells.get(p.id)?.original.joules.length)
|
|
731
|
+
.map((p) => {
|
|
732
|
+
const cell = cells.get(p.id);
|
|
733
|
+
const joules = median(cell.original.joules);
|
|
734
|
+
const attributional = attributionalJoules(p.wireBytes);
|
|
735
|
+
const image = p.classBytes.image ?? 0;
|
|
736
|
+
const script = p.classBytes.script ?? 0;
|
|
737
|
+
const facade = cell.facade.joules.length > 0 ? cell.facade : null;
|
|
738
|
+
return {
|
|
739
|
+
page: p,
|
|
740
|
+
joules,
|
|
741
|
+
attributional,
|
|
742
|
+
ratio: joules / attributional,
|
|
743
|
+
image,
|
|
744
|
+
script,
|
|
745
|
+
other: p.wireBytes - image - script,
|
|
746
|
+
bytes: median(cell.original.bytes),
|
|
747
|
+
missed: cell.original.missed + cell.facade.missed,
|
|
748
|
+
facade: facade && {
|
|
749
|
+
joules: median(facade.joules),
|
|
750
|
+
bytes: median(facade.bytes)
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
});
|
|
754
|
+
const bySite = new Map();
|
|
755
|
+
for (const m of measured)
|
|
756
|
+
bySite.set(m.page.site, [...(bySite.get(m.page.site) ?? []), m.ratio]);
|
|
757
|
+
const siteMeans = [...bySite.values()].map((ratios) => mean(ratios));
|
|
758
|
+
const fit = leastSquares(measured.map((m) => [1, m.image / MB, m.script / MB, m.other / MB]), measured.map((m) => m.joules));
|
|
759
|
+
const sumJ = measured.reduce((s, m) => s + m.joules, 0);
|
|
760
|
+
const sumMb = (pick) => measured.reduce((s, m) => s + pick(m) / MB, 0);
|
|
761
|
+
const withFacade = measured.filter((m) => m.facade !== null);
|
|
762
|
+
const savedJ = withFacade.map((m) => m.joules - m.facade.joules);
|
|
763
|
+
const savedBytes = withFacade.map((m) => m.bytes - m.facade.bytes);
|
|
764
|
+
const meanJ = mean(measured.map((m) => m.joules));
|
|
765
|
+
const meanAttr = mean(measured.map((m) => m.attributional));
|
|
766
|
+
return {
|
|
767
|
+
rounds: new Set(kept.filter((r) => str(r, 'arm') === 'original').map((r) => num(r, 'round'))).size,
|
|
768
|
+
pages: measured.length,
|
|
769
|
+
sites: bySite.size,
|
|
770
|
+
wireBytes: measured.reduce((s, m) => s + m.page.wireBytes, 0),
|
|
771
|
+
dropped,
|
|
772
|
+
idleWatts,
|
|
773
|
+
joules: { mean: meanJ, median: median(measured.map((m) => m.joules)) },
|
|
774
|
+
attributional: {
|
|
775
|
+
mean: meanAttr,
|
|
776
|
+
median: median(measured.map((m) => m.attributional))
|
|
777
|
+
},
|
|
778
|
+
ratio: {
|
|
779
|
+
mean: mean(measured.map((m) => m.ratio)),
|
|
780
|
+
median: median(measured.map((m) => m.ratio)),
|
|
781
|
+
ofMeans: meanJ / meanAttr,
|
|
782
|
+
siteMin: Math.min(...siteMeans),
|
|
783
|
+
siteMax: Math.max(...siteMeans),
|
|
784
|
+
sites: bySite.size
|
|
785
|
+
},
|
|
786
|
+
fit: {
|
|
787
|
+
n: fit.n,
|
|
788
|
+
intercept: fit.coef[0],
|
|
789
|
+
image: fit.coef[1],
|
|
790
|
+
script: fit.coef[2],
|
|
791
|
+
other: fit.coef[3],
|
|
792
|
+
residualSe: fit.residualSe,
|
|
793
|
+
shares: {
|
|
794
|
+
intercept: (fit.coef[0] * fit.n) / sumJ,
|
|
795
|
+
image: (fit.coef[1] * sumMb((m) => m.image)) / sumJ,
|
|
796
|
+
script: (fit.coef[2] * sumMb((m) => m.script)) / sumJ,
|
|
797
|
+
other: (fit.coef[3] * sumMb((m) => m.other)) / sumJ
|
|
798
|
+
}
|
|
799
|
+
},
|
|
800
|
+
facade: withFacade.length === 0
|
|
801
|
+
? null
|
|
802
|
+
: {
|
|
803
|
+
pages: withFacade.length,
|
|
804
|
+
savedJ: { mean: mean(savedJ), median: median(savedJ) },
|
|
805
|
+
savedBytes: { mean: mean(savedBytes), median: median(savedBytes) },
|
|
806
|
+
savedShare: mean(withFacade.map((m, i) => savedJ[i] / m.joules))
|
|
807
|
+
},
|
|
808
|
+
missedPages: measured.filter((m) => m.missed > 0).map((m) => m.page.id)
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* The device cost of splitting one page's scripts. A window's joules are its package energy less the
|
|
813
|
+
* idle draw of its round, over its navigations, as in `firstViewFigures`. Each file count's figure is
|
|
814
|
+
* the median over rounds. The fit is a least-squares line of joules on requests across the file
|
|
815
|
+
* counts of one delay; its intervals come from a bootstrap over rounds with a fixed seed. Byte
|
|
816
|
+
* penalties are against the one-file arm of the same delay.
|
|
817
|
+
*/
|
|
818
|
+
export function chunkSplitFigures(measurement) {
|
|
819
|
+
const kept = measurement.rows.filter((row) => !isContaminated(row));
|
|
820
|
+
const dropped = measurement.rows.length - kept.length;
|
|
821
|
+
const seconds = (row) => num(row, 'elapsedMs') / 1000;
|
|
822
|
+
const idleByRound = new Map();
|
|
823
|
+
for (const row of kept) {
|
|
824
|
+
if (str(row, 'arm') !== 'idle')
|
|
825
|
+
continue;
|
|
826
|
+
const round = num(row, 'round');
|
|
827
|
+
idleByRound.set(round, [
|
|
828
|
+
...(idleByRound.get(round) ?? []),
|
|
829
|
+
num(row, 'pkgJ') / seconds(row)
|
|
830
|
+
]);
|
|
831
|
+
}
|
|
832
|
+
const idle = new Map([...idleByRound].map(([round, w]) => [round, mean(w)]));
|
|
833
|
+
const idleWatts = spread([...idle.values()]);
|
|
834
|
+
const groups = new Map();
|
|
835
|
+
for (const row of kept) {
|
|
836
|
+
if (str(row, 'arm') !== 'chunks')
|
|
837
|
+
continue;
|
|
838
|
+
const round = num(row, 'round');
|
|
839
|
+
const navs = num(row, 'navs');
|
|
840
|
+
const chunks = num(row, 'chunks');
|
|
841
|
+
const rttMs = num(row, 'rttMs');
|
|
842
|
+
const watts = idle.get(round) ?? idleWatts.median;
|
|
843
|
+
const metrics = row.navMetrics;
|
|
844
|
+
const perNav = (key) => metrics.reduce((s, m) => s + (m.after[key] - m.before[key]), 0) / navs;
|
|
845
|
+
const key = `${rttMs}/${chunks}`;
|
|
846
|
+
const group = groups.get(key) ?? { chunks, rttMs, points: new Map() };
|
|
847
|
+
group.points.set(round, {
|
|
848
|
+
joules: (num(row, 'pkgJ') - watts * seconds(row)) / navs,
|
|
849
|
+
requests: num(row, 'requests') / navs,
|
|
850
|
+
bytes: num(row, 'servedTotal') / navs,
|
|
851
|
+
scriptMs: perNav('ScriptDuration') * 1000,
|
|
852
|
+
taskMs: perNav('TaskDuration') * 1000,
|
|
853
|
+
cpuMs: num(row, 'originCpuMs') / navs,
|
|
854
|
+
navErrors: num(row, 'navErrors') ?? 0
|
|
855
|
+
});
|
|
856
|
+
groups.set(key, group);
|
|
857
|
+
}
|
|
858
|
+
const delays = [...new Set([...groups.values()].map((g) => g.rttMs))].sort((a, b) => a - b);
|
|
859
|
+
const arms = [];
|
|
860
|
+
const fits = [];
|
|
861
|
+
for (const rttMs of delays) {
|
|
862
|
+
const group = [...groups.values()]
|
|
863
|
+
.filter((g) => g.rttMs === rttMs)
|
|
864
|
+
.sort((a, b) => a.chunks - b.chunks);
|
|
865
|
+
const values = (g, pick) => [...g.points.values()].map(pick);
|
|
866
|
+
const one = group.find((g) => g.chunks === 1);
|
|
867
|
+
const baseBytes = one ? median(values(one, (p) => p.bytes)) : NaN;
|
|
868
|
+
for (const g of group) {
|
|
869
|
+
const bytes = median(values(g, (p) => p.bytes));
|
|
870
|
+
const bytePenalty = bytes - baseBytes;
|
|
871
|
+
arms.push({
|
|
872
|
+
chunks: g.chunks,
|
|
873
|
+
rttMs,
|
|
874
|
+
rounds: g.points.size,
|
|
875
|
+
joules: spread(values(g, (p) => p.joules)),
|
|
876
|
+
requests: median(values(g, (p) => p.requests)),
|
|
877
|
+
bytes,
|
|
878
|
+
bytePenalty,
|
|
879
|
+
penaltyJ: attributionalJoules(bytePenalty),
|
|
880
|
+
scriptMs: median(values(g, (p) => p.scriptMs)),
|
|
881
|
+
taskMs: median(values(g, (p) => p.taskMs)),
|
|
882
|
+
originCpuMs: median(values(g, (p) => p.cpuMs)),
|
|
883
|
+
navErrors: values(g, (p) => p.navErrors).reduce((s, v) => s + v, 0)
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
const first = group[0];
|
|
887
|
+
const common = [...(first?.points.keys() ?? [])]
|
|
888
|
+
.filter((round) => group.every((g) => g.points.has(round)))
|
|
889
|
+
.sort((a, b) => a - b);
|
|
890
|
+
if (group.length >= 2 && common.length >= 2)
|
|
891
|
+
fits.push(chunkFit(rttMs, group, common));
|
|
892
|
+
}
|
|
893
|
+
return { dropped, idleWatts, arms, fits };
|
|
894
|
+
}
|
|
895
|
+
/** the line of one delay's file counts and its bootstrap over the rounds every count measured */
|
|
896
|
+
function chunkFit(rttMs, group, rounds) {
|
|
897
|
+
const line = (rs, field) => linearFit(group.map((g) => {
|
|
898
|
+
const at = (r) => g.points.get(r);
|
|
899
|
+
return [
|
|
900
|
+
median(rs.map((r) => at(r).requests)),
|
|
901
|
+
median(rs.map((r) => at(r)[field]))
|
|
902
|
+
];
|
|
903
|
+
}));
|
|
904
|
+
const point = {
|
|
905
|
+
joules: line(rounds, 'joules'),
|
|
906
|
+
script: line(rounds, 'scriptMs'),
|
|
907
|
+
task: line(rounds, 'taskMs')
|
|
908
|
+
};
|
|
909
|
+
const draw = lcg(BOOTSTRAP_SEED);
|
|
910
|
+
const reps = [];
|
|
911
|
+
for (let b = 0; b < BOOTSTRAP_REPLICATES; b++) {
|
|
912
|
+
const sample = Array.from({ length: rounds.length }, () => rounds[Math.floor(draw() * rounds.length)]);
|
|
913
|
+
const joules = line(sample, 'joules');
|
|
914
|
+
reps.push([
|
|
915
|
+
joules.slope,
|
|
916
|
+
joules.intercept,
|
|
917
|
+
line(sample, 'scriptMs').slope,
|
|
918
|
+
line(sample, 'taskMs').slope
|
|
919
|
+
]);
|
|
920
|
+
}
|
|
921
|
+
const interval = (value, column) => ({
|
|
922
|
+
value,
|
|
923
|
+
low: nearestRank(column, 0.025),
|
|
924
|
+
high: nearestRank(column, 0.975)
|
|
925
|
+
});
|
|
926
|
+
const slope = interval(point.joules.slope, reps.map((r) => r[0]));
|
|
927
|
+
return {
|
|
928
|
+
rttMs,
|
|
929
|
+
rounds: rounds.length,
|
|
930
|
+
slope,
|
|
931
|
+
intercept: interval(point.joules.intercept, reps.map((r) => r[1])),
|
|
932
|
+
scriptSlope: interval(point.script.slope, reps.map((r) => r[2])),
|
|
933
|
+
taskSlope: interval(point.task.slope, reps.map((r) => r[3])),
|
|
934
|
+
requestsPerJoule: slope.low > 0
|
|
935
|
+
? {
|
|
936
|
+
value: 1 / point.joules.slope,
|
|
937
|
+
low: 1 / slope.high,
|
|
938
|
+
high: 1 / slope.low
|
|
939
|
+
}
|
|
940
|
+
: null
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
/** one arm's windows by page: joules above the round's idle draw, and bytes, per navigation */
|
|
944
|
+
function armCells(rows, arm) {
|
|
945
|
+
const kept = rows.filter((row) => !isContaminated(row));
|
|
946
|
+
const idle = new Map();
|
|
947
|
+
for (const row of kept) {
|
|
948
|
+
if (str(row, 'arm') !== 'idle')
|
|
949
|
+
continue;
|
|
950
|
+
const seconds = num(row, 'elapsedMs') / 1000;
|
|
951
|
+
idle.set(num(row, 'round'), num(row, 'pkgJ') / seconds);
|
|
952
|
+
}
|
|
953
|
+
const idleWatts = median([...idle.values()]);
|
|
954
|
+
const cells = new Map();
|
|
955
|
+
for (const row of kept) {
|
|
956
|
+
if (str(row, 'arm') !== arm)
|
|
957
|
+
continue;
|
|
958
|
+
const page = str(row, 'page');
|
|
959
|
+
const round = num(row, 'round');
|
|
960
|
+
const seconds = num(row, 'elapsedMs') / 1000;
|
|
961
|
+
const navs = num(row, 'navs');
|
|
962
|
+
const watts = idle.get(round) ?? idleWatts;
|
|
963
|
+
const cell = cells.get(page) ?? { joules: [], bytes: [], rounds: new Set() };
|
|
964
|
+
cell.joules.push((num(row, 'pkgJ') - watts * seconds) / navs);
|
|
965
|
+
cell.bytes.push(num(row, 'servedTotal') / navs);
|
|
966
|
+
cell.rounds.add(round);
|
|
967
|
+
cells.set(page, cell);
|
|
968
|
+
}
|
|
969
|
+
const dropped = rows.filter((row) => str(row, 'arm') === arm && isContaminated(row)).length;
|
|
970
|
+
return { cells, dropped };
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* The repeat-view figures of a `first-view-warm` reading. A window's joules are its package energy
|
|
974
|
+
* less the idle draw of its round, over its navigations, as in `firstViewFigures`; the cold figure
|
|
975
|
+
* of each page is taken the same way from the cold reading. A page counts when both readings measured
|
|
976
|
+
* it. The term shares divide each page's summed script, layout and style time by its summed task
|
|
977
|
+
* time; the three terms are reported on their own because they may overlap.
|
|
978
|
+
*/
|
|
979
|
+
export function warmFigures(warm, cold) {
|
|
980
|
+
const repeat = armCells(warm.rows, 'warm');
|
|
981
|
+
const first = armCells(cold.rows, 'original');
|
|
982
|
+
const shared = [...repeat.cells.keys()].filter((page) => first.cells.has(page)).sort();
|
|
983
|
+
const warmMedian = (page) => median(repeat.cells.get(page).joules);
|
|
984
|
+
const coldMedian = (page) => median(first.cells.get(page).joules);
|
|
985
|
+
const joules = shared.map(warmMedian);
|
|
986
|
+
const coldJoules = shared.map(coldMedian);
|
|
987
|
+
const ratio = shared.map((page) => warmMedian(page) / coldMedian(page));
|
|
988
|
+
const tasks = new Map();
|
|
989
|
+
for (const row of warm.rows) {
|
|
990
|
+
if (str(row, 'arm') !== 'warm' || isContaminated(row))
|
|
991
|
+
continue;
|
|
992
|
+
const page = str(row, 'page');
|
|
993
|
+
const sums = tasks.get(page) ?? {
|
|
994
|
+
ScriptDuration: 0,
|
|
995
|
+
LayoutDuration: 0,
|
|
996
|
+
RecalcStyleDuration: 0,
|
|
997
|
+
TaskDuration: 0
|
|
998
|
+
};
|
|
999
|
+
for (const nav of row.warmMetrics) {
|
|
1000
|
+
for (const key of Object.keys(sums)) {
|
|
1001
|
+
const step = nav.after[key] - nav.before[key];
|
|
1002
|
+
sums[key] = sums[key] + step;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
tasks.set(page, sums);
|
|
1006
|
+
}
|
|
1007
|
+
const share = (term) => median(shared.map((page) => {
|
|
1008
|
+
const sums = tasks.get(page);
|
|
1009
|
+
return sums[term] / sums.TaskDuration;
|
|
1010
|
+
}));
|
|
1011
|
+
const refetched = shared.filter((page) => {
|
|
1012
|
+
const repeatBytes = median(repeat.cells.get(page).bytes);
|
|
1013
|
+
return repeatBytes > 0.5 * median(first.cells.get(page).bytes);
|
|
1014
|
+
}).length;
|
|
1015
|
+
return {
|
|
1016
|
+
rounds: new Set([...repeat.cells.values()].flatMap((c) => [...c.rounds])).size,
|
|
1017
|
+
pages: shared.length,
|
|
1018
|
+
dropped: repeat.dropped,
|
|
1019
|
+
joules: { mean: mean(joules), median: median(joules) },
|
|
1020
|
+
coldJoules: { mean: mean(coldJoules), median: median(coldJoules) },
|
|
1021
|
+
ratio: { mean: mean(ratio), median: median(ratio) },
|
|
1022
|
+
taskShare: {
|
|
1023
|
+
script: share('ScriptDuration'),
|
|
1024
|
+
layout: share('LayoutDuration'),
|
|
1025
|
+
recalc: share('RecalcStyleDuration')
|
|
1026
|
+
},
|
|
1027
|
+
refetch: { pages: refetched, share: refetched / shared.length }
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
const BOOTSTRAP_SEED = 12345;
|
|
1031
|
+
const BOOTSTRAP_REPLICATES = 2000;
|
|
1032
|
+
/** a 32-bit linear congruential generator, so one seed gives the same draws on every run */
|
|
1033
|
+
function lcg(seed) {
|
|
1034
|
+
let state = seed >>> 0;
|
|
1035
|
+
return () => {
|
|
1036
|
+
state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
|
|
1037
|
+
return state / 4294967296;
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
/** the nearest-rank value of a sample at `p`: index floor(p * n) of the sorted values */
|
|
1041
|
+
function nearestRank(values, p) {
|
|
1042
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
1043
|
+
return sorted[Math.min(sorted.length - 1, Math.floor(p * sorted.length))];
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* A least-squares fit over pages, with each coefficient's interval from a bootstrap over pages:
|
|
1047
|
+
* resamples with replacement from a fixed seed, dropped when collinear. Null when there are no more
|
|
1048
|
+
* pages than coefficients, or when no resample fits.
|
|
1049
|
+
*/
|
|
1050
|
+
function bootstrapFit(X, y, names) {
|
|
1051
|
+
const n = y.length;
|
|
1052
|
+
if (n <= names.length)
|
|
1053
|
+
return null;
|
|
1054
|
+
const fit = leastSquares(X, y);
|
|
1055
|
+
const mean = y.reduce((s, v) => s + v, 0) / n;
|
|
1056
|
+
const tss = y.reduce((s, v) => s + (v - mean) ** 2, 0);
|
|
1057
|
+
const draw = lcg(BOOTSTRAP_SEED);
|
|
1058
|
+
const reps = [];
|
|
1059
|
+
for (let b = 0; b < BOOTSTRAP_REPLICATES; b++) {
|
|
1060
|
+
const idx = Array.from({ length: n }, () => Math.floor(draw() * n));
|
|
1061
|
+
try {
|
|
1062
|
+
const sample = leastSquares(idx.map((i) => X[i]), idx.map((i) => y[i]));
|
|
1063
|
+
reps.push(sample.coef);
|
|
1064
|
+
}
|
|
1065
|
+
catch (error) {
|
|
1066
|
+
if (!(error instanceof RangeError))
|
|
1067
|
+
throw error;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
if (reps.length === 0)
|
|
1071
|
+
return null;
|
|
1072
|
+
return {
|
|
1073
|
+
pages: n,
|
|
1074
|
+
replicates: reps.length,
|
|
1075
|
+
residualSe: fit.residualSe,
|
|
1076
|
+
r2: 1 - fit.rss / tss,
|
|
1077
|
+
coef: Object.fromEntries(names.map((name, k) => {
|
|
1078
|
+
const column = reps.map((r) => r[k]);
|
|
1079
|
+
return [
|
|
1080
|
+
name,
|
|
1081
|
+
{
|
|
1082
|
+
value: fit.coef[k],
|
|
1083
|
+
low: nearestRank(column, 0.025),
|
|
1084
|
+
high: nearestRank(column, 0.975)
|
|
1085
|
+
}
|
|
1086
|
+
];
|
|
1087
|
+
}))
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
/** Pearson correlation of two equal-length lists */
|
|
1091
|
+
function pearson(a, b) {
|
|
1092
|
+
const n = a.length;
|
|
1093
|
+
const ma = a.reduce((s, v) => s + v, 0) / n;
|
|
1094
|
+
const mb = b.reduce((s, v) => s + v, 0) / n;
|
|
1095
|
+
let cov = 0;
|
|
1096
|
+
let va = 0;
|
|
1097
|
+
let vb = 0;
|
|
1098
|
+
a.forEach((x, i) => {
|
|
1099
|
+
const dx = x - ma;
|
|
1100
|
+
const dy = b[i] - mb;
|
|
1101
|
+
cov += dx * dy;
|
|
1102
|
+
va += dx * dx;
|
|
1103
|
+
vb += dy * dy;
|
|
1104
|
+
});
|
|
1105
|
+
return cov / Math.sqrt(va * vb);
|
|
1106
|
+
}
|
|
1107
|
+
/** the pages of a first-view reading with an original arm: the joules `firstViewFigures` uses, and the class bytes in MB */
|
|
1108
|
+
function firstViewPages(measurement) {
|
|
1109
|
+
const pages = measurement.method['corpus pages'];
|
|
1110
|
+
const kept = measurement.rows.filter((r) => !isContaminated(r));
|
|
1111
|
+
const idle = new Map();
|
|
1112
|
+
for (const row of kept) {
|
|
1113
|
+
if (str(row, 'arm') !== 'idle')
|
|
1114
|
+
continue;
|
|
1115
|
+
const seconds = num(row, 'elapsedMs') / 1000;
|
|
1116
|
+
idle.set(num(row, 'round'), num(row, 'pkgJ') / seconds);
|
|
1117
|
+
}
|
|
1118
|
+
const idleWatts = median([...idle.values()]);
|
|
1119
|
+
const joules = new Map();
|
|
1120
|
+
for (const row of kept) {
|
|
1121
|
+
if (str(row, 'arm') !== 'original')
|
|
1122
|
+
continue;
|
|
1123
|
+
const page = str(row, 'page');
|
|
1124
|
+
const seconds = num(row, 'elapsedMs') / 1000;
|
|
1125
|
+
const navs = num(row, 'navs');
|
|
1126
|
+
const watts = idle.get(num(row, 'round')) ?? idleWatts;
|
|
1127
|
+
const value = (num(row, 'pkgJ') - watts * seconds) / navs;
|
|
1128
|
+
joules.set(page, [...(joules.get(page) ?? []), value]);
|
|
1129
|
+
}
|
|
1130
|
+
return pages
|
|
1131
|
+
.filter((p) => joules.has(p.id))
|
|
1132
|
+
.map((p) => {
|
|
1133
|
+
const image = p.classBytes.image ?? 0;
|
|
1134
|
+
const script = p.classBytes.script ?? 0;
|
|
1135
|
+
return {
|
|
1136
|
+
site: p.site,
|
|
1137
|
+
joules: median(joules.get(p.id)),
|
|
1138
|
+
image: image / MB,
|
|
1139
|
+
script: script / MB,
|
|
1140
|
+
other: (p.wireBytes - image - script) / MB,
|
|
1141
|
+
total: p.wireBytes / MB,
|
|
1142
|
+
requests: p.requests
|
|
1143
|
+
};
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* The class, bytes and request fits of a `first-view` reading, each with bootstrap intervals over
|
|
1148
|
+
* pages. `without` lists hosts whose pages are left out, for a sensitivity check. The request fits
|
|
1149
|
+
* need a request count on every page and are null otherwise.
|
|
1150
|
+
*/
|
|
1151
|
+
export function firstViewFit(measurement, without = []) {
|
|
1152
|
+
const pages = firstViewPages(measurement).filter((p) => !without.includes(p.site));
|
|
1153
|
+
const y = pages.map((p) => p.joules);
|
|
1154
|
+
const withRequests = pages.every((p) => p.requests !== undefined);
|
|
1155
|
+
const requests = (p) => p.requests;
|
|
1156
|
+
return {
|
|
1157
|
+
pages: pages.length,
|
|
1158
|
+
joulesMedian: median(y),
|
|
1159
|
+
corrTotalMb: pearson(y, pages.map((p) => p.total)),
|
|
1160
|
+
classFit: bootstrapFit(pages.map((p) => [1, p.image, p.script, p.other]), y, ['intercept', 'image', 'script', 'other']),
|
|
1161
|
+
bytesFit: bootstrapFit(pages.map((p) => [1, p.total]), y, ['intercept', 'total']),
|
|
1162
|
+
requestFit: withRequests
|
|
1163
|
+
? bootstrapFit(pages.map((p) => [1, p.total, requests(p)]), y, ['intercept', 'total', 'requests'])
|
|
1164
|
+
: null,
|
|
1165
|
+
classRequestFit: withRequests
|
|
1166
|
+
? bootstrapFit(pages.map((p) => [1, p.image, p.script, p.other, requests(p)]), y, ['intercept', 'image', 'script', 'other', 'requests'])
|
|
1167
|
+
: null
|
|
1168
|
+
};
|
|
1169
|
+
}
|