Files
reims-vgpu/scripts/browser-probe/web-gpu-probe.sh
T
Anees IqbalandClaude 6ae2502d7a ✨ A mean frame rate cannot see the hitch it is asked about
`scripts/browser-probe/` (measurement only; no device or backend behavior
changes).

The frame-pacing arm of `gpu-probe.html` reported a mean fps and a single
worst-frame figure. Neither can answer the question the probe exists for.
"120 fps, perfectly even" and "120 fps with occasional stalls" produce the
same mean, and one 40 ms stall and forty of them produce the same worst
frame. The one measured number carried forward from this rig — Safari at
119.4 fps, worst frame 13 ms — is consistent with both a healthy display and
a stuttering one, so it could not settle anything.

The loop now keeps every frame delta and summarises the distribution:
median/p95/p99, a long-frame count and percentage, dropped refreshes, the
worst consecutive run of long frames, and a histogram bucketed in refresh
intervals. The run of long frames is reported separately from their count
because only a run is visible as a jerk; ten scattered drops and one
ten-frame freeze are the same number and not the same defect.

Two choices worth stating. The refresh interval is the *median* observed
delta, not a hardcoded 1/120: this guest display has run at 60 and at 120,
and a fixed budget misreports every frame on the other one. The median
rather than the mean because it is the estimator a burst of long frames
cannot drag with it. A frame counts as long past 1.5 intervals, the midpoint
between one interval and two, which is where a delta stops being jitter
around the budget and becomes a skipped vblank.

The statistics moved into a DOM-free `summarizeDeltas` so they can be tested.
`PROBE_SECONDS` widens the window through `web-gpu-probe.sh` (the settle wait
scales with it, or a slow browser is read before it posts and scored silent);
5 s establishes a mean but can miss a stall that happens twice a minute.

Tests: `node scripts/browser-probe/pacing-stats-test.mjs` — 20 checks, all
passing. It slices the functions out of the page rather than restating them,
so it exercises shipped code and not a copy that can drift. Mutation-verified
by replacing the median with a hardcoded 120 Hz budget: 5 checks fail, and a
healthy 60 Hz stream is then scored as dropping all 300 frames, which is the
specific lie the median exists to prevent.

Not verified: no live guest run yet — this commit changes the instrument, not
the thing measured. Requires `node` for the test only; the probe page itself
runs in the guest browser as before.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-01 23:29:21 +03:00

51 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# scripts/browser-probe/web-gpu-probe.sh — ask each browser, in its own words,
# whether WebGL/WebGPU came up on hardware and how many frames it sustained.
#
# scripts/browser-probe/web-gpu-probe.sh safari|chrome|firefox [extra browser args…]
#
# `PROBE_SECONDS=30` lengthens the frame-pacing window. The page reports a full
# delta distribution (median/p95/p99, long-frame count, worst hitch run, and a
# histogram in refresh intervals), so a mean that looks like 120 fps can still
# be convicted of dropping frames.
#
# The page is served over http from inside the guest and posts its result back
# to that same server (see probe_server.py for why). One browser per run: they
# fight over the foreground and a background window's requestAnimationFrame is
# throttled, which would be scored as a frame-rate result.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GUEST="${GUEST:-macos-vm}"
PORT="${PROBE_PORT:-8998}"
BROWSER="${1:?usage: web-gpu-probe.sh safari|chrome|firefox [args…]}"
shift || true
# How long the page measures frame pacing for. The default matches the page's
# own default; raise it when the question is an *occasional* hitch rather than a
# mean, since a 5 s window can miss a stall that happens twice a minute.
SECONDS_ARG="${PROBE_SECONDS:-}"
# The wait has to outlast the measurement itself plus browser launch, or the
# result is read before it is posted and a slow browser is scored as silent.
SETTLE="${PROBE_SETTLE:-$(( ${SECONDS_ARG:-5} + 25 ))}"
URL="http://127.0.0.1:$PORT/${SECONDS_ARG:+?seconds=$SECONDS_ARG}"
scp -q "$SCRIPT_DIR/probe_server.py" "$SCRIPT_DIR/gpu-probe.html" "$GUEST:/tmp/"
case "$BROWSER" in
safari) APP="Safari" ;;
chrome) APP="Google Chrome" ;;
firefox) APP="Firefox" ;;
*) echo "unknown browser: $BROWSER" >&2; exit 64 ;;
esac
ssh "$GUEST" "pkill -f probe_server.py >/dev/null 2>&1 || true
pkill -f '$APP' >/dev/null 2>&1 || true
sleep 2
nohup python3 /tmp/probe_server.py $PORT /tmp/gpu-probe.html /tmp/probe-result.json \
>/tmp/probe-server.log 2>&1 &
sleep 2
open -a '$APP' ${*:+--args $*} '$URL'
sleep $SETTLE
cat /tmp/probe-result.json 2>/dev/null || echo 'NO RESULT POSTED'"