MetricKit

On this page 7

MetricKit is the Apple framework that collects performance metrics and diagnostic reports on real users’ devices and delivers them to the app itself as aggregated payloads. In mobile performance work on iOS, iPadOS and macOS, it is the first-party source of field data on launch time, hangs, battery use, memory, disk writes and crashes, gathered by the operating system rather than by custom instrumentation.

Apple introduced MetricKit in iOS 13 and expanded it substantially in iOS 14 with diagnostic payloads. Because the system measures the app from the outside, the data covers events that in-app code cannot see on its own, such as watchdog terminations, memory-pressure exits and the energy cost of background work.

How MetricKit collects and delivers data

MetricKit works on a subscriber model. The app registers an object conforming to MXMetricManagerSubscriber with the shared MXMetricManager, and the system calls that subscriber when new payloads are ready. Registration usually happens early at launch so that no delivery is missed.

The operating system records measurements continuously, aggregates them on the device and hands them over in two payload types. The table summarizes how they differ.

PayloadContentDelivery timing
MXMetricPayloadAggregated metrics and histograms for a reporting windowAt most once per day, covering about 24 hours
MXDiagnosticPayloadCrash, hang, CPU and disk-write exception reports with call stacksDaily on iOS 14, immediately on iOS 15 and later
MetricKit payload types

Each payload exposes a jsonRepresentation() method, so teams typically upload the raw JSON to their own backend and analyze it there. Data comes only from devices whose owners agreed to share analytics with app developers, which means the sample is real but not complete.

Metric categories and what they reveal

MetricKit groups measurements into typed metric classes, each describing one aspect of performance or energy use. Many values arrive as histograms rather than averages, which lets engineers see the slow tail that a mean would hide.

Metric classKey valuesTypical question answered
MXAppLaunchMetricTime to first draw, resume timeIs cold start getting slower after a release
MXAppResponsivenessMetricHang time histogramHow often is the main thread blocked
MXAnimationMetricScroll hitch time ratioIs scrolling visibly janky
MXCPUMetric and MXGPUMetricCumulative CPU and GPU timeWhat drives battery drain
MXMemoryMetricPeak memory, average suspended memoryWhy is the app killed in the background
MXDiskIOMetricCumulative logical writesDoes the app wear storage excessively
MXAppExitMetricCounts of normal and abnormal exits by reasonHow many silent terminations occur
Selected MetricKit metric classes

Developers can add custom measurements with mxSignpost, which records intervals around specific operations such as loading a feed. These appear as MXSignpostMetric entries in the daily payload alongside the system metrics.

Diagnostics for crashes, hangs and exceptions

Diagnostic payloads explain why a problem happened, not only how often. Each diagnostic carries metadata such as the app version, device type and operating system build, together with a call stack tree that shows where the main thread or the crashing thread was at the time.

  • Crash diagnostics include the exception type, signal and termination reason.
  • Hang diagnostics record main-thread stalls together with their duration.
  • CPU exception diagnostics flag code that exceeded the system’s CPU usage limits.
  • Disk write exception diagnostics report code that wrote more data than allowed in a period.

Call stacks arrive unsymbolicated, as binary images and offsets. Teams must match them against the dSYM files of each build to obtain readable function names, which is the most common integration hurdle.

Diagnostics are especially valuable for terminations that bypass signal handlers, such as a watchdog kill during a slow launch or a memory-limit exit in the background. In-process crash reporters often miss these events entirely, so MetricKit is frequently the only reliable record of them. Since iOS 15, immediate delivery also lets teams detect a crash spike within hours of a release instead of waiting for the next daily report.

MetricKit compared with other performance tools

MetricKit is one source among several, and it complements rather than replaces lab profiling and third-party crash reporting. The comparison clarifies where it fits.

ToolData sourceMain strength
MetricKitOperating system on user devicesSystem-level field data, including watchdog exits
Xcode OrganizerAggregated MetricKit-style data in XcodeNo code needed, cohort trends by version
Xcode InstrumentsLocal profiling sessionsDeep traces for reproducing a problem
Crash analytics SDKsIn-process signal handlersReal-time alerts and rich custom context
Android vitalsGoogle Play aggregated device dataEquivalent field metrics on Android
MetricKit and related tools

A practical split is to use Instruments to diagnose a problem in the lab, MetricKit and the Organizer to measure its real-world impact, and a crash reporting SDK when the team needs immediate alerting rather than daily batches.

Limitations and integration mistakes

MetricKit is delayed, sampled and aggregated by design, which protects privacy and battery life but limits how it can be used. The table lists frequent problems.

SymptomCauseRemedy
No payloads arriveSubscriber registered too late or releasedRegister at launch and keep a strong reference
Unreadable stack tracesMissing symbolicationArchive dSYM files for every build
Small sample sizeFew users share analyticsTreat trends as indicative, not exact
Cannot test locallyPayloads appear only after a dayUse the Xcode option to simulate payloads
Common MetricKit pitfalls

Because payloads lack per-user identifiers, MetricKit cannot trace a single session end to end. Teams that need that level of detail combine it with their own logging, while keeping MetricKit as the authoritative view of system-measured behavior.

Explained without jargon

MetricKit is like a daily health report that the iPhone writes about an app. The phone quietly notes how long the app takes to open, how often it freezes, how much battery it uses and whether it crashed.

Once a day, the phone hands this summary to the app, which can send it to its developers. Only people who agreed to share data take part. The developers then see how the app really behaves in everyday use, not just on their own test phones.

A typical use case

A team building a grocery delivery app notices rising complaints about freezes after a release, yet nothing reproduces on test devices. They already upload MetricKit payloads to their analytics backend, so they compare the hang time histograms of the old and new versions.

The data shows that the share of sessions with hangs longer than 250 milliseconds has roughly tripled on older iPhones. Hang diagnostics point to the same call stack in most reports: a synchronous database migration that runs on the main thread when the cart screen opens.

Engineers move the migration to a background queue and add an mxSignpost interval around cart loading. Over the next two weeks of daily payloads, the hang rate returns to its earlier level and cart load time drops by about 40 percent, confirming the fix with field data rather than assumptions.