Understand performance during a session
Investigate Flutter rendering performance and resource use with frame timings, supported native metrics, and your own app measurements.
Frame timings help you see whether Flutter spends time building or rasterizing frames. Compare these measurements and supported resource metrics with the surrounding session activity when investigating performance.
The native runtime samples supported iOS and Android memory, FPS, and battery
channels. Flutter instrumentation adds the following channels on every
supported Flutter target. On macOS, native FPS samples are derived from Flutter
frame timings and retained on channel 3.
| Channel | Id | Unit |
|---|---|---|
| Flutter frame build | 40 | ms |
| Flutter frame raster | 41 | ms |
| Flutter frame total | 42 | ms |
| Flutter frame count | 43 | count |
Register app metrics as needed:
await Ansight.instance.registerMetricChannel(
const AnsightChannel(id: 50, name: 'Queue depth', unit: 'items'),
);
await Ansight.instance.metric(42, channel: 50);
Native runtime resource channels are opt-in:
final options = createOptionsBuilder()
.withOpenFileHandleTracking()
.withJniReferenceCountTracking()
.build();
Open file handles use reserved channel 7 on supported native targets. JNI references use reserved channel 6 on Android only. Native ids 0-7 and 255 are reserved, and Flutter instrumentation uses 40-43; choose a different id for app channels.
Set captureFrames: false when installing Flutter instrumentation if frame timing is unnecessary. Use enableFramesPerSecond(), disableFramesPerSecond(), and captureBuiltInTelemetrySample() for native sampling control.
Numeric values, units, and channel IDs
Metrics accept finite numbers, including fractions such as 16.67 and 0.125.
They are preserved through native bridges, live sessions, offline archives, and
replay. NaN and infinity are rejected. Values use double precision; integers
above 2^53 are not guaranteed to remain exact. Existing integer calls continue to work.
Declare unit on the channel (for example ms, bytes, %, or count). group
organizes related channels, while type, source, and kind describe their
meaning. The player offers separate metric lanes with compatible units, and
separate event/span lanes by channel. Units are metadata; callers must send values
in the declared unit.
Use 64–254 for portable application channels. This is the recommended range, not a requirement to renumber existing custom channels.
| IDs | Owner / meaning |
|---|---|
| 0 | Managed/Java heap, depending on the SDK |
| 1 | Native heap on Android; physical footprint on Apple |
| 2 | Android RSS; reserved on every stack |
| 3 | Frames per second |
| 4 | App lifecycle |
| 5 | Battery level |
| 6 | JNI reference diagnostics |
| 7 | Open file handles |
| 32–33 | React Native JavaScript heap used/total; avoid for app channels |
| 40–43 | Flutter build/raster/total frame duration and frame count; avoid for app channels |
| 255 | Unspecified channel; valid for recording events, not custom registration |
Core registration rejects 0–7 and 255. Framework collectors own their IDs when installed. Register a channel before recording metrics against it; existing unknown-channel behavior is unchanged.
Timed spans (zones)
A span names an operation and records its start and finish. A zone is the same
concept; there is one span API and one recording contract. Each span has a stable
ID, an optional explicit parent ID, a channel, a UTC start time, a monotonic
elapsed duration in milliseconds, and an outcome (ok, error, or cancelled).
Explicit parents work across threads and asynchronous operations. End is
idempotent. A start without an end remains incomplete in replay; shutdown,
crashes, or retention must not manufacture a successful ending. Scope disposal
means success unless the caller explicitly marks failure; use the measured
operation helpers to record thrown errors automatically.
Spans use the existing application event stream, with event type Span and JSON
in details: spanId, parentSpanId, phase (start/end), startedAtUtc,
durationMs (end only), and status (end only). End records repeat their start
metadata so cropped or reordered recordings can still reconstruct a completed
span. This adds fields/event data to the existing format; it introduces no
second session schema or version negotiation.
The host’s telemetry timeline query includes matchedSpanCount, spans, and
spansTruncated (at most 500 returned spans). Channel/time filters apply; span
ranges overlap the query interval. Event records remain available independently.
Example
await ansight.registerMetricChannel(const AnsightChannel(id: 64, name: 'Frame', unit: 'ms', group: 'Render'));
await ansight.metric(16.67, channel: 64);
await ansight.measure('Frame', (frame) async {
final upload = await ansight.beginSpan('Upload', channel: 64, parentSpanId: frame.id);
try { await uploadWork(); }
catch (_) { await upload.end(status: 'error'); rethrow; }
finally { await upload.end(); }
}, channel: 64);