Version: 2020.2

Profiler.EndThreadProfiling

切换到手册
public static void EndThreadProfiling ();

描述

释放性能分析器用于线程的内部资源。

性能分析器分配内存以存储有关线程的信息。要释放相应内存,请使用 EndThreadProfiling。 调用后,性能分析器将停止收集线程上的任何数据。

注意: 针对 Unity 内部线程(例如主线程、渲染线程或作业系统线程)调用此方法无效。

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