ProfilerMarker
Performance marker used for profiling arbitrary code blocks.
Read time 2 minutesLast updated 4 days ago
Definition
- Type: Struct
- Namespace: Unity.Profiling
- Assembly: UnityEngine.CoreModule
public struct ProfilerMarker
Remarks
Use ProfilerMarker to mark up script code blocks for the Profiler.
The information produced by markers is displayed in the CPU Profiler and can be also captured with Recorder. During development (in Editor and Development Players) this can help to get performance overview of different parts of game code and identify performance issues.
using Unity.Profiling;public class MySystemClass{ static readonly ProfilerMarker s_PreparePerfMarker = new ProfilerMarker("MySystem.Prepare"); static readonly ProfilerMarker s_SimulatePerfMarker = new ProfilerMarker(ProfilerCategory.Ai, "MySystem.Simulate"); public void UpdateLogic() { s_PreparePerfMarker.Begin(); // ... s_PreparePerfMarker.End(); using (s_SimulatePerfMarker.Auto()) { // ... } }}
ProfilerMarker represents a named profiler handle and is the most efficient way of profiling your code. It can be used in jobified code.
Methods ProfilerMarker.Begin and ProfilerMarker.End are marked with ConditionalAttribute. They are conditionally compiled away and thus have zero overhead in non-Development (Release) builds.
When Profiler collects instrumentation data, ProfilerMarker helps to reduce overhead and the amount of transferred data. Profiler.BeginSample transfers full string to the data stream while ProfilerMarker.Begin and CustomSampler.Begin only integer identifier of the marker.
Also ProfilerMarker.End provides a context information to the Recorder making it possible to track timings of a marked code in Players.
Additional Resources: Recorder.
Constructors
Constructor | Description |
|---|---|
| ProfilerMarker(System.Char*,System.Int32) | Constructs a new performance marker for code instrumentation. |
| ProfilerMarker(System.String) | Constructs a new performance marker for code instrumentation. |
| ProfilerMarker(Unity.Profiling.ProfilerCategory,System.Char*,System.Int32) | Constructs a new performance marker for code instrumentation. |
| ProfilerMarker(Unity.Profiling.ProfilerCategory,System.Char*,System.Int32,Unity.Profiling.LowLevel.MarkerFlags) | Constructs a new performance marker for code instrumentation. |
| ProfilerMarker(Unity.Profiling.ProfilerCategory,System.String) | Constructs a new performance marker for code instrumentation. |
| ProfilerMarker(Unity.Profiling.ProfilerCategory,System.String,Unity.Profiling.LowLevel.MarkerFlags) | Constructs a new performance marker for code instrumentation. |
Properties
Property | Description |
|---|---|
| Handle | Gets native handle of the ProfilerMarker. |
Methods
Method | Description |
|---|---|
| Auto | Creates a helper struct for the scoped using blocks. |
| Begin | Begin profiling a piece of code marked with a custom name defined by this instance of ProfilerMarker. |
| End | End profiling a piece of code marked with a custom name defined by this instance of ProfilerMarker. |
Structs
Struct | Description |
|---|---|
| ProfilerMarker.AutoScope | Helper IDisposable struct for use with ProfilerMarker.Auto. |