dmnet.st Commando

How it works · write-up

Profiling the 3D view on a Meta Quest

docs/DEVICE_PROFILING.md · 14 KB · updated 2026-11-03

Working notes, rendered as they are: they were written while building the game, so expect ROM addresses, register names and references to source files that are not published.

The 3D styles have to hold the headset's refresh rate in VR (90 Hz on the Quest 3). This kit measures a real game on the headset without anyone wearing it, and can be rerun after any rendering change (BACKLOG_3D 3D-35).

What it measures

node tools/quest_profile.mjs run drives playlab.html on the headset:

  1. Loads the page with ?measure=1&invincible=1 and switches the chosen 3D style on.
  2. Switches the autopilot on and waits until it reaches a busy goal. The default is Destroy timed firing position in Area 1, with trenches, about ten soldiers and grenades in view.
  3. Switches the autopilot off, because its planning costs up to 240 ms per frame on the Quest. It also switches off the desktop-only shadows and occlusion, as game.html does on the headset. Then it waits for 60 game updates per second.
  4. Records the browser window's WebGL calls.
  5. Enters VR and moves the scene to a standing player's view (see below).
  6. Collects: - the headset's own frame timing from the VrApi log: frames per second, app GPU time, CPU-and-GPU latency, GPU and CPU load; - draw calls per frame, by model, split into visible and cut away by the tabletop's clip planes; - WebGL calls per second, and which draw sizes carry the triangles; - the objects beyond the tabletop edges, with the draws each one would cost; - two headset screenshots, as drawn and with the clip planes off; - a DevTools CPU profile of 6 s (vr.cpuprofile, which opens in Chrome DevTools' Performance panel). The summary gives self and inclusive time per function and self time per script file, with the frame count over the same game seconds for milliseconds per frame. (program) is native browser work outside JavaScript: WebGL command encoding, uniform uploads and WebXR submission.
  7. Runs the comparisons named by --compare (default merge,colours,mirrored,batches; also page): - merge: static scenery merged by material (src/render3d/static-merge.ts), against the placed models. - colours: merged by surface with vertex colours, against merged by material. - mirrored: mirrored actor copies batched, against drawn part by part. - hud: the VR HUD drawn from the character atlas (src/render3d/hud-tiles.ts), against the overlay canvas uploaded as a texture. - batches: the instanced drawing of repeated actor parts (src/render3d/part-batches.ts), against every part on its own. - baked: soldiers drawn as instances from baked poses, against part by part. - detail: the toy ground's fragment detail, against plain painted ground (GPU cost). - shadowmap: a 1024 texel VR shadow map against 2048 (after shadows). - shadows: the sun's shadow map in VR (playlab.html's "Sun shadows in VR"), against none. It is left on afterwards, so put it last in --compare.

Each comparison runs four cycles of 6 s on and 6 s off on the same stretch of play, assigns each VrApi second to a mode by the headset's clock, and leaves out the second around each switch. It also leaves out seconds with under 10 ms of CPU-and-GPU work, which carry no game frames. It counts the draws per frame in both modes and leaves the optimisation on afterwards. Results go under comparisons in the summary. The headset and the PC must use the same time zone, because logcat prints local time. page hides every playlab.html panel except the 3D canvas, to separate the lab page's cost from the game's, and takes a second CPU profile with the panels hidden. 8. Leaves VR and turns the headset's wear sensor back on.

Everything goes to captures/device/<time>-<style>/summary.json, plus the screenshots. The captures folder is not tracked.

The standing view

A headset lying on a table sees the diorama edge-on from table height. In that view the diorama covers little of the screen, so the GPU load is understated. The probe moves the whole scene by M = P·D⁻¹, where P is the real head pose and D is the wanted one: eyes 1.65 m above the floor, over the origin, looking at DIORAMA_CENTER. The headset then renders exactly what a standing player sees. Check vr.jpg: the whole battlefield should be in view from above.

Setup

  • Headset: 1. Turn on developer mode. 2. Turn on wireless debugging. The tool finds the headset over mDNS (adb mdns services), or pass --device ip:port. 3. Open the Quest browser once. 4. Place the headset where its cameras can track: a lit room, facing open space. While tracking is lost the Quest shows "Finding position in room" and draws neither the browser panel nor VR content.
  • PC:
  • Install adb (set ADB to its path if it isn't on PATH).
  • Use the HTTPS certificate the headset already trusts (captures/audio/https/, made by tools/create_dev_certificate.py).
  • Complete the clean-checkout prerequisites, including the indexed effect pack from npm run audio:samples, then run a current build: npm run build.

Run the server and the profile in two terminals:

python tools/device_measure_server.py --port 8444
node tools/quest_profile.mjs run --host <LAN address> --style toy
  • --host is this PC's LAN address in the certificate.
  • --style is toy, bricks or lowpoly.
  • --goal sets another autopilot goal to wait for.
  • --sample sets the seconds of VrApi timing to keep.
  • --vr multiview loads the page with ?vr=multiview, so VR sessions draw through the WebGPURenderer multiview prototype (BACKLOG_3D 3D-36). The log and the summary report whether the session got multiview. The output folder name ends in -multiview.
  • --compare "" skips the A/B comparisons.
  • --trace records a Chrome trace of 4 s in VR after the CPU profile, from the browser-level DevTools target, so it covers every browser process: the page's renderer, the GPU process and the browser's VR thread. It saves vr-trace.json (opens in chrome://tracing or Perfetto), and the summary gives each thread's busy time per second and its self time per event name. The renderer's CommandBuffer::GetGpuFenceHandle is time spent waiting for the GPU process, not computing (BACKLOG_3D 3D-37). Tracing adds overhead: frame times run about 1 ms longer while it records.
  • --heap records what the page allocates for 6 s in VR after the CPU profile: a sampling heap profile (one sample per 4 KB allocated) that keeps the objects collected meanwhile, so it shows the garbage and not only what survives. It saves vr.heapprofile (DevTools' Memory panel loads it), and the summary gives KB allocated per second, by function and by script file. Major garbage collections were the largest slow frames (BACKLOG_3D 3D-44).
  • --scroll measures VR while the view scrolls. The autopilot plays 180 s in the window while the page's input tape (src/input-tape.ts, only with ?measure=1) records the inputs; then the tape replays in VR from the state it started in, so the autopilot's planning is not in the measured frames. Use an early goal (--goal "Advance through section"). The log and the summary (scrolled) report how far the view moved and how much of the tape played; a replay that stopped matching the recorded tick or camera reports where. The output folder name ends in -scroll. The probe frameLog logs every XR frame of the replay; the summary's frameLog lists the slow ones with the game tick and camera they followed, so a stall can be found again at the same place of the same tape. The draw-count probe and the headset screenshot themselves make two long frames at fixed times in every run (about 18 and 20 s in). --tape <seconds> sets how long the autopilot records (180 by default, about 65 s of play on the Quest); comparisons need about 50 s more, so use --tape 420 with --compare.
  • --page game measures VR on game.html, the page players use (implies --scroll): the tape recorded on playlab.html (start state and inputs, saved with the recordings' lossless codec) is carried to game.html?measure=1&invincible=1&view=<style> in the same tab and replays there. Use --tape 420 with --compare.
  • Each A/B side also reports page: every XR frame the page drew in its windows (frame rate, frames later than 12.5 ms and 22 ms), from the frame log (--scroll, --page game). VrApi lines can go missing under load; prefer page when they do. A shadows comparison also takes a vr-shadows headset screenshot: check the shadows are drawn before reading their cost.
  • --adb and --device name the adb executable and the headset's Wi-Fi address when adb is not on the PATH.

Two other commands: - node tools/quest_profile.mjs screenshot <name> takes a headset screenshot. It fails rather than return an older picture; an asleep headset takes none. Add --awake to wake it for the picture. - node tools/quest_profile.mjs restore turns the wear sensor back on, if a run was interrupted. - node tools/quest_profile.mjs trace <name> traces whatever the headset browser does now into captures/device/<name>.json and prints the summary. Hold the headset awake first (a run or screenshot --awake does), or an asleep headset gives no XR frames. - node tools/quest_profile.mjs trace-summary <file> prints the summary of a saved trace. - node tools/quest_profile.mjs profile-diff <before.cpuprofile> <after.cpuprofile> compares two CPU profiles, for example vr.cpuprofile and vr-shadows.cpuprofile of one run: self and inclusive time per function in ms per second, largest changes first. V8 inlining can file a function under a caller that did not call it; check the call paths in DevTools' Performance panel before acting on one row.

Phones

node tools/quest_profile.mjs phone --device <adb serial> --style toy measures the 3D view in Chrome on an Android phone (BACKLOG_3D 3D-40). Serve the hook over HTTP first: python tools/device_measure_server.py --http --port 8445. The phone reaches it as its own 127.0.0.1 through adb reverse, which is a secure context without a certificate.

  1. Pair the phone once: Settings → Developer options → Wireless debugging → Pair device with pairing code, then adb pair <ip>:<pairing port> <code>. adb then finds the phone over mDNS (adb devices lists it as adb-<serial>._adb-tls-connect._tcp). With the headset connected too, pass that name as --device.
  2. The tool opens playlab.html?measure=1&invincible=1 in Chrome, holds the screen on with the page's wake lock, and plays the same autopilot scenario as run up to --goal. Then it records an input tape of --tape seconds (45 by default) and stops the autopilot.
  3. It puts the 3D view in full screen. The view keeps the arcade's 224:256 shape, centred, so all of it is on screen.
  4. For each desktop-effects setting in --effects (default off,on: the sun shadow map, ambient occlusion and tilt-shift, which game.html leaves off on touch devices) and each pixel ratio in --ratios (default 3,2,1.5,1), it replays the tape and measures --measure seconds (12 by default) after a 2 s settle: - the window's frame rate and frame gaps; - script time per frame; - draws and triangles; - on Qualcomm GPUs, the GPU's busy share (/sys/class/kgsl/kgsl-3d0/gpu_busy_percentage, sampled every 0.5 s).
  5. It takes a phone screenshot at the first ratio of each effects setting. Then it leaves the page, which ends the wake lock and the full screen.

Everything goes to captures/device/<time>-<style>-phone/summary.json, with the display's refresh rate and the GPU's name. Chrome caps the frame rate at the display's mode, often 60 Hz. When every setting reaches the cap, the GPU busy share shows the headroom. It depends on the GPU clock, which the phone changes with load, so compare shares within one run, not as milliseconds.

Files

File Role
tools/device_measure_server.py tools/serve.py over HTTPS. Injects the page script into game.html or playlab.html with ?measure=1, and appends /__report posts to captures/device/reports.jsonl.
tools/device_measure_page.js Runs before the page's modules. Keeps three.js's scenes and renderers (__THREE_DEVTOOLS__ hook) in window.__measure, times window and XR frames, and reports load marks and a frame summary every 5 s.
tools/device_probes.mjs The in-page probes the profile runs over the DevTools protocol.
tools/quest_profile.mjs adb (Wi-Fi), the DevTools socket, the scenario, VrApi parsing and screenshots; phone for Android phones.

game.html?measure=1 works too, for load times and window frame rates on phones. Its numbers arrive in reports.jsonl.

On this PC, python tools/device_measure_server.py --http --port 8445 serves the same hook over plain HTTP on 127.0.0.1. A desktop browser can then run the probes from tools/device_probes.mjs in its console, for example to compare frames with the part batches on and off.

Pitfalls

  • A panel out of view gets no frames. The tool brings the browser forward with am start. If the window numbers show 0 fps, check a screenshot.
  • A background tab gets almost no frames. am start with a URL opens a new tab, so duplicates collect. The tool brings the tab it drives to the front (/json/activate).
  • Lost tracking. A headset lying still, or in a dim room, loses tracking ("Finding position in room"), and the browser then shows no panel and opens no DevTools socket. Pick it up and look around a lit room until it recovers.
  • A stuck VR session. After a page reload, the browser can refuse VR with "There is already an active, immersive XRSession" or "The specified session configuration is not supported". Restart it with adb shell am force-stop com.oculus.browser.
  • Leftover probes. A probe that leaves a callback behind skews later numbers. Measure on a freshly loaded page.