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 a href=”” needsToDrawRect: /a or a href=”” getRectsBeingDrawn:count: /a 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.
NOTE
Use the Core Animation template to profile an app on a physical device. Profiling an app in the iOS Simulator will not produce true real-world results.
Do not use the Core Animation instrument to measure OpenGL ES performance.
To measure frame rate
- Connect your iOS device to your Mac.
- Launch Instruments.
- When the profiling template selection dialog appears, click Core Animation.
- Choose your iOS device and app from the target device and process lists.
- Click Choose to create a trace document.
- Click the Record button () in the toolbar or press Command-R to begin recording.
- Use your app normally.
- Click the Stop button () or press Command-R again when complete.
- 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
- Connect your iOS device to your Mac.
- Launch Instruments.
- When the profiling template selection dialog appears, click OpenGL ES Analysis.
- Choose your iOS device and app from the target device and process lists.
- Click Choose to create a trace document.
- Click the Record button () in the toolbar or press Command-R to begin recording.
- Use your app normally, exercising your OpenGL ES graphics code.
- After a few seconds of measurement, click the Stop button () or press Command-R again.
- 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.
Find Graphics-Related Bottlenecks in iOS or OS X
The GPU Driver profiling template uses the GPU Driver and Time Profiler instruments to measure app performance and provides more than just the number of frames per second your app renders.
To look for graphics-related bottlenecks
- Launch Instruments.
- When the profiling template selection dialog appears, click GPU Driver.
- Choose your device and app from the target device and process lists.
- Click Choose to create a trace document.
- Click the Record button () in the toolbar or press Command-R to begin recording.
- Use your app normally.
- Click the Stop button () or press Command-R again when complete.
- Press Command-3 to display the extended detail area of the inspector pane.
- Examine the collected data.
The individual statistics displayed by the GPU Driver instrument in the timeline pane can be enabled and disabled in the record settings area of the inspector pane.
The detail pane displays all of the gathered information for a specific sample. Select a row of data to view the sample’s statistics in the extended detail area of the inspector pane.
Bottlenecks for an OpenGL app are usually GPU or CPU bottlenecks. GPU bottlenecks occur when the GPU forces the CPU to wait for information because the GPU has too much information to process. CPU bottlenecks occur when the GPU has to wait for information from the CPU before the GPU can process it. CPU bottlenecks can often be fixed by changing the underlying logic of your app to create a better overall flow of information to the GPU. Common bottlenecks include:
- Geometry limited. If Tiler Utilization is high, examine your vertex shader processes.
- Pixel limited. If Rendered Utilization is high, examine your fragment shader processes.
- CPU limited. If Tiler Utilization and Rendered Utilization are both low, the performance bottleneck may not be in your OpenGL code. Examine your code’s overall logic.