Profiler.BeginThreadProfiling

Switch to Manual
public static void BeginThreadProfiling (string threadGroupName, string threadName);

Parameters

threadGroupName线程所属的线程组的名称。
threadName线程的名称。

Description

在调用此方法的线程上启用性能分析。

使线程在性能分析器时间轴视图中与其注册名称一同显示,并显示线程上每个样本的持续时间。 跨帧边界的样本会被切片并且可能为多个帧贡献时间。

Note: Calling this method on an internal Unity thread (such as main thread, render thread or job system threads) has no effect.

using UnityEngine;
using UnityEngine.Profiling;
using System.Threading;

public class ExampleClass : MonoBehaviour { CustomSampler sampler; void Start() { sampler = CustomSampler.Create("MyCustomSampler"); var thread = new Thread(MyThreadFunc) { IsBackground = true }; thread.Start(); }

void MyThreadFunc() { Profiler.BeginThreadProfiling("My threads", "My thread 1"); // Now samples will show up in the profiler timeline view for (int i = 0; i < 10; i++) { sampler.Begin(); // ... sampler.End(); }

// Unregister the thread before exit Profiler.EndThreadProfiling(); } }

注意: 应始终在线程销毁之前调用 Profiler.EndThreadProfiling 来释放内部资源。

另请参阅:Profiler.EndThreadProfilingCustomSampler