Guides and Sample Code

Developer

Instruments User Guide

On This Page

Measure Graphics Performance

Extensive use of graphics in your iOS app can make your app stand out from your competitors. But unless you use graphics resources responsibly, your app will slow down, reduce battery life, and look mediocre no matter how good the content you are trying to render. For optimal graphic performance:

  • Ensure that the frame rate of animations is sufficient for providing a fluid visual experience without negatively impacting app performance.

  • Reduce the number of views your app uses.

  • Reduce the use of opacity, such as in views that exhibit a translucent blur. If you need to use opacity, avoid using it over views that are updated frequently. Otherwise, energy cost is magnified, as both the background view and the translucent view must be updated whenever content changes.

  • Draw to smaller portions of the screen—only the portions that are changing. To do this, use needsToDrawRect: or getRectsBeingDrawn:count: to identify the specific area to update, and pass the result to drawRect:.

  • Eliminate drawing when your app or its content is not visible; for example, when your app is in the background, or when its content is obscured by other views, clipped, or offscreen.

  • Eliminate drawing during window resizing.

Measure Core Animation Graphics Performance in iOS

The Core Animation profiling template uses the Core Animation and Time Profiler instruments to measure your iOS app’s graphics and CPU performance. This template provides a quick and lightweight starting point for measuring the number of frames per second rendered by your app. It allows you to quickly see where your app renders fewer frames than expected. By correlating what you were doing at the time the sample was taken, you can identify areas of your code that need to be optimized.

To measure frame rate
  1. Connect your iOS device to your Mac.

  2. Launch Instruments.

  3. In the profiling template selection dialog that appears, click Core Animation.

  4. Choose your iOS device and app from the target device and process lists.

  5. Click Choose to create a trace document.

  6. Click the Record button (image: ../Art/inline_record_button_2x.png) in the toolbar (or press Command-R) to begin recording.

  7. Use your app normally.

  8. Click the Stop button (image: ../Art/inline_stop_button_2x.png), or press Command-R again, when complete.

  9. Examine the collected data.

    The detail pane shows the frame rate for each recorded sample.

Correlate Interactions with Results

After capturing data with the Core Animation instrument, you may see spikes in the timeline pane where the frame rate of the app becomes appreciably better. In some cases, however, spikes can be caused by changing the device between landscape and normal orientation—and if you don’t know this, you might spend time trying to find what caused the performance increase. One way to correlate interactions with results is to insert flags into the timeline when you performed certain events. See Set Flags.

Debugging Options

Core Animation contains a number of useful debugging options in the display settings area of the inspector pane. You do not need to be running a trace to use these options on your iOS device.

  • Color Blended Layers. Shows blended view layers. Multiple view layers that are drawn on top of each other with blending enabled are highlighted in red. Reducing the amount of red in your app when this option is selected can dramatically improve your app’s performance. Blended view layers often cause slow table scrolling.

  • Color Hits Green and Misses Red. Marks views in green or red. A view that is able to use a cached rasterization is marked in green.

  • Color Copied Images. Shows images that are copied by Core Animation in blue.

  • Color Immediately. Removes the 10 ms delay when performing color-flush operations.

  • Color Misaligned Images. Places a magenta overlay over images where the source pixels are not aligned to the destination pixels.

  • Color Offscreen-Rendered Yellow. Places a yellow overlay over content that is rendered offscreen.

  • Color OpenGL Fast Path Blue. Places a blue overlay over content that is detached from the compositor.

  • Flash Updated Regions. Colors regions on your iOS device in yellow when those regions are updated by the graphics processor.

Measure OpenGL Activity in iOS

The OpenGL ES Analysis profiling template uses the OpenGL ES Analyzer and GPU Driver instruments to measure and analyze OpenGL ES activity in your iOS app in order to detect correctness and performance problems. It also recommends how to address found problems.

To measure OpenGL Activity
  1. Connect your iOS device to your Mac.

  2. Launch Instruments.

  3. In the profiling template selection dialog that appears, click OpenGL ES Analysis.

  4. Choose your iOS device and app from the target device and process lists.

  5. Click Choose to create a trace document.

  6. Click the Record button (image: ../Art/inline_record_button_2x.png) in the toolbar (or press Command-R) to begin recording.

  7. Use your app normally, exercising your OpenGL ES graphics code.

  8. After a few seconds of measurement, click the Stop button (image: ../Art/inline_stop_button_2x.png), or press Command-R again.

  9. Examine the collected data.

Errors are listed in the detail pane sorted by their severity. Red squares indicate the most severe problems, and orange triangles indicate less severe problems. A recommendation and the stack trace are displayed in the extended detail area of the inspector pane for the issue selected in the detail pane.