Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Begin

Use for the flow start point.
Read time 1 minuteLast updated 4 days ago

Definition

Begin = 0

Remarks

The Begin flow event type marks up the profiler sample as a flow start point. The new flow identifier is generated for the Begin event. Use it to track all profiler samples which belong to the same flow. ProfilerFlowEventType.Next denotes the next point of the flow and ProfilerFlowEventType.End denotes the flow termination. Flow identifier starts from 1 and is incremented by 1 for each new Begin.
An example of a flow start point is job scheduling. For instance, IJobExtensions.Schedule generates an implicit ProfilerFlowEventType.Begin Profiler flow event and IJob.Execute generates an implicit ProfilerFlowEventType.Next event.
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(); } }}
Additional Resources: ProfilerUnsafeUtility.FlowEvent.