---
title: Analyzing model runtime performance with Instruments
framework: coreai
role: article
role_heading: Article
path: coreai/analyzing-model-runtime-performance-with-instruments
---

# Analyzing model runtime performance with Instruments

Diagnose model performance by capturing a trace in Instruments.

## Overview

Overview When a Core AI model runs on your device, many events happen internally that can significantly affect performance. To get useful performance information for apps with on-device models, profile your app in Instruments. This template helps you: Profile model performance alongside the rest of your app. Identify startup delays from models that aren’t specialized for the current hardware. Compare model performance across CPU, GPU, and Neural Engine. Find unnecessary delays from repeatedly loading uncached models. Record a new trace Start with your Xcode project open and your device connected to your Mac. Next, select your app’s scheme and a run destination, then choose Product > Profile. In the Instruments template picker, select the Core AI template and click the Choose button.

Alternatively, open Instruments and choose the Core AI template. The Core AI template includes the following instruments: note: Profile on a real device for the most accurate performance data. To begin recording the trace, click the Record button at the top left of the window. In your app, perform the actions that invoke your Core AI model so the trace captures the resulting events. When you finish, click the Record button again to stop recording. note: For the most actionable results, run your app on its own. Other apps competing for CPU, GPU, or Neural Engine resources can distort the trace. Review the trace recording Now that you’ve recorded a trace, the Instruments timeline shows recorded data from each of the instruments in the Core AI template.

The Core AI instrument divides model activity into multiple tracks. The top track shows all activity. Expand it to reveal a child track for each active model, and expand a model’s track to reveal a child track for each of its active functions. note: The default function name is main. Each colored band represents an event in one of the four event categories. Each category has different latency characteristics. The categories, in the order they typically appear, are: Specialization events are often the most time-intensive operations during model runtime. Each model produces at most one Specialization event — none if the model is fully specialized for the device or already cached. You can learn more about specialization and how to optimize model performance in your app in Compiling Core AI models ahead of time and Managing model specialization and caching.

Next, brief Load events appear in the timeline. They occur only at the start of runtime, when your app first loads the model into memory. If you see frequent Load events during runtime, check that your app doesn’t reload models repeatedly.

Finally, brief Setup events appear in the timeline, and Inference events follow. A Setup event precedes each inference.

## See Also

### Runtime monitoring and analysis

- [Monitoring model performance with the debug gauge](coreai/monitoring-model-performance-with-the-debug-gauge.md)
