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.
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.
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.
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.
Click the encoder with the highest GPU time to show its counters in the assistant editor.
Check Counters for Anomalies
Move the pointer over a counter to reveal its 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.
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.