I’m currently working on calculating frame timings in a Unity project for Android, and I need to accurately measure raw CPU and GPU times per frame while excluding the additional time introduced by VSync. I’ve been using FrameTimingManager
to capture these timings, but I’ve noticed that the GPU times it returns include the delay due to VSync.
To check the frame timings I’ve added frame numbers to the profile markers, to check the profiler frame data to the one captured by the FrameTimingManager but even that doesn’t match up properly and therefore cant be inspected properly.
Profiler Data (5.8 MB)
Any way to get the breakdown of how to get these timings individually.
Code for calculating the cpu and gpu times:-
FrameTiming[] frameTimings = new FrameTiming[5];
private void Update()
{
Profiler.BeginSample("Frame_" + Time.frameCount);
FrameTimingManager.CaptureFrameTimings();
uint numTimings = FrameTimingManager.GetLatestTimings((uint)frameTimings.Length, frameTimings);
if (numTimings > 0)
{
Debug.Log($"Time.frameCount: {Time.frameCount}, CPU0: {frameTimings[0].cpuFrameTime:F2} ms, (CPU1) {frameTimings[1].cpuFrameTime:F2} ms, (CPU2) {frameTimings[2].cpuFrameTime:F2} ms, CPU (by unscaled): {Time.unscaledDeltaTime * 1000:F2} ms, GPU:{frameTimings[0].gpuFrameTime:F2} ms");
}
Profiler.EndSample();
}
Frame timings captured from code above
Timing data for frame 2418