用于分析任意代码块的自定义 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 按条件编译的。
因此,在非开发版中部署时,它的开销为零。
另请参阅:Sampler、CustomSampler.Create、CustomSampler.Begin。
Create | 创建一个用于分析代码的各个部分的新 CustomSampler。 |
GetRecorder | 返回与采样器关联的 Recorder。 |