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:
+39
-8
@@ -39,8 +39,16 @@ type Row struct {
|
||||
TotalLines int
|
||||
VisStart int
|
||||
VisEnd int
|
||||
Gap bool // DeltaMs is an idle gap, not frame latency (see gapThreshold)
|
||||
}
|
||||
|
||||
// gapThreshold separates "the app was idle" from "a frame was slow": a
|
||||
// gap of this length or more means no frames were emitted for that whole
|
||||
// time, so the first frame of the next burst carries the entire idle period
|
||||
// in DeltaMs. A genuinely slow frame on a real device is at most a few
|
||||
// tens of ms.
|
||||
const gapThreshold = 100 * time.Millisecond
|
||||
|
||||
// Profiler records logic-frame cadence plus context. All methods must be
|
||||
// called from the owning goroutine only (no locks).
|
||||
type Profiler struct {
|
||||
@@ -110,6 +118,7 @@ func (p *Profiler) Record(ctx Ctx) {
|
||||
TotalLines: ctx.TotalLines,
|
||||
VisStart: ctx.VisStart,
|
||||
VisEnd: ctx.VisEnd,
|
||||
Gap: delta >= gapThreshold,
|
||||
})
|
||||
|
||||
if now.Sub(p.lastLog) >= time.Second {
|
||||
@@ -120,18 +129,40 @@ func (p *Profiler) Record(ctx Ctx) {
|
||||
p.flush()
|
||||
p.lastFlush = now
|
||||
}
|
||||
// Burst ended: persist immediately. The periodic flush above only runs
|
||||
// inside Record, so without this an idle tail (or a force-stopped app)
|
||||
// would lose the last burst's rows; the frame that opens a new burst is
|
||||
// the moment the previous burst's rows become final.
|
||||
if delta >= 2*time.Second {
|
||||
p.flush()
|
||||
p.lastFlush = now
|
||||
}
|
||||
}
|
||||
|
||||
// logSummary prints a rolling percentile summary of the frames buffered since
|
||||
// the last flush to logcat.
|
||||
// the last flush to logcat. Idle gaps are kept OUT of the latency
|
||||
// percentiles (they are pauses between bursts of activity, not slow frames)
|
||||
// and reported separately.
|
||||
func (p *Profiler) logSummary() {
|
||||
n := len(p.buf)
|
||||
if n == 0 {
|
||||
return
|
||||
}
|
||||
ds := make([]float64, n)
|
||||
for i, r := range p.buf {
|
||||
ds[i] = r.DeltaMs
|
||||
gaps, maxGap := 0, 0.0
|
||||
ds := make([]float64, 0, n)
|
||||
for _, r := range p.buf {
|
||||
if r.Gap {
|
||||
gaps++
|
||||
if r.DeltaMs > maxGap {
|
||||
maxGap = r.DeltaMs
|
||||
}
|
||||
continue
|
||||
}
|
||||
ds = append(ds, r.DeltaMs)
|
||||
}
|
||||
if len(ds) == 0 {
|
||||
log.Printf("PERF frames=%d (all idle gaps; max=%.0f ms)", n, maxGap)
|
||||
return
|
||||
}
|
||||
p50, p90, p99, mx := percentiles(ds)
|
||||
over16, over33 := 0, 0
|
||||
@@ -143,16 +174,16 @@ func (p *Profiler) logSummary() {
|
||||
over33++
|
||||
}
|
||||
}
|
||||
log.Printf("PERF frames=%d p50=%.1f p90=%.1f p99=%.1f max=%.1f ms over16.7=%.0f%% over33.4=%.0f%%",
|
||||
n, p50, p90, p99, mx, pct(over16, n), pct(over33, n))
|
||||
log.Printf("PERF frames=%d p50=%.1f p90=%.1f p99=%.1f max=%.1f ms over16.7=%.0f%% over33.4=%.0f%% gaps=%d maxGap=%.0fms",
|
||||
n, p50, p90, p99, mx, pct(over16, len(ds)), pct(over33, len(ds)), gaps, maxGap)
|
||||
}
|
||||
|
||||
// flush appends the buffered rows to the CSV file and clears the buffer.
|
||||
func (p *Profiler) flush() {
|
||||
if len(p.buf) > 0 && p.file != nil {
|
||||
for _, r := range p.buf {
|
||||
fmt.Fprintf(p.file, "%d,%.3f,%.3f,%s,%.1f,%.1f,%d,%d,%d\n",
|
||||
r.Seq, r.Tms, r.DeltaMs, r.Page, r.ScrollDP, r.MaxScrollDP, r.TotalLines, r.VisStart, r.VisEnd)
|
||||
fmt.Fprintf(p.file, "%d,%.3f,%.3f,%s,%.1f,%.1f,%d,%d,%d,%v\n",
|
||||
r.Seq, r.Tms, r.DeltaMs, r.Page, r.ScrollDP, r.MaxScrollDP, r.TotalLines, r.VisStart, r.VisEnd, r.Gap)
|
||||
}
|
||||
}
|
||||
p.buf = p.buf[:0]
|
||||
|
||||
Reference in New Issue
Block a user