roamwright 0.61.23 → 0.61.25
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 +2 -1
- package/examples/title-backdrop.html +52 -0
- package/examples/title-backdrop.js +160 -0
- package/index.js +25 -0
- package/package.json +1 -1
- package/rendering/scene-flash.js +105 -0
- package/rendering/title-backdrop-sprites.js +342 -0
- package/rendering/title-backdrop.js +212 -0
- package/runtime/article-page.js +128 -0
- package/runtime/articles.js +177 -0
- package/runtime/hud-room.js +103 -0
- package/runtime/journey.js +60 -0
- package/runtime/site-pages.js +343 -0
- package/tools/README.md +2 -1
- package/tools/build-checks.cjs +188 -0
- package/tools/build-checks.test.cjs +36 -0
- package/tools/ios-sim.sh +5 -1
- package/tools/page-driver.cjs +4 -1
- package/tools/scene-bench.cjs +38 -1
package/tools/README.md
CHANGED
|
@@ -30,6 +30,7 @@ const { renewShaders, renewalFlags, saltFor } = require('roamwright/tools/shader
|
|
|
30
30
|
| `shader-arrival.cjs` | Fresh and repeat visit shader-arrival and late-compile audits (`observeShaderArrival`, `verifyShaderArrival`, `runShaderArrival`, `runLateCompiles`). |
|
|
31
31
|
| `load-audit.cjs` | Step-by-step load timing (`runReady`), stalled-load diagnostics (`runLoadDiag`), invalid WebGL program watch (`runGlWatch`), first-visit terrain-shaping timing (`runShapeTiming`), and cold throttled scene-set fetch timing (`runColdSetFetch`). |
|
|
32
32
|
| `world-tour.cjs` | Multi-land, interior-vision, and scene smoke tour runner (`runWorldTour`) that visits configured stops in one session and tags page/console errors by stage. |
|
|
33
|
+
| `build-checks.cjs` | Small checks against a built page: two builds' fixed views turn by turn (`runBuildAb`), a page loaded twice in one profile (`runLoadTwice`), the opening view's bench at a held hour (`runOpeningBench`), and whether the title screen enters the world untouched (`runTitleIdle`). |
|
|
33
34
|
| `quiet-bench.cjs` | Quiet-machine full benchmark runner (`runQuietBench`): measures first and repeat load times, post-GC heap/backing memory, GPU renderer, fixed-view `perfTest()`, and opening-view `stageTimes()`. |
|
|
34
35
|
| `geometry-hash.cjs` | In-browser geometry and terrain-bake hashing runners: worker-baked height lattice readback (`runGroundHash`), crowd batch & standard hashing (`runCrowdHash`), skinned figure hashing (`runFigureHash`), and full cast & mount hashing (`runBeastHash`). |
|
|
35
36
|
| `tree-inspect.cjs` | Instanced tree inspection and wood benchmark runners: four-distance open-side stills of the nearest tree of a kind (`runTreeLook`) and GPU `bench()` across the densest 100 m square (`runTreeBench`). |
|
|
@@ -40,7 +41,7 @@ const { renewShaders, renewalFlags, saltFor } = require('roamwright/tools/shader
|
|
|
40
41
|
| `look-stats.cjs` | Photo statistics of a frame's RGBA pixels (clipped and crushed shares, saturation, contrast), warnings against thresholds, and drift against a kept baseline. Runs in Node and, handed over as text, inside a page. |
|
|
41
42
|
| `scene-run.cjs` | Shared scene playback helpers (`seekSceneInPage`, `startSceneInPage`, `readyPageForSceneInPage`, `releaseLoopInPage`, `parseSceneSpec`), single-scene still capture (`captureSceneStills`), shadow half-width sampling (`measureSceneShadow`), and full-duration contact-strip watching (`watchScenes`). |
|
|
42
43
|
| `scene-batch.cjs` | Multi-scene visual and diagnostic batch runner (`runSceneBatch`, `parseSceneBatchArgs`): plays requested scenes at explicit or percentage beats, saves stills and optional labelled contact sheets, and logs FPS, script time, active cast count, and problems. |
|
|
43
|
-
| `scene-bench.cjs` | Native 3840 × 2160 GPU-fenced scene benchmark and per-part cost breakdown runner (`runSceneBench`, `parseSceneBenchArgs`): unifies held-beat frame timing (`includeCosts: false`) and per-part hiding gains via `partTimes()` (`includeCosts: true`).
|
|
44
|
+
| `scene-bench.cjs` | Native 3840 × 2160 GPU-fenced scene benchmark and per-part cost breakdown runner (`runSceneBench`, `parseSceneBenchArgs`): unifies held-beat frame timing (`includeCosts: false`) and per-part hiding gains via `partTimes()` (`includeCosts: true`); `runSceneCpu` plays a scene to a moment and lists its costliest script functions per frame from a CPU profile. |
|
|
44
45
|
| `scene-audit-beat.cjs` | Scene visibility audit pure helpers (`parseAuditArgs`, `beatTimes`, `stillName`, `flagsOfBeat`, `flagsOfScene`) and page-side cast projection, frustum submission, triangle delta, and readPixels delta probes (`beginBeatInPage`, `endBeatInPage`). |
|
|
45
46
|
| `scene-audit-sheet.cjs` | Audit contact sheet renderer (`drawAuditSheetInPage`, `writeAuditSheets`), console row/summary formatters (`formatAuditRow`, `printAuditSummary`), and atomic `audit.json` writer (`saveAuditReport`). |
|
|
46
47
|
| `scene-audit.cjs` | Full-catalog scene visibility audit runner (`runSceneAudit`): plays scenes across lands with automatic crash/hang recovery (`within`, `Stopped`, `TimedOut`) and writes per-land contact sheets and `audit.json`. |
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Small page checks a world runs against its built page through a page driver (page-driver.cjs):
|
|
2
|
+
// two builds' fixed views turn by turn, a page loaded twice in one profile, the opening view's bench at a held hour,
|
|
3
|
+
// and whether the title screen enters the world untouched.
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Keeps the least milliseconds seen for each named view (and the last quality seen) in `best`, from one round's rows.
|
|
8
|
+
*
|
|
9
|
+
* @param {Record<string, number|string>} best The running best of one build, changed in place.
|
|
10
|
+
* @param {Array<[string, number, string]>} rows `[view name, ms, quality]` for each view of one round.
|
|
11
|
+
* @returns {Record<string, number|string>} `best`.
|
|
12
|
+
*/
|
|
13
|
+
function keepLeast(best, rows) {
|
|
14
|
+
for (const [name, ms, quality] of rows) {
|
|
15
|
+
best[name] = Math.min(best[name] ?? Infinity, ms);
|
|
16
|
+
best.q = quality;
|
|
17
|
+
}
|
|
18
|
+
return best;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Lines comparing two builds' least view times: the name, this build's, the base's and their difference.
|
|
23
|
+
*
|
|
24
|
+
* @param {[Record<string, number|string>, Record<string, number|string>]} best This build's best, then the base's.
|
|
25
|
+
* @returns {string[]} One line per view, then a line naming both builds' quality.
|
|
26
|
+
*/
|
|
27
|
+
function formatBuildAb([mine, base]) {
|
|
28
|
+
const lines = [];
|
|
29
|
+
for (const name of Object.keys(mine))
|
|
30
|
+
if (name !== 'q')
|
|
31
|
+
lines.push([name.padEnd(30), 'this', mine[name], 'base', base[name], 'diff', (mine[name] - base[name]).toFixed(2)].join(' '));
|
|
32
|
+
lines.push(['quality', mine.q, base.q].join(' '));
|
|
33
|
+
return lines;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The line `runLoadTwice` prints for one visit: the address's path, which visit, the steps' sum and each step.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} url The address opened.
|
|
40
|
+
* @param {number} visit 0 for the first visit, 1 for the second.
|
|
41
|
+
* @param {Array<[string, number]>} steps `[step, ms]` for each start-up step.
|
|
42
|
+
* @param {string[]} errors Page and console errors seen.
|
|
43
|
+
* @returns {string}
|
|
44
|
+
*/
|
|
45
|
+
function formatLoadTwice(url, visit, steps, errors) {
|
|
46
|
+
return [
|
|
47
|
+
url.split('/').slice(3).join('/') || '/',
|
|
48
|
+
visit ? 'again' : 'first',
|
|
49
|
+
steps.reduce((a, b) => a + b[1], 0),
|
|
50
|
+
'ms',
|
|
51
|
+
JSON.stringify(steps.map(x => x[1])),
|
|
52
|
+
errors.length ? 'ERRORS ' + errors.join(' | ') : '',
|
|
53
|
+
].join(' ');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Two builds turn by turn at 3456 x 2234 (1728 x 1117 at 2x), High: each round runs the page's `perfTest()` on both and
|
|
58
|
+
* prints its rows; at the end it prints the least ms of each view per build and their difference.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} driver A page driver (page-driver.cjs).
|
|
61
|
+
* @param {object} options
|
|
62
|
+
* @param {string[]} options.bases This build's address, then the other's.
|
|
63
|
+
* @param {number} [options.rounds=3] Rounds, each on both builds.
|
|
64
|
+
*/
|
|
65
|
+
async function runBuildAb(driver, { bases, rounds = 3 }) {
|
|
66
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
67
|
+
const best = [{}, {}];
|
|
68
|
+
for (let r = 0; r < rounds; r++)
|
|
69
|
+
for (let b = 0; b < 2; b++) {
|
|
70
|
+
const ctx = await browser.newContext({ viewport: { width: 1728, height: 1117 }, deviceScaleFactor: 2 });
|
|
71
|
+
await driver.applyStorage(ctx, { quality: 'high', 'quality-fit': 'high', muted: '1' });
|
|
72
|
+
const page = await ctx.newPage();
|
|
73
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 200)));
|
|
74
|
+
await driver.enter(page, bases[b] + '?v=' + Date.now(), { waitUntil: 'load', titledMs: 180000 });
|
|
75
|
+
await page.waitForTimeout(2000);
|
|
76
|
+
const rows = await page.evaluate(
|
|
77
|
+
async d => (await window[d].perfTest()).map(x => [x.name || x.view, x.ms, window[d].state.quality]),
|
|
78
|
+
driver.debug,
|
|
79
|
+
);
|
|
80
|
+
keepLeast(best[b], rows);
|
|
81
|
+
console.log('round', r, b ? 'base' : 'this', rows.map(x => x[0] + ' ' + x[1]).join(' | '));
|
|
82
|
+
await ctx.close();
|
|
83
|
+
}
|
|
84
|
+
for (const line of formatBuildAb(best)) console.log(line);
|
|
85
|
+
await driver.closeBrowser(browser, 8000);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Loads each address twice in one browser profile, so what the first visit kept is there for the second, and prints the
|
|
90
|
+
* page's `loadTimes` steps for each visit with any errors.
|
|
91
|
+
*
|
|
92
|
+
* @param {object} driver A page driver (page-driver.cjs).
|
|
93
|
+
* @param {string[]} urls The addresses to open.
|
|
94
|
+
*/
|
|
95
|
+
async function runLoadTwice(driver, urls) {
|
|
96
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
97
|
+
const ctx = await browser.newContext({ viewport: { width: 1280, height: 720 } });
|
|
98
|
+
for (const url of urls)
|
|
99
|
+
for (let i = 0; i < 2; i++) {
|
|
100
|
+
const page = await ctx.newPage();
|
|
101
|
+
const errors = [];
|
|
102
|
+
page.on('pageerror', e => errors.push(e.message.slice(0, 160)));
|
|
103
|
+
page.on('console', m => m.type() === 'error' && errors.push(m.text().slice(0, 160)));
|
|
104
|
+
await page.goto(url);
|
|
105
|
+
await page.waitForFunction(
|
|
106
|
+
([titleId, cls]) => !document.getElementById(titleId)?.hidden || document.body.classList.contains(cls),
|
|
107
|
+
[driver.titleId, driver.crossingClass],
|
|
108
|
+
{ timeout: 180000 },
|
|
109
|
+
);
|
|
110
|
+
await page.waitForTimeout(1500); // let what was baked be kept
|
|
111
|
+
const steps = await page.evaluate(d => window[d].loadTimes.map(x => [x[0], x[1]]), driver.debug);
|
|
112
|
+
console.log(formatLoadTwice(url, i, steps, errors));
|
|
113
|
+
await page.close();
|
|
114
|
+
}
|
|
115
|
+
await driver.closeBrowser(browser, 8000);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The opening view at 3456 x 2234 on the graphics card, the hour held: after a warm-up, four `bench()` runs, one more with
|
|
120
|
+
* its parts, and `stageTimes()`, printed as one JSON line.
|
|
121
|
+
*
|
|
122
|
+
* @param {object} driver A page driver (page-driver.cjs).
|
|
123
|
+
* @param {object} [options]
|
|
124
|
+
* @param {string} [options.quality='high'] The quality preset.
|
|
125
|
+
* @param {number} [options.hour=0.715] The time of day held, as a fraction of the day.
|
|
126
|
+
*/
|
|
127
|
+
async function runOpeningBench(driver, { quality = 'high', hour = 0.715 } = {}) {
|
|
128
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
129
|
+
const ctx = await browser.newContext({ viewport: { width: 1728, height: 1117 }, deviceScaleFactor: 2 });
|
|
130
|
+
await driver.applyStorage(ctx, { quality });
|
|
131
|
+
const page = await ctx.newPage();
|
|
132
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
133
|
+
page.on('console', m => m.type() === 'error' && console.log('CONSOLE', m.text().slice(0, 300)));
|
|
134
|
+
await driver.enter(page, driver.BASE + '?v=' + Date.now());
|
|
135
|
+
await page.waitForTimeout(4000);
|
|
136
|
+
const result = await page.evaluate(
|
|
137
|
+
async ([d, h]) => {
|
|
138
|
+
const app = window[d];
|
|
139
|
+
app.holdQuality(true);
|
|
140
|
+
app.env.flow = false;
|
|
141
|
+
app.env.time = h;
|
|
142
|
+
app.state.mode = 'inspect';
|
|
143
|
+
const wait = ms => new Promise(r => setTimeout(r, ms));
|
|
144
|
+
for (let i = 0; i < 25; i++) {
|
|
145
|
+
await app.bench(3);
|
|
146
|
+
await wait(80);
|
|
147
|
+
}
|
|
148
|
+
const runs = [];
|
|
149
|
+
for (let i = 0; i < 4; i++) runs.push((await app.bench()).ms);
|
|
150
|
+
return { quality: app.state.quality, runs, bench: await app.bench(), stages: await app.stageTimes() };
|
|
151
|
+
},
|
|
152
|
+
[driver.debug, hour],
|
|
153
|
+
);
|
|
154
|
+
console.log(JSON.stringify(result));
|
|
155
|
+
await driver.closeBrowser(browser, 8000);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Opens the page and touches nothing: does the title screen enter the world by itself? Prints the start button's text and
|
|
160
|
+
* the page's mode four times over about seven seconds.
|
|
161
|
+
*
|
|
162
|
+
* @param {object} driver A page driver (page-driver.cjs).
|
|
163
|
+
*/
|
|
164
|
+
async function runTitleIdle(driver) {
|
|
165
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
166
|
+
const page = await (await browser.newContext({ viewport: { width: 1200, height: 700 } })).newPage();
|
|
167
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
168
|
+
await page.goto(driver.BASE + '?v=' + Date.now(), { waitUntil: 'domcontentloaded' });
|
|
169
|
+
await page.waitForFunction(
|
|
170
|
+
([titleId, cls]) => !document.getElementById(titleId)?.hidden || document.body.classList.contains(cls),
|
|
171
|
+
[driver.titleId, driver.crossingClass],
|
|
172
|
+
{ timeout: 120000 },
|
|
173
|
+
);
|
|
174
|
+
for (const wait of [200, 2000, 2000, 2500]) {
|
|
175
|
+
await page.waitForTimeout(wait);
|
|
176
|
+
console.log(
|
|
177
|
+
JSON.stringify(
|
|
178
|
+
await page.evaluate(
|
|
179
|
+
([d, startId]) => [document.getElementById(startId).textContent, window[d].state.mode],
|
|
180
|
+
[driver.debug, driver.startId],
|
|
181
|
+
),
|
|
182
|
+
),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
await driver.closeBrowser(browser, 8000);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
module.exports = { keepLeast, formatBuildAb, formatLoadTwice, runBuildAb, runLoadTwice, runOpeningBench, runTitleIdle };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const test = require('node:test');
|
|
4
|
+
const { keepLeast, formatBuildAb, formatLoadTwice } = require('./build-checks.cjs');
|
|
5
|
+
|
|
6
|
+
test('keepLeast keeps each view’s least time over rounds and the last quality', () => {
|
|
7
|
+
const best = {};
|
|
8
|
+
keepLeast(best, [
|
|
9
|
+
['Lake', 12.5, 'high'],
|
|
10
|
+
['Road', 9, 'high'],
|
|
11
|
+
]);
|
|
12
|
+
keepLeast(best, [
|
|
13
|
+
['Lake', 11, 'medium'],
|
|
14
|
+
['Road', 10, 'medium'],
|
|
15
|
+
]);
|
|
16
|
+
assert.deepEqual(best, { Lake: 11, Road: 9, q: 'medium' });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('formatBuildAb lines each view with both builds and their difference, then the qualities', () => {
|
|
20
|
+
const lines = formatBuildAb([
|
|
21
|
+
{ Lake: 11, q: 'high' },
|
|
22
|
+
{ Lake: 12.25, q: 'high' },
|
|
23
|
+
]);
|
|
24
|
+
assert.equal(lines.length, 2);
|
|
25
|
+
assert.match(lines[0], /^Lake +this 11 base 12.25 diff -1.25$/);
|
|
26
|
+
assert.equal(lines[1], 'quality high high');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('formatLoadTwice names the path, the visit, the steps’ sum and any errors', () => {
|
|
30
|
+
const steps = [
|
|
31
|
+
['Reading the page', 300],
|
|
32
|
+
['Ground', 200],
|
|
33
|
+
];
|
|
34
|
+
assert.equal(formatLoadTwice('http://localhost:8765/', 0, steps, []), '/ first 500 ms [300,200] ');
|
|
35
|
+
assert.equal(formatLoadTwice('http://localhost:8765/location/x', 1, steps, ['boom']), 'location/x again 500 ms [300,200] ERRORS boom');
|
|
36
|
+
});
|
package/tools/ios-sim.sh
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
# SIM_DEVICE simulator device name (default: "iPhone 14 Pro Max")
|
|
16
16
|
# SIM_CHROME_BUNDLE Chromium iOS bundle id (default: org.chromium.ost.chrome.ios.dev)
|
|
17
17
|
# SIM_PORT localhost port for the simulator server (default: 8764)
|
|
18
|
+
# SIM_ARRIVE seconds to wait for the browser to ask for the page (default: 30)
|
|
18
19
|
# SIM_STORAGE_LOG_KEY localStorage key holding the diagnostic log JSON (default: roamwright:log)
|
|
19
20
|
# SIM_DEFAULT_ADDRESS default route address when $1 is omitted
|
|
20
21
|
# SIM_SERVE_SCRIPT relative path to server script supporting SERVE_ENTRY (default: scripts/serve.py)
|
|
@@ -84,12 +85,15 @@ xcrun simctl terminate "$udid" "$CHROME" 2>/dev/null || true
|
|
|
84
85
|
began=$(date -u +%Y-%m-%dT%H:%M:%S)
|
|
85
86
|
xcrun simctl launch "$udid" "$CHROME" >/dev/null
|
|
86
87
|
arrived=
|
|
87
|
-
|
|
88
|
+
# A busy Mac (a gate's sweeps running beside it) can take well over 12 s to restore the browser's tab: wait SIM_ARRIVE seconds.
|
|
89
|
+
waited_for=0
|
|
90
|
+
while [ "$waited_for" -lt "${SIM_ARRIVE:-30}" ]; do
|
|
88
91
|
grep -q "GET /?$entry " "$asked" && {
|
|
89
92
|
arrived=1
|
|
90
93
|
break
|
|
91
94
|
}
|
|
92
95
|
sleep 1
|
|
96
|
+
waited_for=$((waited_for + 1))
|
|
93
97
|
done
|
|
94
98
|
[ -n "$arrived" ] || {
|
|
95
99
|
xcrun simctl openurl "$udid" "chromium://localhost:$port/" >/dev/null 2>&1 || true
|
package/tools/page-driver.cjs
CHANGED
|
@@ -40,7 +40,7 @@ function npxCached(name) {
|
|
|
40
40
|
* @param {string} [options.crossingClass='crossing'] Body class present when a direct address enters without the title screen.
|
|
41
41
|
* @param {string} [options.canvasSelector='#c'] CSS selector of the WebGL canvas element.
|
|
42
42
|
* @returns {{ chromium: object, shell: string, BASE: string, OUT: string, GPU: object, env: string, debug: string,
|
|
43
|
-
* storagePrefix: string, canvasSelector: string, printLog: Function, installCuts: Function, longRun: Function,
|
|
43
|
+
* storagePrefix: string, canvasSelector: string, titleId: string, startId: string, crossingClass: string, printLog: Function, installCuts: Function, longRun: Function,
|
|
44
44
|
* enter: Function, routeUrl: Function, clearView: Function, closeBrowser: Function, applyStorage: Function }}
|
|
45
45
|
*/
|
|
46
46
|
function createPageDriver({
|
|
@@ -265,6 +265,9 @@ function createPageDriver({
|
|
|
265
265
|
debug,
|
|
266
266
|
storagePrefix,
|
|
267
267
|
canvasSelector,
|
|
268
|
+
titleId,
|
|
269
|
+
startId,
|
|
270
|
+
crossingClass,
|
|
268
271
|
printLog,
|
|
269
272
|
installCuts,
|
|
270
273
|
longRun,
|
package/tools/scene-bench.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// (`includeCosts: true`, via `window[debug].stageTimes()` and `window[debug].partTimes()`).
|
|
4
4
|
'use strict';
|
|
5
5
|
const { routeForScene, seekSceneInPage, startSceneInPage } = require('./scene-run.cjs');
|
|
6
|
+
const { startCpuProfile, stopCpuProfile, summarizeCpuProfile } = require('./cpu-profile.cjs');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Parses CLI arguments for `runSceneBench` in either multi-scene `<id>:<t1,t2>` mode or legacy
|
|
@@ -146,4 +147,40 @@ async function runSceneBench(
|
|
|
146
147
|
await driver.closeBrowser(browser, 8000);
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Plays a scene to a moment, benches it and says where the script's time goes, function by function (a development build
|
|
152
|
+
* names them): the least-CPU of four 20-frame benches, then a 120-frame CPU profile's 22 costliest functions per frame.
|
|
153
|
+
*
|
|
154
|
+
* @param {object} driver A page driver (page-driver.cjs).
|
|
155
|
+
* @param {object} options
|
|
156
|
+
* @param {string} options.id The scene's id in `window[debug].CONFIG.events`.
|
|
157
|
+
* @param {number} [options.at=20] Seconds into the scene to measure at.
|
|
158
|
+
* @param {string} [options.quality='high'] The quality preset.
|
|
159
|
+
*/
|
|
160
|
+
async function runSceneCpu(driver, { id, at = 20, quality = 'high' }) {
|
|
161
|
+
const browser = await driver.chromium.launch({ executablePath: driver.shell, ...driver.GPU });
|
|
162
|
+
const ctx = await browser.newContext({ viewport: { width: 1728, height: 1117 }, deviceScaleFactor: 2 });
|
|
163
|
+
await driver.applyStorage(ctx, { quality });
|
|
164
|
+
const page = await ctx.newPage();
|
|
165
|
+
page.on('pageerror', e => console.log('PAGE ERROR', e.message.slice(0, 300)));
|
|
166
|
+
await driver.enter(page, driver.routeUrl(''));
|
|
167
|
+
await page.waitForTimeout(3000);
|
|
168
|
+
await page.evaluate(d => window[d].holdQuality(true), driver.debug);
|
|
169
|
+
await page.evaluate(startSceneInPage, { debug: driver.debug, id });
|
|
170
|
+
await page.waitForFunction(([d, s]) => window[d].director.ev && window[d].director.t >= s, [driver.debug, +at], { timeout: 180000 });
|
|
171
|
+
for (let i = 0; i < 3; i++) await page.evaluate(d => window[d].bench(10), driver.debug);
|
|
172
|
+
const runs = [];
|
|
173
|
+
for (let i = 0; i < 4; i++) runs.push(await page.evaluate(d => window[d].bench(20), driver.debug));
|
|
174
|
+
const best = runs.reduce((a, b) => (b.cpu < a.cpu ? b : a));
|
|
175
|
+
console.log('bench', JSON.stringify(best), 'quality', await page.evaluate(d => window[d].state.quality, driver.debug));
|
|
176
|
+
const cdp = await ctx.newCDPSession(page);
|
|
177
|
+
await startCpuProfile(cdp, 100);
|
|
178
|
+
for (let i = 0; i < 6; i++) await page.evaluate(d => window[d].bench(20), driver.debug);
|
|
179
|
+
const profile = await stopCpuProfile(cdp);
|
|
180
|
+
const summary = summarizeCpuProfile(profile, { excludeIdle: true, style: 'zero' });
|
|
181
|
+
console.log('profiled ms', summary.totalMs.toFixed(0), '(120 frames)');
|
|
182
|
+
for (const [k, v] of summary.self.slice(0, 22)) console.log((v / 120).toFixed(3).padStart(7), 'ms/frame', k);
|
|
183
|
+
await driver.closeBrowser(browser, 8000);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
module.exports = { parseSceneBenchArgs, runSceneBench, runSceneCpu };
|