Recorder

class in UnityEngine.Profiling

切换到手册

描述

录制特定采样器生成的性能分析数据。

录制器会累积帧期间每个 Begin/End 对所用的时间。 启用后,它会对采样器生成的 Begin 和 End 样本之间的增量时间求和。 使用 elapsedNanoseconds 可获取前一帧的累积时间。

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); } }

注意: 无论性能分析器状态如何,录制器都会收集数据。启用录制器后,每次按采样器时都会累积数据。 这些信息等同于您在 Profiler Window 的 Hierarchy 视图中看到的信息。

目前,采样器仅在 Editor 和 Development Player 中可用。使用 Recorder.isValid 可验证录制器能否收集数据。

录制器仅支持内部静态性能分析器标签以及 CustomSampler 生成的标签。 不支持脚本方法调用生成的动态内部标签以及 Profiler.BeginSample 生成的标签。

另请参阅:SamplerRecorder.isValidRecorder.elapsedNanoseconds

变量

elapsedNanoseconds前一帧的 Begin/End 对的累积时间(以纳秒为单位)。(只读)
enabled启用录制。
isValid如果录制器有效且可收集数据,则返回 true。(只读)
sampleBlockCount在前一帧中调用 Begin/End 对的次数。(只读)

公共函数

CollectFromAllThreads将录制器配置为从所有线程收集样本。
FilterToCurrentThread将录制器配置为仅从当前线程收集数据。

静态函数

Get使用此函数可获取特定性能分析器标签的录制器。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961