Using Xcode Instruments
Last modified on Mon 17 Oct 2022

Just like with everything else, tools won't give you good results unless you know how, when, and why to apply them. If you go out and you buy the most expensive frying pan on the market it's still not going to make you a good chef. - Christin Wiedemann

The Instruments app in Xcode provides a rich set of tools and templates for profiling your app performance that can help you debug and overcome performance issues, like bad CPU usage, poor implementation of battery resources, unnecessary memory consumption, etc.

If you are testing with the Instruments app and notice that the battery is draining fast, too much CPU is being used, etc., take a screenshot of the profiler and attach it to your task because this will help developers to find the issue much faster.

Although it's embedded within and may be used with Xcode, Instruments is a separate app, which may be used independently as needed.

To install Xcode, go to App Store and install it from there.

To start using Instruments and profile the app, an iOS developer will need to install a debug build on your device (preferable). There is another option with using any build which doesn't require a developer but has a constraint which is hidden names for all collected data.

The other option is good if you only need to check overall app performance without digging deep into the data.

How to setup everything is explained below on example of non-debug build.

Steps:

  1. Connect an iPhone with Macbook and open the app you want to profile (this is important because it won't work if the app is closed).

  2. In Xcode, choose Xcode > Open Developer Tool > Instruments.

  3. In the profiling template selection dialog that appears, select a target device and find your app in the Running Applications list.

  4. Select a desired profiling template.

  5. Click Choose.

  6. Click the Record button in the toolbar (or press Command-R) to begin recording.

  7. Use your app or the system normally.

  8. Click the Stop button, or press Command-R again, when complete.

A trace document is used to organize and configure instruments for profiling, initiate data collection, and view and analyze the results.

The trace document includes the following main areas:

In the Instruments documentation you can find additional options this tool can give you like tracking CPU core and thread use, find performance bottlenecks and memory leaks, etc. You can even find zombies, I kid you not.