CustomSampler

class in UnityEngine.Profiling

/

Inherits from:Profiling.Sampler

Switch to Manual

Description

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

Use CustomSampler to measure execution time of script code blocks. Produced information is displayed in the CPU Profiler and can be captured with Recorder.
Using CustomSampler is more efficient than using Profiler.BeginSample to profile your code. This is because CustomSamplers that have been created in advance have very low Begin call overhead compared to 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

Public Functions

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

Static Functions

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

Inherited members

Variables

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

Public Functions

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

Static Functions

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