Understand performance during a session

Compare iOS frame rate, memory, and custom metrics with session activity when investigating slowdowns or resource growth.

Telemetry adds performance context to what happened in your app. Record numeric samples over time to see how frame rate, memory, and your own metrics change around actions or errors in a session.

For app logs and timeline events, see Capturing Logs.

Built-In Channels

The iOS runtime can record:

  • managed heap where available
  • physical footprint through native process memory APIs
  • FPS through CADisplayLink
  • battery level when enabled
  • process open-file-handle count when enabled
  • custom channels registered by the app

The aggregate developer setup enables FPS and the default memory channels. Battery remains opt-in.

Minimal Setup

let options = try AnsightOptions.createBuilder()
    .withFramesPerSecond()
    .build()

try AnsightRuntime.shared.initializeAndActivate(options: options)

Tune Sampling And Retention

let options = try AnsightOptions.createBuilder()
    .withSampleFrequencyMilliseconds(250)
    .withRetentionPeriodSeconds(900)
    .withFramesPerSecond()
    .build()

Lower sample intervals produce denser graphs and more overhead.

Battery Level

let options = try AnsightOptions.createBuilder()
    .withBatteryLevel()
    .build()

The SDK enables battery monitoring while active and restores the previous system setting when deactivated.

Custom Metrics

try AnsightRuntime.shared.registerMetricChannel(
    AnsightChannel(
        id: 42,
        name: "Queue Depth",
        color: "#FF9500",
        unit: "items",
        type: "queue"
    )
)

try AnsightRuntime.shared.metric(17, channel: 42)

For sampled values, register a metric stream:

try AnsightRuntime.shared.registerMetricStream(
    AnsightMetricStream(
        channel: AnsightChannel(id: 43, name: "Cache Items", unit: "items", type: "cache")
    ) {
        Int64(cache.itemCount)
    }
)

Do not use reserved channel ids. The cross-platform SDK reserves ids 0-7 for built-in memory, FPS, lifecycle, battery, JNI reference count, and open file handles, plus 255 for the unspecified channel. JNI reference sampling is Android-only; id 6 remains reserved on iOS for a stable cross-platform contract.

Open File Handles

Open-file-handle tracking is off by default. Enable channel 7 when the session needs a process-level resource trend:

let options = try AnsightOptions.createBuilder()
    .withOpenFileHandleTracking()
    .build()

Use File Descriptor Diagnostics when a point-in-time investigation needs individual descriptors, paths, or limit utilization rather than only the sampled count.

Runtime Sampling

Capture a built-in telemetry sample manually when you need a point-in-time reading before the next scheduled sample:

AnsightRuntime.shared.captureBuiltInTelemetrySample()

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.

IDsOwner / meaning
0Managed/Java heap, depending on the SDK
1Native heap on Android; physical footprint on Apple
2Android RSS; reserved on every stack
3Frames per second
4App lifecycle
5Battery level
6JNI reference diagnostics
7Open file handles
32–33React Native JavaScript heap used/total; avoid for app channels
40–43Flutter build/raster/total frame duration and frame count; avoid for app channels
255Unspecified 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

try AnsightRuntime.shared.registerMetricChannel(AnsightChannel(id: 64, name: "Frame", unit: "ms", group: "Render"))
try AnsightRuntime.shared.metric(16.67, channel: 64)
try AnsightRuntime.shared.measure("Frame", channel: 64) { frame in
    let upload = try AnsightRuntime.shared.beginSpan("Upload", channel: 64, parentSpanId: frame.id)
    defer { try? upload.end() }
    // Work here. Call try upload.end(status: "error") if it failed.
}
// measure also accepts an async throwing closure. AnsightMetricStream.floating
// accepts a sampler returning Double?; existing integer samplers remain supported.