Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Profiler.BeginThreadProfiling

Suggest a change

Success!

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.

Close

Submission failed

For 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.

Close

Cancel

public static method BeginThreadProfiling(threadGroupName: string, threadName: string): void;
public static void BeginThreadProfiling(string threadGroupName, string threadName);

Parameters

threadGroupName The name of the thread group the thread belongs to.
threadName The name of the thread.

Description

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.

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

Note: Profiler.EndThreadProfiling should always be called before thread destruction to free internal resources.

See Also: Profiler.EndThreadProfiling, CustomSampler.

Did you find this page useful? Please give it a rating: