用于流程起点。
Begin 流事件类型将分析器样本标记为流程起点。Begin 事件将生成新的流程标识符。使用它来跟踪属于同一流程的所有分析器样本。 Next 表示流程的下一个点,End 表示流程的终止。流程标识符从 1 开始,对于每个新的 Begin 增加 1。
流程起点的示例是作业调度。例如,IJobExtensions.Schedule 生成一个隐式 Begin 分析器流程事件,而 IJob.Execute 生成一个隐式 Next 事件。
using System; using System.Threading; using Unity.Profiling; using Unity.Profiling.LowLevel; using Unity.Profiling.LowLevel.Unsafe;
public class Example { static readonly ProfilerMarker k_ScheduleTasksMarker = new ProfilerMarker("Schedule Task"); static readonly ProfilerMarker k_TaskMarker = new ProfilerMarker("Task");
static void EmitFlowEventAndChainThread(uint flowId) { // Mark the next k_TaskMarker as a beginning of the flow ProfilerUnsafeUtility.FlowEvent(flowId, ProfilerFlowEventType.Next); using (k_TaskMarker.Auto()) { // Do work } }
static void ScheduleTask() { using (k_ScheduleTasksMarker.Auto()) { var flowId = ProfilerUnsafeUtility.CreateFlow(ProfilerUnsafeUtility.CategoryScripts); // Mark the parent k_ScheduleTasksMarker as a beginning of the flow ProfilerUnsafeUtility.FlowEvent(flowId, ProfilerFlowEventType.Begin); var thread = new Thread(() => EmitFlowEventAndChainThread(flowId)); thread.Start(); } } }