# FlowEvent(uint, ProfilerFlowEventType)

> Add flow event to a Profiler sample.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Profiling.LowLevel.Unsafe](/engine/6000.6/script-reference/unity/profiling/lowlevel/unsafe.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static void FlowEvent(uint flowId, ProfilerFlowEventType flowEventType)
```

### Parameters

**** (\[uint]\(https\://learn.microsoft.com/dotnet/api/system.uint32)): Profiler flow identifier.**** (\[ProfilerFlowEventType]\(/engine/6000.6/script-reference/unity/profiling/profilerfloweventtype)): Flow event type.

### Remarks

Use Profiler flow events to highlight the dependencies between task execution on different threads.

Flow event works in conjunction with [ProfilerMarker](/engine/6000.6/script-reference/unity/profiling/profilermarker.md).

```csharp
using System;
using System.Threading;
using Unity.Profiling;
using Unity.Profiling.LowLevel;
using Unity.Profiling.LowLevel.Unsafe;

public class Example
{
    public const int k_NumberOfTasks = 4;

    static readonly ProfilerMarker k_ScheduleParallelTasksMarker = new ProfilerMarker("Schedule Parallel Tasks");
    static readonly ProfilerMarker k_ParallelTaskMarker = new ProfilerMarker("Parallel Task");
    static readonly ProfilerMarker k_TaskSyncMarker = new ProfilerMarker("Sync Task");

    static void EmitFlowEventAndChainThread(uint flowId)
    {
        // Mark the next k_ParallelTaskMarker as a beginning of the flow
        ProfilerUnsafeUtility.FlowEvent(flowId, ProfilerFlowEventType.ParallelNext);
        using (k_ParallelTaskMarker.Auto())
        {
            // Do work
        }
    }

    static void ScheduleParallelTask()
    {
        uint flowId;
        var threads = new Thread[k_NumberOfTasks];
        using (k_ScheduleParallelTasksMarker.Auto())
        {
            flowId = ProfilerUnsafeUtility.CreateFlow(ProfilerUnsafeUtility.CategoryScripts);
            // Mark the parent k_ScheduleParallelTasksMarker as a beginning of the flow
            ProfilerUnsafeUtility.FlowEvent(flowId, ProfilerFlowEventType.Begin);
            for (var i = 0; i < k_NumberOfTasks; ++i)
            {
                var thread = new Thread(() => EmitFlowEventAndChainThread(flowId));
                thread.Start();
                threads[i] = thread;
            }
        }

        using (k_TaskSyncMarker.Auto())
        {
            // Mark the parent k_TaskSyncMarker as a beginning of the flow
            ProfilerUnsafeUtility.FlowEvent(flowId, ProfilerFlowEventType.End);
            for (var i = 0; i < k_NumberOfTasks; ++i)
                threads[i].Join();
        }
    }
}
```

You must use `FlowEvent` together with a [ProfilerMarker](/engine/6000.6/script-reference/unity/profiling/profilermarker.md).

To mark the sample as a beginning or end of a flow, use `FlowEvent` with [ProfilerFlowEventType.Begin](/engine/6000.6/script-reference/unity/profiling/profilerfloweventtype/begin.md) and [ProfilerFlowEventType.End](/engine/6000.6/script-reference/unity/profiling/profilerfloweventtype/end.md) events within a scope that is instrumented with [ProfilerMarker.Begin](/engine/6000.6/script-reference/unity/profiling/profilermarker/begin.md) and [ProfilerMarker.End](/engine/6000.6/script-reference/unity/profiling/profilermarker/end.md), or within the `using` scope of [ProfilerMarker.Auto](/engine/6000.6/script-reference/unity/profiling/profilermarker/auto.md).

To mark the sample as a flow continuation point, use `FlowEvent` with [ProfilerFlowEventType.Next](/engine/6000.6/script-reference/unity/profiling/profilerfloweventtype/next.md) and [ProfilerFlowEventType.ParallelNext](/engine/6000.6/script-reference/unity/profiling/profilerfloweventtype/parallelnext.md) before a call to [ProfilerMarker.Begin](/engine/6000.6/script-reference/unity/profiling/profilermarker/begin.md) or [ProfilerMarker.Auto](/engine/6000.6/script-reference/unity/profiling/profilermarker/auto.md).

**Note:** Unity Job System automatically marks up job scheduling, execution and wait points.

Additional Resources: [ProfilerUnsafeUtility.CreateFlow](/engine/6000.6/script-reference/unity/profiling/lowlevel/unsafe/profilerunsafeutility/createflow.md), CPU Usage Profiler module.
