Files
plezy/tools/perf/launch.sh
edde746 f95465067e chore(tools): add the on-device frame and startup benchmark harness
The measurements behind the preceding commits needed a repeatable way to drive a
real Android TV box and read both sides of the frame. `dumpsys gfxinfo` alone is
not enough (it sees the HWUI composite, not Flutter's UI and raster threads), and
DevTools is not scriptable.

- `vmclient.mjs` -- Dart VM Service client over WebSocket, plus percentile and
  timeline helpers and a CPU self/total-time reducer over `getCpuSamples`.
- `scenarios.mjs` -- repeatable D-pad workloads. Keys are sent as one batched
  `input keyevent` invocation per burst, because a separate invocation per key
  costs more on the device than the interaction being measured.
- `bench.mjs` -- runs a scenario and correlates Flutter's own frame phases
  (`Animator::BeginFrame`, LAYOUT, SEMANTICS, BUILD, PAINT, `Rasterizer::DoDraw`)
  with HWUI framestats, reporting medians over repeats.
- `profile.mjs` -- CPU self/total time by function plus an allocation profile.
- `launch.sh` -- cold-launches the profile build, sets up its own port forward and
  prints a host-reachable VM Service URI. Passes `--ez enable-dart-profiling`,
  which only `flutter run` supplies by default, and wakes the display first
  because `am start -W` silently reports no `TotalTime` when the screen is off.

Not referenced by `lib/` and not packaged; `tools/` is outside the APK.
2026-08-23 18:13:39 +02:00

43 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Cold-launch the profile build and print a host-reachable VM Service URI.
# Deterministic: own forward on a fixed port, token read from logcat.
set -euo pipefail
ADB="$HOME/Library/Android/sdk/platform-tools/adb"
DEVICE="${PLEZY_DEVICE:-192.168.1.7:5555}"
PKG=com.edde746.plezy
HOST_PORT="${PLEZY_VM_PORT:-9223}"
a() { "$ADB" -s "$DEVICE" "$@"; }
a shell input keyevent 224 >/dev/null 2>&1 || true
a shell am force-stop "$PKG" >/dev/null 2>&1 || true
sleep 2
a logcat -c
a shell input keyevent 224 >/dev/null 2>&1 || true
# --ez enable-dart-profiling: FlutterShellArgs reads it from the intent, which
# `am start` must supply explicitly (only `flutter run` passes it for us).
a shell am start -W -S --ez enable-dart-profiling true -n "$PKG/$PKG.MainActivity" >/dev/null 2>&1
LINE=""
for _ in $(seq 1 40); do
LINE=$(a logcat -d 2>/dev/null | grep -o 'The Dart VM service is listening on http://127.0.0.1:[0-9]*/[^ ]*' | tail -1 || true)
[ -n "$LINE" ] && break
sleep 1
done
[ -n "$LINE" ] || { echo "VM service never published" >&2; exit 1; }
URI="${LINE##* }" # http://127.0.0.1:PORT/TOKEN/
DEV_PORT=$(echo "$URI" | sed -E 's#.*127\.0\.0\.1:([0-9]+)/.*#\1#')
TOKEN=$(echo "$URI" | sed -E 's#.*127\.0\.0\.1:[0-9]+/##')
a forward --remove "tcp:$HOST_PORT" >/dev/null 2>&1 || true
a forward "tcp:$HOST_PORT" "tcp:$DEV_PORT" >/dev/null
# Let the app reach its settled home screen before anyone measures it.
sleep "${PLEZY_SETTLE:-14}"
a shell input keyevent 224 >/dev/null 2>&1 || true
echo "http://127.0.0.1:$HOST_PORT/$TOKEN"