Profiler.BeginThreadProfiling

切换到手册
public static void BeginThreadProfiling (string threadGroupName, string threadName);

参数

threadGroupNameThe name of the thread group the thread belongs to.
threadName线程的名称。

描述

Enables profiling on the thread which calls this method.

Makes the thread show up with its registered name in the Profiler Timeline View, showing the duration of each sample on the thread. Samples which cross frame boundary are sliced and might contribute time to multiple frames.

Multiple calls of BeginThreadProfiling on the same thread have no effect. You can only set group and name once. Calling the function on the main thread will produce an error.

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

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961