CustomSampler

UnityEngine.Profiling 中的类

/

继承自:Profiling.Sampler

/

实现于:UnityEngine.CoreModule

描述

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

使用 CustomSampler 来测量脚本代码块的执行时间。生成的資訊将在 CPU 分析器 中显示,并可以使用 Recorder 进行捕获。
与使用 Profiler.BeginSample 分析代码相比,使用 CustomSampler 更有效率。这是因为预先创建的 CustomSampler 具有非常低的 Begin 调用开销,而 Profiler.BeginSample 则没有。

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如果 Sampler 有效,则返回 true。(只读)
nameSampler 名称。(只读)

公共方法

GetRecorder返回与 Sampler 关联的 Recorder。

静态方法

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

Did you find this page useful? Please give it a rating: