Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/claude/skills/mobile-dev/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ CPU, memory, and FPS, but not per-thread detail, and their Ask buttons cannot se
chat, so the user asks you instead: read the samples with
`mobile_read_performance_recording` (and frame pages with
`mobile_read_performance_frames` for Android jank) before answering. FPS is
device-wide and cannot attribute a slowdown to one app. For a physical iPhone,
device-wide and cannot attribute a slowdown to one app. When the card includes
Android frame detail, select a diamond on the FPS graph to inspect a late,
dropped or janky display frame and its SurfaceFlinger reasons. For a physical iPhone,
use `summary.hitchStats` for the count and time lost to visible hitches in the
selected range. A null result means hitch data is unavailable for that range. Use
`mobile_list_performance_recordings` to find earlier runs and
Expand Down
6 changes: 5 additions & 1 deletion docs/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ The Memory track shows the main process's current usage, sampled average, maximu

The green **Display FPS** track shares the CPU and memory timeline, cursor, zoom and 150-second history. It records independently of the selected app, with current, average, maximum and minimum FPS. It includes other apps and system UI; a quiet or locked screen can report zero. This measures display updates rather than the panel's refresh rate, and does not identify which app caused a drop. Missing measurements remain gaps.

Android 12+ uses only Perfetto FrameTimeline's presented actual display frames, excluding dropped frames and individual app/layer frames. A bundled external native consumer reads a bounded 4 MiB trace buffer once per second over ADB without creating a trace file, attaching a debugger, requiring root or installing an app SDK. Readback adds roughly three seconds of delay. SurfaceFlinger can report a frame later; the chart updates that frame's original interval. Devices without FrameTimeline and Android versions below 12 report an explicit limitation.
On Android 12+, the FPS counter counts presented display frames from Perfetto FrameTimeline. A bundled external native consumer reads a bounded 4 MiB trace buffer once per second over ADB without creating a trace file, attaching a debugger, requiring root or installing an app SDK. Readback adds roughly three seconds of delay. SurfaceFlinger can report a frame later; the chart updates that frame's original interval. Devices without FrameTimeline and Android versions below 12 report an explicit limitation.

Diamonds on the live and saved **Display FPS** graphs mark frames SurfaceFlinger reported as late, dropped or janky. A frame with multiple reasons gets one diamond. Select it to see its time, presentation status and reported reasons. For a dropped frame the time is the end of the frame event. The **Inspect** menu also lists FPS samples with their flagged-frame counts and distinguishes a captured interval with zero flags from one without FrameTimeline data. An idle interval adds no markers by itself. These events cover the whole display, including system UI.

In chat hosts that can only show a recording preview, the diamonds appear when the frame data fits the tool result. Open the full recording in Mobile Dev to inspect larger runs.

Android FPS intervals also retain `frameTimeline`: its `clock` is `boottime`,
`intervalEndNs` identifies the device interval endpoint, and `frames` contains
Expand Down
5 changes: 5 additions & 0 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ The server measures Instruments startup and finalization with
Hitch events, app identity, and trace contents stay local. Existing
`ui.recording.derive` timing includes matching hitches to recorded FPS intervals and summarizing the selected range.

Since 0.1.195, `ui.performance.frame_markers` measures the time in milliseconds
to derive Android markers when the live FPS history changes. It uses the existing
bounded UI timing windows. Saved Android marker processing is included in
`ui.recording.derive`. Frame times, tokens and jank reasons stay local.

## Resource-saving operations

Since 0.1.179, `resource_saving.apply` counts successful and failed applications of
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobile-dev",
"version": "0.1.194",
"version": "0.1.195",
"private": true,
"workspaces": [
"packages/shared",
Expand Down
23 changes: 19 additions & 4 deletions packages/core/src/recording-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,28 @@ export function registerRecordingTools(server: McpServer, recordings: Performanc
const result = { content: [{ type: "text" as const, text: describeRecording(recording, summary, range) }], structuredContent };
const preview = recordingPreview(recording);
const response = withinResultBytes(result, { preview });
if (response === result || recording.iosHitches === undefined) return response;
const withHitches = { ...preview, iosHitches: recording.iosHitches };
return withinResultBytes(response, { preview: withHitches });
if (response === result) return response;
if (recording.iosHitches) {
const withHitches = { ...preview, iosHitches: recording.iosHitches };
return withinResultBytes(response, { preview: withHitches });
}
if (recording.target.platform === "android") {
let frameCount = 0;
let captured = false;
for (const sample of recording.fps.samples) {
if (sample.frameTimeline === undefined) continue;
captured = true;
frameCount += sample.frameTimeline.frames.length;
// Even a frame with one-digit values takes over 60 JSON bytes.
if (frameCount * 60 > RESULT_BYTES) return response;
}
if (captured) return withinResultBytes(response, { preview: { ...preview, fps: recording.fps } });
}
return response;
});
registerAppTool(server, "mobile_render_performance_recording", {
title: "Show an interactive performance chart in chat",
description: "Show a saved CPU/memory/FPS recording as an inline interactive chart with shared drag selection, thread breakdown and Ask. Completed physical iOS recordings overlay hitch markers on Display FPS, with per-sample hitch counts and range totals. Android frame data adds jank rate, classification coverage, dropped frames and frame-interval P50/P95/P99, updating with the selected range. Call this when reporting scrolling FPS/jank or comparing implementations so the user sees the chart alongside the analysis. The full timeline stays visible; automatic change highlights do not select or limit a range. Omit range unless the user requested a selection. Pass recording.id from mobile_record_performance or mobile_list_performance_recordings. Active runs update until finished. Data tools return measurements without rendering a chart. Returns the recording ID and summary numbers; the chart reads the samples itself, so use mobile_read_performance_recording for sample-level detail.",
description: "Show a saved CPU/memory/FPS recording as an inline interactive chart with shared drag selection, thread breakdown and Ask. Completed physical iOS recordings overlay hitch markers on Display FPS, with per-sample hitch counts and range totals. Android FrameTimeline marks late, dropped and janky device-wide display frames. Range statistics include jank rate, classification coverage, dropped frames and frame-interval P50/P95/P99. Call this when reporting scrolling FPS/jank or comparing implementations so the user sees the chart alongside the analysis. The full timeline stays visible; automatic change highlights do not select or limit a range. Omit range unless the user requested a selection. Pass recording.id from mobile_record_performance or mobile_list_performance_recordings. Active runs update until finished. Data tools return measurements without rendering a chart. Returns the recording ID and summary numbers; the chart reads the samples itself, so use mobile_read_performance_recording for sample-level detail.",
inputSchema, outputSchema: referenceOutputSchema, annotations: read, _meta: { ui: { resourceUri: RECORDING_URI, visibility } },
}, showRecording);
const comparisonTitle = comparisonTitleSchema.default("Performance comparison");
Expand Down
13 changes: 10 additions & 3 deletions packages/core/test/recording-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ test("recording tools distinguish data, inline rendering, workspace opening and
assert.equal(result.structuredContent?.title, recording.title);
const text = result.content.map(item => item.type === "text" ? item.text : "").join("");
assert.match(text, new RegExp(`recordingId ${recording.id}`));
// A preview for cards that cannot read the recording: every sample, no thread or frame detail.
// Small Android recordings carry exact frame timings for preview-only hosts.
const preview = result.structuredContent?.preview as typeof recording | undefined;
assert.equal(preview?.samples.length, recording.samples.length);
assert.ok(preview?.samples.every(sample => sample.threads.length === 0));
assert.ok(preview?.fps.samples.every(sample => sample.frameTimeline === undefined));
assert.deepEqual(preview?.fps, recording.fps);
assert.ok(JSON.stringify(result).length < 45_000, `${name} fits a host's tool result cap`);
}
assert.deepEqual(result.structuredContent?.range, { start: 12, end: 18 });
Expand Down Expand Up @@ -204,6 +204,11 @@ test("results that show recordings fit a host's result limit, leaving out previe
const directory = await mkdtemp(join(tmpdir(), "mobile-dev-recording-tools-"));
const store = new RecordingStore(directory);
const longest = longestRecordingFixture();
const frames = Array.from({ length: 900 }, (_, index) => {
const time = String(index + 1);
return { token: time, startTimeNs: time, endTimeNs: time, presentType: 2, jankType: 2 };
});
longest.fps.samples[0].frameTimeline = { clock: "boottime", intervalEndNs: "1000000000", frames };
const second = { ...longestRecordingFixture(), id: "44b7030b-a74e-466f-aeb0-bcd3ae8af972" };
const short = { ...recordingFixture(), id: "27cfecab-d99c-4533-90dd-e14a7cb0087b" };
const shortSecond = { ...recordingFixture(), id: "5d1f3c0e-8a4b-4e2a-9c61-0f7e2b9d4a13" };
Expand All @@ -219,7 +224,9 @@ test("results that show recordings fit a host's result limit, leaving out previe
const bytes = (result: unknown) => Buffer.byteLength(JSON.stringify(result));
// The longest recording still carries its preview, for cards that cannot read it.
const shown = await client.callTool({ name: "mobile_render_performance_recording", arguments: { recordingId: longest.id } });
assert.ok(shown.structuredContent?.preview);
const preview = shown.structuredContent?.preview as typeof longest;
assert.equal(preview.fps.samples.length, longest.fps.samples.length);
assert.equal(preview.fps.samples[0].frameTimeline, undefined);
assert.ok(bytes(shown) <= RESULT_BYTES, `${bytes(shown)} bytes`);
const compared = await client.callTool({ name: "mobile_compare_performance_recordings", arguments: { recordingIds: [longest.id, second.id] } });
assert.equal(compared.structuredContent?.previews, undefined);
Expand Down
33 changes: 27 additions & 6 deletions packages/shared/src/frame-statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,32 @@ export const nullableDisplayFrameStatsSchema = displayFrameStatsSchema.nullable(
export type DisplayFrameStats = z.infer<typeof displayFrameStatsSchema>;

const JANK_NONE = 1;
// UNKNOWN (256), unspecified (0), and future bits do not identify a classified frame.
const JANK_REASONS = 2 | 4 | 8 | 16 | 32 | 64 | 128 | 512 | 1024;
const JANK_UNKNOWN = 256;
const jankReasons: [number, string][] = [
[2, "SurfaceFlinger scheduling"], [4, "Prediction error"], [8, "Display HAL"],
[16, "SurfaceFlinger CPU deadline missed"], [32, "SurfaceFlinger GPU deadline missed"],
[64, "App deadline missed"], [128, "Buffer stuffing"],
[512, "SurfaceFlinger stuffing"], [1024, "Dropped frame"],
];
const JANK_REASONS = jankReasons.reduce((mask, [bit]) => mask | bit, 0);
const CLASSIFIED_JANK_BITS = JANK_NONE | JANK_REASONS;

export function classifyDisplayJank(bits: number | undefined) {
if (bits === undefined || bits === 0 || (bits & ~CLASSIFIED_JANK_BITS) !== 0) return "unknown";
return (bits & JANK_REASONS) === 0 ? "none" : "janky";
}

export function describeDisplayJank(bits = 0) {
const labels = [];
for (const [bit, label] of jankReasons) {
if ((bits & bit) !== 0) labels.push(label);
}
if ((bits & JANK_UNKNOWN) !== 0) labels.push("Unknown reason");
if ((bits & ~(CLASSIFIED_JANK_BITS | JANK_UNKNOWN)) !== 0) labels.push("Unrecognized jank flags");
if (labels.length > 0) return labels.join(", ");
return bits === JANK_NONE ? "No classified jank" : "Jank classification unavailable";
}

function percentile(sorted: number[], fraction: number) {
const rank = Math.ceil(sorted.length * fraction);
return sorted[rank - 1];
Expand Down Expand Up @@ -88,11 +110,10 @@ export function summarizeDisplayFrames(samples: DisplayFpsSample[], duration: nu
continue;
}
stats.presentedFrameCount++;
const jank = frame.jankType;
const classified = jank !== undefined && jank !== 0 && (jank & ~CLASSIFIED_JANK_BITS) === 0;
if (classified) {
const jank = classifyDisplayJank(frame.jankType);
if (jank !== "unknown") {
stats.classifiedPresentedFrameCount++;
if ((jank & JANK_REASONS) !== 0) stats.jankyPresentedFrameCount++;
if (jank === "janky") stats.jankyPresentedFrameCount++;
} else stats.unclassifiedPresentedFrameCount++;
const presentation = BigInt(frame.endTimeNs);
if (previousPresentation !== undefined && presentation > previousPresentation) {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PLUGIN_VERSION = "0.1.194";
export const PLUGIN_VERSION = "0.1.195";
5 changes: 4 additions & 1 deletion packages/skills/mobile-dev/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ the same interaction and duration. Use `summary.frameStats` from
frames and pacing percentiles alongside FPS. Show each run with
`mobile_render_performance_recording` when reporting FPS/jank, including when the
analysis uses the frame-read tool. The existing chart card includes Android jank
statistics and updates them for the selected range. Do not infer jank from average
statistics and updates them for the selected range. The live and saved FPS charts
mark each late, dropped or janky display frame once. Select a diamond for its
timestamp and SurfaceFlinger reasons, or inspect a sample for its flagged-frame
count. These events cover the whole device. Do not infer jank from average
FPS or count unknown classifications as smooth frames. If `frameStats` is null,
report that per-frame statistics were not captured.

Expand Down
Loading
Loading