CustomSampler

class in UnityEngine.Profiling

/

继承自:Profiling.Sampler

切换到手册

描述

用于分析任意代码块的自定义 CPU 性能分析器标签。

使用 CustomSampler 测量脚本代码块的执行时间。生成的信息将显示在 CPU 性能分析器中,并且可以通过 Recorder 捕获。\ 使用 CustomSampler 来分析代码比使用 Profiler.BeginSample 更高效。这是因为与 Profiler.BeginSample 相比,预先创建的 CustomSamplers 具有非常低的 Begin 调用开销。

using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour { CustomSampler sampler; void Start() { sampler = CustomSampler.Create("MyCustomSampler"); }

void Update() { sampler.Begin(); // do something that takes a lot of time sampler.End(); } }

CustomSampler.Begin 是使用 ConditionalAttribute 按条件编译的。 因此,在非开发版中部署时,它的开销为零。

另请参阅:SamplerCustomSampler.CreateCustomSampler.Begin

公共函数

Begin开始使用由 CustomSampler 的此实例定义的自定义标签分析一段代码。
End使用自定义标签结束对一段代码的分析。

静态函数

Create创建一个用于分析代码的各个部分的新 CustomSampler。

继承的成员

变量

isValid如果采样器有效,则返回 true。(只读)
name采样器名称。(只读)

公共函数

GetRecorder返回与采样器关联的 Recorder。

静态函数

Get返回特定 CPU 性能分析器标签的 Sampler 对象。
GetNames返回所有已注册性能分析器标签的数量和名称。