name | 用于在 Profiler 窗口中标识样本的字符串。 |
targetObject | 为样本提供上下文的对象。 |
开始使用自定义标签分析一段代码。
The Profiler displays the sample in the Hierarchy and Timeline views. The sample is nested under the events or functional calls that lead to the execution of the sampled code. For example, a sample placed in Update displays under Update.ScriptRunBehaviourUpdate
in the Profiler Hierarchy and Timeline views. If you supply a targetObject
, then you can click on the sample in the Profiler Timeline to select that object in the Editor (when profiling from the Editor Play mode).
Profiler.BeginSample 是使用 ConditionalAttribute 按条件编译的。
因此,在非开发版中部署时,它的开销为零。
using UnityEngine; using System.Collections; using UnityEngine.Profiling;
public class ExampleClass : MonoBehaviour { void Example() { Profiler.BeginSample("MyPieceOfCode"); // Code to measure... Profiler.EndSample(); } }