Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ProfilerMarker.AutoScope

Helper IDisposable struct for use with ProfilerMarker.Auto.
Read time 1 minuteLast updated 12 days ago

Definition

public struct ProfilerMarker.AutoScope : IDisposable

Remarks

Use ProfilerMarker.Auto to enclose a piece of code you want to profile in using statement. Constructor of AutoScope calls ProfilerMarker.Begin and Dispose method - ProfilerMarker.End.
The contextUnityObject parameter associates the profiling sample with a specific Unity object, making it easier to identify which objects contribute to performance issues in the Profiler window.
The metadata parameter attaches additional contextual information to help distinguish different execution paths or parameter values without creating separate markers.

Examples

using Unity.Profiling;using UnityEngine;public class MySystemClass : MonoBehaviour{ ProfilerMarker simulatePerfMarker = new ProfilerMarker("MySystem.Simulate"); ProfilerMarker processItemPerfMarker = new ProfilerMarker("MySystem.ProcessItem"); public void UpdateLogic() { // Basic usage using (simulatePerfMarker.Auto()) { // ... } // With object context using (simulatePerfMarker.Auto(this)) { // ... } } public void ProcessItem(string itemType) { // With metadata using (processItemPerfMarker.Auto(itemType)) { // ... } }}