Add pre-release frame-regression profiling

Ensures the app never generates frames without a cause (frame emission
is event-driven; a spinner would burn CPU/battery for the app's entire
idle life). Verified on the emulator and the phone: healthy runs show
ZERO frames across all idle windows (PERF-PRESENT fps < 1).

- perf: rows whose previous frame is >= 100ms away are idle gaps, not
  slow frames — flagged in the CSV (new gap column) and kept out of the
  logcat summary's latency percentiles (reported as gaps=N maxGap=...).
  A frame >= 2s after the previous one flushes the CSV, so a burst's
  rows are persisted the moment the next burst starts (an idle tail or
  force-stop no longer loses the last burst).
- editor: debug 'open <path>' command (cmd-file poller, perf mode):
  opens a file from any page via the same OpenFile path as a browser
  tap — deterministic, no pixel tapping.
- e2e: TestNoFramesWhileIdle (browser + editor after load/scroll/find)
  asserts the logic emits ZERO frames across an idle window once
  settled — the headless contract, in the regular go-test suite.
- scripts/profile_emulator.sh: drives launch, 8s idle, open (seeded
  4000-line file), 16s idle, 3 scrolls on a device/emulator; groups the
  CSV into phases at idle gaps >= 2s and FAILs on a phase over its frame
  budget (1/s spinner exceeds a 16s idle budget; faster ones balloon a
  phase or show in PERF-PRESENT). Validated both ways: PASS on a healthy
  build (emulator + phone), FAIL on an injected 500ms frame spinner.
- doc: architecture.md §11 updated (gap handling, burst flush, debug
  open, frame-regression guard, 2026-08 measurements).
This commit is contained in:
gmp
2026-08-20 14:18:08 -04:00
parent c789de4b44
commit ac1c32e4c0
5 changed files with 360 additions and 21 deletions
+36 -6
View File
@@ -543,17 +543,42 @@ cannot measure this app because it renders into a `SurfaceView`).
`/storage/emulated/0/PadPerf/enable` before launch. `main.go` then creates a
`perf.Profiler` that writes `logic_frames.csv` (one row per logic frame: seq,
ms-since-start, frame delta, page, scroll Dp, max-scroll Dp, total lines,
visible byte range) and logs a rolling ~1 s `PERF` summary. `DestroyEvent`
stops it (final flush + `PERF stopped` summary with p50/p90/p99/max).
visible byte range, gap flag) and logs a rolling ~1 s `PERF` summary.
`DestroyEvent` stops it (final flush + `PERF stopped` summary with
p50/p90/p99/max).
- **Gap handling**: a row whose previous frame is ≥ 100 ms away is an idle
gap, not a slow frame (the first frame of a burst would otherwise carry the
whole idle period in its delta). Gap rows are flagged in the CSV, kept out
of the summary's latency percentiles, and reported separately
(`gaps=N maxGap=…ms`). A frame that arrives ≥ 2 s after the previous one
also flushes the CSV immediately: the frame that opens a new burst is the
moment the previous burst's rows become final, so an idle tail (or a
force-stopped app) does not lose the last burst.
- **Main-side presents**: `main.go` separately counts `app.FrameEvent`s and
logs a rolling `PERF-PRESENT frames=N fps=F` line; fps ≫ 1 while idle means
something is invalidating the window continuously.
- **Hook**: `internal/editor.PerfRecord` is a package-level func, set by
`main.go` only when enabled. `Logic.emitFrame` calls it on the owner
goroutine with a `ProbeRecord` **before** sending the frame. When disabled it
is `nil` and the per-frame cost is a single nil check.
- **Debug scroll jumps** (for testing, off by default): with the profiler on,
- **Debug commands** (for testing, off by default): with the profiler on,
`main.go` also polls `/storage/emulated/0/PadPerf/cmd` (a one-shot file
consumed on read). `top`, `bottom`, `frac <0..1>`, and `dp <int>` jump the
editor's `ScrollOffset` (clamped to `[0, MaxScroll]`) and emit a frame. This
lets a test drive large-offset scrolls deterministically without pixel taps.
consumed on read; `Logic.applyDebugCmd`). `top`, `bottom`, `frac <0..1>`,
and `dp <int>` jump the editor's `ScrollOffset` (clamped to
`[0, MaxScroll]`) and emit a frame; `open <path>` opens a file from any
page (same `OpenFile` path as a browser tap) and emits. This lets a test
drive scrolls and file opens deterministically without pixel taps.
- **Frame-regression guard** (pre-release): frame emission is event-driven, so
a healthy app emits small per-action bursts and nothing while idle. Two
layers check that: `TestNoFramesWhileIdle` (internal/test/e2e, in the
regular go-test suite) asserts the logic emits ZERO frames across an idle
window after the browser and the editor (load + scroll + find cycle)
settle; and `scripts/profile_emulator.sh` runs the full sequence on a
device/emulator — 8 s idle, open, 16 s idle, three scrolls — via the debug
commands above, seeds a known 4000-line file for the open, and FAILs if any
idle-split phase of the CSV exceeds its frame budget (a ≥ 1/s spinner
exceeds a 16 s idle budget; a faster one balloons a phase or shows up in
PERF-PRESENT).
- The profiler is owned by the goroutine that creates it and is single-goroutine
(no locks). It does **not** `Sync()` the CSV per flush (only per row batch) to
avoid periodic fsync hitches in the logic path.
@@ -561,3 +586,8 @@ cannot measure this app because it renders into a `SurfaceView`).
across scroll offsets 0.02→1.0 (no large-offset degradation); the visible byte
range stays ≤ ~4.3 KB (0.04% of the file); PSS plateaus ~250 MB (bounded
high-water mark, no leak). See `development_plan.md` Phase 6.
- **Measured** (emulator, 4000-line file, 2026-08): the pre-release profile
passes with 5 phases — browser startup 5–6 frames, open 5–6, and 1–2 per
scroll — and ZERO frames across all idle windows (PERF-PRESENT fps < 1
throughout); an injected 500 ms frame spinner makes the script FAIL
(phase 1 = 69 frames vs budget 10, PERF-PRESENT fps ≈ 2.4).