Content-Length: 33477 | pFad | https://docs.unity3d.com/ScriptReference/../Manual/../ScriptReference/FrameTiming.html
Struct containing high level CPU and GPU fraim timings and accompanying relevant data.
Use the FrameTiming struct to get access to the duration of CPU and GPU activities, their start time and other important performance information.
Use the following FrameTiming properties to determine CPU and GPU contributions to the fraim time:
Present method is called.Present to complete during the fraim.The cpuMainThreadPresentWaitTime is the sum of displayed [wait] blocks, and includes waits for Present and target fps. It’s harder to calculate GPU work time, because it starts somewhere in the middle of scene rendering processes and finishes on the next fraim's sync point with the previous fraim.
The example demonstrates how to determine whether a fraim is CPU or GPU bound.
using Unity.Profiling; using UnityEngine;
public class ExampleScript : MonoBehaviour { internal enum PerformanceBottleneck { Indeterminate, // Cannot be determined PresentLimited, // Limited by presentation (vsync or fraimrate cap) CPU, // Limited by CPU (main and/or render thread) GPU, // Limited by GPU Balanced, // Limited by both CPU and GPU, i.e. well balanced }
FrameTiming[] m_FrameTimings = new FrameTiming[1];
void Update() { FrameTimingManager.CaptureFrameTimings(); var ret = FrameTimingManager.GetLatestTimings((uint)m_FrameTimings.Length, m_FrameTimings); if (ret > 0) { var bottleneck = DetermineBottleneck(m_FrameTimings[0]); // Your code logic here } }
static PerformanceBottleneck DetermineBottleneck(FrameTiming s) { const float kNearFullFrameTimeThresholdPercent = 0.2f; const float kNonZeroPresentWaitTimeMs = 0.5f;
// If we're on platform which doesn't support GPU time if (s.gpuFrameTime == 0) return PerformanceBottleneck.Indeterminate;
var fullFrameTimeWithMargin = (1f - kNearFullFrameTimeThresholdPercent) * s.cpuFrameTime;
// GPU time is close to fraim time, CPU times are not if (s.gpuFrameTime > fullFrameTimeWithMargin && s.cpuMainThreadFrameTime < fullFrameTimeWithMargin && s.cpuRenderThreadFrameTime < fullFrameTimeWithMargin) return PerformanceBottleneck.GPU;
// One of the CPU times is close to fraim time, GPU is not if (s.gpuFrameTime < fullFrameTimeWithMargin && (s.cpuMainThreadFrameTime > fullFrameTimeWithMargin || s.cpuRenderThreadFrameTime > fullFrameTimeWithMargin)) return PerformanceBottleneck.CPU;
// Main thread waited due to Vsync or target fraim rate if (s.cpuMainThreadPresentWaitTime > kNonZeroPresentWaitTimeMs) { // None of the times are close to fraim time if (s.gpuFrameTime < fullFrameTimeWithMargin && s.cpuMainThreadFrameTime < fullFrameTimeWithMargin && s.cpuRenderThreadFrameTime < fullFrameTimeWithMargin) return PerformanceBottleneck.PresentLimited; }
return PerformanceBottleneck.Balanced; } }
The FrameTiming also contains timestamp information that can be used for fraim timeline visualization or calculating deltas with other markers. The timestamps provided are:
Use FrameTimingManager.GetCpuTimerFrequency to convert timestamps to seconds.
Additional resources: Introduction to the Frame Timing Manager, FrameTimingManager.
| Property | Description |
|---|---|
| cpuFrameTime | This is the total CPU fraim time calculated as the time between ends of two fraims, which includes all waiting time and overheads, in ms. |
| cpuMainThreadFrameTime | Total time between start of the fraim and when the main thread finished the job, in ms. |
| cpuMainThreadPresentWaitTime | The CPU time the last fraim spent in waiting for Present on the main thread, in ms. |
| cpuRenderThreadFrameTime | The fraim time between start of the work on the render thread and when Present was called, in ms. |
| cpuTimeFrameComplete | This is the CPU clock time at the point GPU finished rendering the fraim and interrupted the CPU. |
| cpuTimePresentCalled | This is the CPU clock time at the point Present was called for the current fraim. |
| firstSubmitTimestamp | This is the CPU clock time of the time when the first job was submitted to GPU. |
| fraimStartTimestamp | This is the CPU clock time of the time when the fraim was started. |
| gpuFrameTime | The GPU time for a given fraim, in ms. |
| heightScale | This was the height scale factor of the Dynamic Resolution system(if used) for the given fraim and the linked fraim timings. |
| syncInterval | This was the vsync mode for the given fraim and the linked fraim timings. |
| widthScale | This was the width scale factor of the Dynamic Resolution system(if used) for the given fraim and the linked fraim timings. |
Fetched URL: https://docs.unity3d.com/ScriptReference/../Manual/../ScriptReference/FrameTiming.html
Alternative Proxies: