| Parameter | Description |
|---|---|
| contextUnityObject | Unity object associated with the profiling operation. |
| metadata | Additional contextual metadata string for the marker. |
Helper IDisposable struct for use with ProfilerMarker.Auto.
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.
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)) { // ... } } }