Understand performance during a session
Compare .NET app activity with FPS, memory, and resource metrics to investigate slowdowns and growing resource use.
Numeric telemetry shows how performance and resource use change while you exercise your app. Record supported built-in metrics and app-defined channels, then compare those samples with the events and evidence in the session.
For application logs and timeline events, see Capturing Logs.
What Ansight Captures By Default
When you use Options.Default, Ansight starts with:
- sample frequency:
500ms - retention window:
10 minutes - FPS tracking enabled
- default memory channels for the current platform
- battery level tracking disabled
- open-file-handle tracking disabled
- Android JNI-reference-count tracking disabled
An empty Options.CreateBuilder().Build() uses the same sample frequency, retention, memory channels, and battery default, but it does not enable FPS unless you call WithFramesPerSecond() or use an all-in-one setup extension such as WithAnsightSdk(...) or UseAnsight<App>().
That gives the local host player a live and recorded memory telemetry stream without requiring any optional tool packages. Add FPS and battery channels explicitly when those graphs matter.
Minimal Setup
using Ansight;
var options = Options.CreateBuilder()
.WithFramesPerSecond()
.Build();
Runtime.InitializeAndActivate(options);
That setup gives you FPS plus the platform-default memory channels.
WithFramesPerSecond() is shown explicitly here because empty builder setup does not enable FPS by itself. The all-in-one setup extensions enable FPS for you.
Tune Sampling And Retention
Use the builder when you want a tighter or looser telemetry stream:
using Ansight;
var options = Options.CreateBuilder()
.WithSampleFrequencyMilliseconds(250)
.WithRetentionPeriodSeconds(900)
.WithFramesPerSecond()
.Build();
Runtime.InitializeAndActivate(options);
- Lower sample intervals produce a denser telemetry stream and more overhead.
- Higher retention keeps more metrics buffered for the active session.
Memory Channels
DefaultMemoryChannels is a flags enum:
ManagedHeapNativeHeapResidentSetSizePhysicalFootprintAll
Platform defaults:
- Android:
ManagedHeap | NativeHeap | ResidentSetSize - iOS and Mac Catalyst:
ManagedHeap | PhysicalFootprint - other targets:
ManagedHeap
Battery Level
Battery level telemetry is opt-in because it reads a platform battery API at the configured sample cadence.
using Ansight;
var options = Options.CreateBuilder()
.WithBatteryLevel()
.Build();
Runtime.InitializeAndActivate(options);
When supported, the SDK adds the reserved Battery Level channel and records the current charge percentage from 0 to 100.
Platform support:
- Android: reads
BatteryManagerthrough the current application context. - iOS and Mac Catalyst: enables
UIDevice.BatteryMonitoringEnabledwhile the runtime is active and restores the previous setting when deactivated. - other targets: no battery samples are emitted.
To keep all-in-one setup but add battery tracking, enable it in the setup callback:
builder.UseAnsight<App>(ansight =>
{
ansight.WithBatteryLevel();
});
Use WithoutBatteryLevel() to explicitly disable the channel when starting from shared option code.
Runtime Resource Channels
Open-file-handle and JNI-reference tracking are opt-in:
var options = Options.CreateBuilder()
.WithOpenFileHandleTracking()
.WithJniReferenceCountTracking()
.Build();
WithOpenFileHandleTracking() emits reserved channel 7 where the runtime can read the process handle count. WithJniReferenceCountTracking() emits reserved channel 6 on .NET Android using the Java.Interop tracked global-reference count; other targets do not emit JNI samples.
These channels provide trends at the normal sample frequency. On Android, use JNI Reference Diagnostics when a point-in-time investigation needs a bounded JNI-rooted object graph.
Replace The Default Memory Set
Use WithDefaultMemoryChannels(...) when you want a known, explicit memory profile:
using Ansight;
var options = Options.CreateBuilder()
.WithFramesPerSecond()
.WithDefaultMemoryChannels(DefaultMemoryChannels.All)
.Build();
Runtime.InitializeAndActivate(options);
Remove Specific Default Channels
Use WithoutDefaultMemoryChannels(...) when you want to trim the built-in platform defaults instead of replacing them outright:
using Ansight;
var options = Options.CreateBuilder()
.WithFramesPerSecond()
.WithoutDefaultMemoryChannels(DefaultMemoryChannels.NativeHeap)
.Build();
Runtime.InitializeAndActivate(options);
Custom Metrics
Register custom channels with AddAdditionalChannel(...) or WithAdditionalChannels(...), then record samples with Runtime.Metric(value, channelId).
using System.Drawing;
using Ansight;
using Ansight.Telemetry.Channels;
const byte QueueDepthChannel = 42;
var options = Options.CreateBuilder()
.AddAdditionalChannel(new Channel(
QueueDepthChannel,
"Sync queue depth",
Color.FromArgb(88, 166, 255)))
.Build();
Runtime.InitializeAndActivate(options);
Runtime.Metric(value: 17, channel: QueueDepthChannel);
Do not use reserved channel ids. The SDK reserves ids 0-7 for built-in memory, FPS, lifecycle, battery, JNI reference count, and open file handles, plus byte.MaxValue for unspecified events.
What the Local Player Does With Telemetry
The local player uses these channels to render live and recorded time-series charts for:
- FPS
- built-in memory channels
- battery level, when enabled and supported
- any additional metric channels you register
Telemetry is also available in captured sessions and can be included in downstream analysis workflows.
Recommended Defaults
For most teams:
- Start with the built-in defaults.
- Keep the sample interval at
500msunless you are diagnosing short spikes. - Extend retention only when you need longer local sessions in memory.
- Pair telemetry with Screen Views and App Lifecycle so the graphs have session context.
- Add
WithBatteryLevel()only when battery state is relevant to the session you are diagnosing.
Related Docs
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
var channel = new Ansight.Telemetry.Channels.Channel(64, "Frame", System.Drawing.Color.CornflowerBlue,
unit: "ms", group: "Render");
// Add channel through Options.CreateBuilder().WithAdditionalChannels(new[] { channel }).
Ansight.Runtime.Metric(16.67, 64);
using (var frame = Ansight.Runtime.BeginSpan("Frame", 64))
{
using var upload = Ansight.Runtime.BeginSpan("Upload", 64, frame.Id);
// Work here. Call upload.Fail() if it failed.
}
var result = await Ansight.Runtime.MeasureAsync("Fetch", () => FetchAsync(), 64);