Measuring Graphics Performance in Your iOS Device

Extensive use of graphics in your app can make your app stand out from your competitor. But unless you use graphics resources responsibly, your app will slow down and look mediocre no matter how good the images you are trying to render.

Use the three trace templates found in the iOS Graphics section to profile your app. Ensure that the frame rate is high enough and that your graphics don’t impede your app’s performance.

Measuring Core Animation Graphics Performance

Instruments uses the Core Animation instrument to measure your app’s graphical performance on iOS devices. The Core Animation trace template provides a quick and lightweight option for measuring the number of frames per second rendered by your app. This instrument is not intended to be used to measure OpenGL ES performance. You can quickly see where your app renders fewer than expected frames. By correlating what you were doing at the time the sample was taken, you can identify areas of your code that need to be improved.

Correlate your interactions with your app with the results displayed in Instruments. In Figure 9-1, you can see spikes where the frame rate of the app becomes appreciably better. Without knowing what was happening with the device during these spikes, it would be natural for you to want to duplicate these higher frame rates throughout the app. However, these spikes were caused by orientation changes when the device was changed between landscape and normal orientation. Without knowing that an orientation change by the device was performed, you might spend time trying to find what caused the performance increase and replicating it throughout your app.

Figure 9-1  Core Animation trace template showing frame rate spikes

Core Animation contains several useful debugging options in the Detail pane. You do not need to be running a trace in order to see these options working on your iOS device. Select the running process from the Target pop-up menu.

Measuring OpenGL Activity with the OpenGL ES Analysis Trace Template

The OpenGL ES Analysis template measures and analyzes OpenGL ES activity in order to detect OpenGL ES correctness and performance problems. It also offers you recommendation for addressing found problems. It consists of the OpenGL ES Analyzer and the OpenGL ES Driver instruments.

bullet
To get OpenGL ES Analyzer to make suggestions for your app
  1. Open the OpenGL ES Analysis template in the iOS group.

  2. Click the Choose Target pop-up and select your iOS device.

  3. Click the Choose Target pop-up a second time and choose the app you want to analyze.

  4. Click the Record button to begin recording data, and exercise your OpenGL graphics code.

  5. Click the Stop button when issues stop accumulating in the detail pane.

    ../Art/OpenGL ES Analizer suggestion.png

Errors are listed in the Detail pane, showing total occurrences, unique occurrences, category, summary, and (at the far left) a severity code that is either a red square for most severe, or an orange triangle for less severe. When an error is selected a recommendation is provided in the Extended Detail pane on how to fix the detected problem.

Finding Bottlenecks with the OpenGL ES Driver Trace Template

The OpenGL ES Driver trace template is also used to measure app performance and provides you with more information than just the number of frames per second that your app renders. The Extended Detail pane displays all of the gathered information for a specific sample. Each statistic can also be displayed in the track pane by configuring the OpenGL ES Driver to display that particular statistic. For detailed information about the statistic offered, see “OpenGL ES Driver Instrument” in the Instruments User Reference.

Figure 9-2  Detailed information for a Core Animation sample

Bottlenecks for an OpenGL app often come in two forms, a GPU bottleneck or a CPU bottleneck. GPU bottlenecks occur when the GPU forces the CPU to wait for information as it has to much information to process. CPU bottlenecks often occur when the GPU has to wait for information from the CPU before it 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. The following shows a list of bottlenecks and common symptoms that point to the bottleneck: