Optimizing Performance with GPU Counters

Examine granular metrics for your rendering or compute calls, and tune your app as needed.


GPU counters are granular statistics that relate to the specific render, compute, or blit work your app did in the captured frame. To find coding problems or tune your performance, check the counters for hot spots and make adjustments to your app as needed.

Counters contain a wide range of statistics that can show you a wide range of issues. The problems you find are unique to the performance characteristics of your app at the time you captured the frame, but the process to diagnose the cause is the same.

Capture a Frame with the Metal Frame Debugger

GPU counters work with Xcode's Metal frame capture. Build and run your project, then click the camera button on Xcode's debugging toolbar.

For more information about frame capture, see Frame Capture Debugging Tools.

Check the Duration of GPU Activity Within the Frame

When the capture completes, Xcode displays the results in the Debug navigator. To understand whether the captured frame exhibits a performance issue worthy of investigation, first check how long the GPU was active during the frame. To do that, click FPS.

Screenshot of the FPS button in the Debug navigator marked by a callout.

The GPU gauge displays in Xcode's center pane. The amount of time that the GPU was active within the duration of the captured frame is marked in the following image.

Screenshot of the frame time statistics of the GPU guage pane.

If the GPU frame time is low, it indicates that your captured frame doesn't reflect a performance issue with respect to the GPU's work. That can mean that your app's GPU workload doesn't impair performance, or that you need to capture a frame at a different point in your app to test performance.

Even if your app is achieving the desired frames per second (FPS), it's still a good idea to use GPU counters to minimize your GPU frame time, because doing so increases your app's GPU workload capacity.

View the GPU Counters Graph

To begin performance tuning, view the performance of your app's encoders using the GPU counter graph. Click GPU in the Debug navigator to display the GPU counter graph in Xcode's center pane.

Screenshot of the GPU guage in the Debug navigator.

Screenshot of the GPU Counters Graph showing the relative performance of an app's twelve encoders.

This pane shows all of your app's encoders that did work during the frame. The height of the bar represents the encoder's relative amount of the frame's GPU time. The highest bar identifies the encoder that took the longest to complete.

Find an Encoder with High GPU Time

Minimize the duration of the longest-running encoder in the captured frame to optimize your app's performance. To find the longest running encoder, hold the pointer over an encoder bar to view its GPU Time.

Screeshot of an encoder in the counter graph with a tooltip displaying its GPU time.

Click the encoder with the highest GPU time to show its counters in the assistant editor.

Screenshot of the selected encoder's GPU counters listed in a table.

Check Counters for Anomalies

Move the pointer over a counter to reveal its description.

Screenshot of the mouse hovering over a specific counter. A tooltip is displayed that contains that counters description.

By analyzing values that may be hotspots in your frame, counters may suggest a specific cause of your performance problem. For example, if your vertices count is twice as high as you expect, it suggests that either your meshes or draw calls are duplicated somewhere in your code.

Use Other Metal Tools

Sometimes, counter data may only hint at a problem, and you can benefit by leveraging additional Metal tools. For example, suppose your fragment shader time is unexpectedly high.

Screenshot of the Fragment Shader Time counter selected with its tooltip shown, reading: "Percentage of time spent in the fragment shader, relative to the total GPU time."

Use the shader profiler to discover which specific lines in your fragment shader are slow. For more information, see Optimizing Performance with the Shader Profiler.

See Also

Optimizing Your App

Optimizing Performance with the Shader Profiler

Discover which lines of shader code take the longest to complete, identify their primary GPU activities, and tune your shaders accordingly.

Optimizing Performance with Pipeline Statistics

Decide how to tune your encoder performance by identifying your app's longest-running encoders and their primary GPU activity.

Improving Memory and Resource Usage

Analyze and tune your app's Metal memory footprint using Memory Viewer.