Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseFrees the internal resources used by the Profiler for the thread.
Profiler allocates memory to store information about the thread. To free that memory use EndThreadProfiling. Once called, Profiler stops collecting any data on the thread. Calling the function on the main thread will produce an error.
#pragma strict var sampler: CustomSampler; function Start() { sampler = CustomSampler.Create("MyCustomSampler"); var thread: var = new Thread(MyThreadFunc); thread.Start(); } function MyThreadFunc() { Profiler.BeginThreadProfiling("My threads", "My thread 1"); // Now samples will show up in the profiler timeline view for (var i: int = 0; i < 10; i++) { sampler.Begin(); // ... sampler.End(); } // Unregister the thread before exit Profiler.EndThreadProfiling(); }
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(); } }
See Also: Profiler.BeginThreadProfiling, CustomSampler.