版本:Unity 6 (6000.0)
语言英语
  • C#

ProfilerUnsafeUtility.FlowEvent

建议更改

成功!

感谢您帮助我们提升 Unity 文档的质量。虽然我们无法接受所有投稿,但我们确实会阅读每条来自用户的建议,并在恰当的情况下进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请在几分钟后<a>重试</a>。感谢您花时间帮助我们提升 Unity 文档的质量。

关闭

取消

声明

public static void FlowEvent(uint flowId, Unity.Profiling.ProfilerFlowEventType flowEventType);

参数

flowId Profiler 流标识符。
flowEventType 流事件类型。

说明

将流事件添加到 Profiler 样本。

使用 Profiler 流事件来突出在不同线程上的任务执行之间的依赖关系。

流事件与 ProfilerMarker 配合使用。

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(); } } }

必须将 FlowEventProfilerMarker 一起使用。

要将样本标记为流的开头或结尾,请在 FlowEvent 中使用 ProfilerFlowEventType.BeginProfilerFlowEventType.End 事件,这些事件必须在使用 ProfilerMarker.BeginProfilerMarker.End 进行检测的范围内,或在 ProfilerMarker.Autousing 范围内。


要将样本标记为流延续点,请在 FlowEvent 中使用 ProfilerFlowEventType.NextProfilerFlowEventType.ParallelNext,然后调用 ProfilerMarker.BeginProfilerMarker.Auto

注意:Unity Job System 会自动标记作业调度、执行和等待点。

其他资源:CreateFlowCPU 使用情况 Profiler 模块