Documentation

Unity Engine

Download Unity

Unity Engine

Recorder

Records profiling data produced by a specific Sampler.
Read time 2 minutesLast updated 2 hours ago

Definition

Warning
Deprecated. Use Unity.Profiling.ProfilerRecorder instead.
public sealed class Recorder

Remarks

Recorder accumulates elapsed time of every Begin/End pair during a frame. Once enabled it sums delta time between Begin and End samples produced by a Sampler. Use Recorder.elapsedNanoseconds to get the accumulated time for the previous frame.
Deprecated: Recorder is deprecated. Use ProfilerRecorder instead. ProfilerRecorder has no finalizer and must be disposed explicitly. To migrate to a ProfilerRecorder, create a ProfilerRecorder for the marker name and read its
LastValue
. To read GPU time, create a second recorder with
ProfilerRecorderOptions.GpuRecorder
, as you would with
gpuElapsedNanoseconds
.
using Unity.Profiling;using UnityEngine;public class ExampleClass : MonoBehaviour{ ProfilerRecorder cpuRecorder; ProfilerRecorder gpuRecorder; void OnEnable() { var options = ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately; cpuRecorder = new ProfilerRecorder("MyMarker", 1, options); gpuRecorder = new ProfilerRecorder("MyMarker", 1, options | ProfilerRecorderOptions.GpuRecorder); } void OnDisable() { cpuRecorder.Dispose(); gpuRecorder.Dispose(); } void Update() { if (cpuRecorder.Valid) Debug.Log("CPU time: " + cpuRecorder.LastValue + " ns"); if (gpuRecorder.Valid) Debug.Log("GPU time: " + gpuRecorder.LastValue + " ns"); }}
using UnityEngine;using UnityEngine.Profiling;public class ExampleClass : MonoBehaviour{ Recorder behaviourUpdateRecorder; void Start() { behaviourUpdateRecorder = Recorder.Get("BehaviourUpdate"); behaviourUpdateRecorder.enabled = true; } void Update() { if (behaviourUpdateRecorder.isValid) Debug.Log("BehaviourUpdate time: " + behaviourUpdateRecorder.elapsedNanoseconds); }}
Note: A Recorder collects data regardless of the Profiler state. When a Recorder is enabled, data is accumulated every time its Sampler is hit. This information is equivalent to the one you can see in Hierarchy view in the Profiler Window.
At the moment Samplers are available only in the Editor and Development Players. Use Recorder.isValid to verify if Recorder can collect the data.
Recorder supports only internal static Profiler labels and labels generated by CustomSampler. Dynamic internal labels produced by scripting method calls and labels produced by Profiler.BeginSample are not supported.

Properties

Property

Description

elapsedNanosecondsAccumulated time of Begin/End pairs for the previous frame in nanoseconds. (Read Only)
enabledEnables recording.
gpuElapsedNanosecondsGets the accumulated GPU time, in nanoseconds, for a frame. The Recorder has a three frame delay so this gives the timings for the frame that was three frames before the one that you access this property on. (Read Only).
gpuSampleBlockCountGets the number of Begin/End time pairs that the GPU executed during a frame. The Recorder has a three frame delay so this gives the timings for the frame that was three frames before the one that you access this property on. (Read Only).
isValidReturns true if Recorder is valid and can collect data. (Read Only)
sampleBlockCountNumber of time Begin/End pairs was called during the previous frame. (Read Only)

Methods

Method

Description

CollectFromAllThreadsConfigures the recorder to collect samples from all threads.
FilterToCurrentThreadConfigures the recorder to only collect data from the current thread.

Static Methods

Method

Description

GetUse this function to get a Recorder for the specific Profiler label.