I am trying measuring performance in my app, I used two difference ways to measure commandBuffer completion time. One way is using MTLCommandBuffer addCompletedHandler:
commandBuffer.addCompletedHandler { cb in let executionDuration = cb.gpuEndTime - cb.gpuStartTime /* ... */ }
The other way is to use MTLCaptureManager. And I found two interesting things: First, the completion time from addCompletedHandler was 26.82ms, on the other hand, GPU time from the capture manager was 13.49ms. I have been trying to understand why these two number are way different, but couldn't fine any concrete answer.
Second, the GPU time is different from shader times shown in timeline in Performances. Here is screenshot.
According to the timeline, it took 17.57ms. There is inconsistency. I did same test multiple times, and sometimes process time on timeline is less than GPU time, or vise versa.
Within this command buffer, there are 56 dispatches. Is this because there are too many dispatches?
I tested this on iPhone 12 Max with iOS 15.2.1
If there is someone who can give me clear explanation, it would be really appreciated.