import { type ActionHandler } from '@farmslot/recipe-runner'; import { type FrameMetricSummary, type PerformanceSourceStatus } from '@farmslot/recipe-runner/runtime/cdp-trace'; import { type AndroidDeviceDescription, type AndroidFrameSample, type AndroidGfxinfoCaptureResult, type AndroidGfxinfoPerformanceBackend, type AndroidShownMarker } from './android-gfxinfo-performance.js'; export declare const PERFORMANCE_CAPTURE_ACTION = "app.performance_capture"; export interface RecipeNodeSpan { nodeId: string; action: string; /** What the node acted on (its test id, selector, text or key), named in failures. */ target?: string; startedAtEpochMs: number; endedAtEpochMs?: number; } export interface PerformanceBudget { /** Fail when the lowest sustained FPS of the window is below this. */ min_sustained_fps?: number; /** Fail when the 95th percentile press latency is above this. */ max_press_p95_ms?: number; /** Fail when any press latency is above this, or a press could not be timed. */ max_press_ms?: number; /** Fail when the window recorded fewer native frames, e.g. a scroll that never rendered. */ min_frames?: number; } /** * The reference a failure is compared against, e.g. the default branch on a * named build and refresh rate. `label` and the numbers appear in failure * messages; the whole object is echoed in the summary. */ export interface PerformanceBaseline { label: string; sustained_fps?: number; press_p95_ms?: number; press_max_ms?: number; /** Native frames the window recorded on the baseline. */ frames?: number; /** Display refresh rate of the baseline; a different measured rate is noted. */ refresh_hz?: number; [key: string]: unknown; } export interface PerformanceTargets { fps?: number; press_ms?: number; } export interface PressLatency { nodeId: string; action: string; target?: string; /** Input frame start to the end of the frame that answered it; absent when not timed. */ latencyMs?: number; /** * `shown`: the screen's `[farmslot-perf] shown` line, logged after React * committed it, and the frames that started by two frame budgets after it. * `mount`: the first frame after the touch that stood out is the answer. * `first-frame`: none stood out, so the press is timed to the first frame * after the touch; the new screen did no measurable UI-thread work. */ answer?: 'shown' | 'mount' | 'first-frame'; /** The screen whose shown line times the press (`shown_markers`). */ marker?: string; /** Why the press has no latency. */ unmeasuredReason?: string; } export interface PerformanceWindowSummary { schemaVersion: 1; id: string; status: PerformanceSourceStatus; platform: 'android'; source: string; startedAtEpochMs: number; endedAtEpochMs: number; durationMs: number; frames: FrameMetricSummary; /** The lowest active FPS over any `sustainedWindowMs` of the window; absent with too few frames. */ sustainedFps?: number; sustainedWindowMs: number; presses: PressLatency[]; press: PressStats; /** The same statistics per press target, e.g. per tab. */ pressByTarget: Record; /** * `inconclusive` when the capture has a coverage gap (failed polls, frames * gfxinfo overwrote), whatever else failed: it never passes, and `failures` * still lists what the partial capture showed. An idle window, no frames and * no gaps, passes. */ budget?: { verdict: 'pass' | 'fail' | 'inconclusive'; limits: PerformanceBudget; failures: string[]; inconclusive: string[]; }; baseline?: PerformanceBaseline; targets?: { fps?: { target: number; sustainedFps?: number; activeFps?: number; met: boolean; }; press?: { target: number; p95Ms?: number; maxMs?: number; met: boolean; }; }; /** Frames the capture may have missed: poll failures, overwritten frames, an overrun window. */ coverageGapReasons: string[]; /** Why the source has no frames, e.g. an idle screen. Not a gap. */ unavailableReasons: string[]; /** Observations that don't change the verdict, e.g. a refresh rate unlike the baseline's. */ notes: string[]; } export interface PressStats { count: number; timed: number; /** Timed presses answered by their screen's shown line. */ shown: number; /** Timed presses with no standout mount frame, answered by the first frame. */ firstFrame: number; p50Ms?: number; p95Ms?: number; maxMs?: number; } export interface PerformanceCaptureSession { handler: ActionHandler; /** The runner's node boundaries, used to find the presses inside a window. */ recordNodeEvent(event: { nodeId: string; action: string; target?: string; status: 'running' | 'passed' | 'failed'; }): void; close(): Promise; } export interface PerformanceCaptureSessionOptions { env: Record; logger?: Pick; /** Validate the nodes without a device: no window opens and nothing is measured. */ dryRun?: boolean; createBackend?: (env: Record) => AndroidGfxinfoPerformanceBackend; now?: () => number; } export declare function createPerformanceCaptureSession({ env, logger, dryRun, createBackend, now, }: PerformanceCaptureSessionOptions): PerformanceCaptureSession; export declare function summarizeWindow({ id, startedAtEpochMs, endedAtEpochMs, maxDurationMs, result, spans, budget, shownMarkers, baseline, targets, sustainedWindowMs, responseWindowMs, }: { id: string; startedAtEpochMs: number; endedAtEpochMs: number; maxDurationMs: number; result: AndroidGfxinfoCaptureResult; spans: readonly RecipeNodeSpan[]; budget?: PerformanceBudget; /** Press target -> the screen whose `[farmslot-perf] shown` line answers it. */ shownMarkers?: Record; baseline?: PerformanceBaseline; targets?: PerformanceTargets; sustainedWindowMs: number; responseWindowMs: number; }): PerformanceWindowSummary; /** * The press's latency: from the first frame that handled input during the * press node to the end of the frame that answered it. The answer is the * first later frame that stands out (see MOUNT_MIN_MS) within * `responseWindowMs`, or past it within `MOUNT_LOOKAHEAD` windows, after a * pause too, a frame with a whole frame budget of UI-thread work: the frame * that mounts and draws the new screen. Touch ripples run on the render * thread. Only when nothing answers that way is the press timed to the first * frame within `responseWindowMs` (`first-frame`). A press with no input * frame, or no frame after it, is untimed. */ export declare function measurePress(samples: readonly AndroidFrameSample[], span: RecipeNodeSpan, responseWindowMs: number, windowEndEpochMs: number): PressLatency; /** * A press timed by the app's own word: from the first frame that handled input * during the press node to the screen's next `[farmslot-perf] shown` line, or * to the end of the last frame from the touch on that started by * `SHOWN_MARKER_FRAMES` frame budgets after the line, if that is later. The * app logs the line from the second animation frame after focus, once * JavaScript is free, so the UI thread can still be finishing the mount frame * then. A press can over-read by up to about two light frames, and could miss * a mount frame that starts more than two budgets after the line; a live * update that starts later doesn't count, and a stall that delays the mount * delays the line too. No line before the next press leaves the press untimed. */ export declare function measureShownPress(samples: readonly AndroidFrameSample[], span: RecipeNodeSpan, screen: string, markers: readonly AndroidShownMarker[], searchEndEpochMs: number, frameBudgetMs: number): PressLatency; export interface PerformanceReportEnvironment { device?: AndroidDeviceDescription; checkout?: { head?: string; dirty?: boolean; }; } export declare function renderPerformanceReport(title: string, summaries: readonly PerformanceWindowSummary[], environment?: PerformanceReportEnvironment): string; //# sourceMappingURL=performance-capture.d.ts.map