Files
iron-arc/tools/device/perf.sh
T

43 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Measures presented-frame timing of the running app.
#
# NOTE: `dumpsys gfxinfo` is useless for Flutter apps (they render through their
# own SurfaceView/Impeller pipeline, so HWUI renders 0 frames). We therefore read
# SurfaceFlinger frame timestamps of the BLAST layer instead.
set -euo pipefail
ADB=${ADB:-adb}
PKG=${PKG:-de.softwareapphb.ironarc}
layer=$($ADB shell dumpsys SurfaceFlinger --list 2>/dev/null | tr -d '\r' \
| grep -F 'SurfaceView[' | grep -F "$PKG" | grep -F '(BLAST)#0' | head -1)
if [ -z "$layer" ]; then
echo 'layer not found - is the app running in the foreground?' >&2
exit 1
fi
echo "layer: $layer"
$ADB shell "dumpsys SurfaceFlinger --latency '$layer'" > /tmp/ironarc-latency.txt
python3 - <<'PY'
rows = []
vsync = None
for line in open('/tmp/ironarc-latency.txt'):
parts = line.split()
if len(parts) == 1 and parts[0].isdigit() and vsync is None:
vsync = int(parts[0])
continue
if len(parts) == 3 and all(p.isdigit() for p in parts):
_, actual, _ = map(int, parts)
if actual not in (0, 9223372036854775807):
rows.append(actual)
rows = sorted(set(rows))
deltas = sorted((rows[i + 1] - rows[i]) / 1e6 for i in range(len(rows) - 1))
deltas = [d for d in deltas if 1 <= d <= 200]
if not deltas:
print('no valid frames captured')
raise SystemExit(1)
thr = (vsync / 1e6 if vsync else 16.666) * 1.2
q = lambda p: deltas[min(len(deltas) - 1, int(len(deltas) * p))]
jank = sum(1 for d in deltas if d > thr) / len(deltas) * 100
print(f'frames={len(deltas)} fps_median={1000 / q(0.5):.1f}')
print(f'p50={q(0.5):.2f}ms p90={q(0.9):.2f}ms p99={q(0.99):.2f}ms')
print(f'jank(> {thr:.1f}ms) = {jank:.1f}%')
PY