|
|
|
@@ -7,6 +7,9 @@
|
|
|
|
|
// Startup reports the first rasterised frame (ms since navigation) and the
|
|
|
|
|
// main.dart.js / canvaskit fetch times.
|
|
|
|
|
//
|
|
|
|
|
// --memory (Linux) adds `rssMB`: the resident memory of every process of the
|
|
|
|
|
// private Chrome (renderer, GPU, workers) once the measured steps settle.
|
|
|
|
|
//
|
|
|
|
|
// --cpuprofile records a V8 CPU profile of the measured steps (first rep),
|
|
|
|
|
// writes `<scenario>.cpuprofile` and prints the functions with the most
|
|
|
|
|
// inclusive and self time; use a `flutter build web --profile` build so the
|
|
|
|
@@ -22,7 +25,7 @@
|
|
|
|
|
// CanvasKit rasterises on the CPU, so compare builds with each other rather
|
|
|
|
|
// than predicting a device. --gpu keeps the GPU (WebGL), which is what a
|
|
|
|
|
// desktop user has: use it to judge raster time.
|
|
|
|
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
|
|
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
|
|
|
import { join } from 'node:path';
|
|
|
|
|
import { parseArgs } from 'node:util';
|
|
|
|
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
|
|
@@ -33,7 +36,7 @@ import { attribute, loadSourceMap } from './cpu_attribution.mjs';
|
|
|
|
|
const { values: opts } = parseArgs({
|
|
|
|
|
options: {
|
|
|
|
|
build: { type: 'string' }, out: { type: 'string' }, repeat: { type: 'string', default: '5' },
|
|
|
|
|
only: { type: 'string' }, cpuprofile: { type: 'boolean' }, frames: { type: 'boolean' }, shots: { type: 'boolean' }, gpu: { type: 'boolean' }, size: { type: 'string', default: '560x900' },
|
|
|
|
|
only: { type: 'string' }, cpuprofile: { type: 'boolean' }, frames: { type: 'boolean' }, shots: { type: 'boolean' }, gpu: { type: 'boolean' }, memory: { type: 'boolean' }, size: { type: 'string', default: '560x900' },
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
if (!opts.build || !opts.out) throw new Error('usage: --build <dir> --out <dir>');
|
|
|
|
@@ -106,6 +109,16 @@ const lookup = opts.cpuprofile ? await loadSourceMap(opts.build) : null;
|
|
|
|
|
const server = await serveBuild(opts.build);
|
|
|
|
|
const browser = await openBrowser({ gpu: Boolean(opts.gpu) });
|
|
|
|
|
const { send, on } = browser;
|
|
|
|
|
// Sums VmRSS over the browser's processes (SystemInfo ids are OS pids).
|
|
|
|
|
async function chromeRssMB() {
|
|
|
|
|
const { processInfo } = await browser.sendBrowser('SystemInfo.getProcessInfo');
|
|
|
|
|
let kb = 0;
|
|
|
|
|
for (const { id } of processInfo) {
|
|
|
|
|
const status = await readFile(`/proc/${id}/status`, 'utf8').catch(() => '');
|
|
|
|
|
kb += Number(status.match(/^VmRSS:\s+(\d+)/m)?.[1] ?? 0);
|
|
|
|
|
}
|
|
|
|
|
return kb / 1024;
|
|
|
|
|
}
|
|
|
|
|
const evaluate = async (expression) => (await send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true })).result?.value;
|
|
|
|
|
let frames = [];
|
|
|
|
|
let firstFrame = null;
|
|
|
|
@@ -191,8 +204,14 @@ try {
|
|
|
|
|
await delay(2000);
|
|
|
|
|
const startup = s.name.startsWith('startup');
|
|
|
|
|
const loads = startup ? await evaluate(`Object.fromEntries(performance.getEntriesByType('resource')
|
|
|
|
|
.filter((e) => /main\\.dart\\.js|canvaskit\\.wasm/.test(e.name))
|
|
|
|
|
.filter((e) => /main\\.dart\\.(js|wasm)$|canvaskit\\.wasm|skwasm(_heavy)?\\.wasm/.test(e.name))
|
|
|
|
|
.map((e) => [e.name.split('/').pop(), Math.round(e.responseEnd)]))`) : null;
|
|
|
|
|
if (startup && rep === 0) {
|
|
|
|
|
// Which build the loader picked: WebAssembly (skwasm, threaded only
|
|
|
|
|
// when cross-origin isolated) or JavaScript (CanvasKit).
|
|
|
|
|
console.log(` renderer: ${await evaluate(`(window._flutter_skwasmInstance ? 'skwasm' : window.flutterCanvasKit ? 'canvaskit' : '?')
|
|
|
|
|
+ (window.crossOriginIsolated ? ' isolated' : '')`)}`);
|
|
|
|
|
}
|
|
|
|
|
await run(s.setup);
|
|
|
|
|
await settle();
|
|
|
|
|
const startFrames = startup ? 0 : frames.length;
|
|
|
|
@@ -218,7 +237,8 @@ try {
|
|
|
|
|
const sum = (i) => f.reduce((a, x) => a + x[i], 0) / 1000;
|
|
|
|
|
const max = (i) => f.reduce((a, x) => Math.max(a, x[i]), 0) / 1000;
|
|
|
|
|
reps.push({ frames: f.length, buildSum: sum(0), buildMax: max(0), rasterSum: sum(1), rasterMax: max(1),
|
|
|
|
|
longest: max(2), over16: f.filter((x) => x[2] > 16667).length, firstFrame, ...loads });
|
|
|
|
|
longest: max(2), over16: f.filter((x) => x[2] > 16667).length, firstFrame, ...loads,
|
|
|
|
|
...(opts.memory ? { rssMB: await chromeRssMB() } : {}) });
|
|
|
|
|
}
|
|
|
|
|
const keys = Object.keys(reps[0]).filter((k) => typeof reps[0][k] === 'number');
|
|
|
|
|
results[s.name] = Object.fromEntries(keys.map((k) => [k, r1(median(reps.map((r) => r[k])))]));
|
|
|
|
|