# ProfilerMarker

> Performance marker used for profiling arbitrary code blocks.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Profiling](/engine/6000.3/script-reference/unity/profiling.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
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](/engine/6000.3/script-reference/unityengine/profiling/recorder.md). During development (in Editor and Development Players) this can help to get performance overview of different parts of game code and identify performance issues.

```csharp
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](/engine/6000.3/script-reference/unity/profiling/profilermarker/begin.md) and [ProfilerMarker.End](/engine/6000.3/script-reference/unity/profiling/profilermarker/end.md) 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](/engine/6000.3/script-reference/unityengine/profiling/profiler/beginsample.md) transfers full string to the data stream while [ProfilerMarker.Begin](/engine/6000.3/script-reference/unity/profiling/profilermarker/begin.md) and [CustomSampler.Begin](/engine/6000.3/script-reference/unityengine/profiling/customsampler/begin.md) only integer identifier of the marker.

Also [ProfilerMarker.End](/engine/6000.3/script-reference/unity/profiling/profilermarker/end.md) provides a context information to the [Recorder](/engine/6000.3/script-reference/unityengine/profiling/recorder.md) making it possible to track timings of a marked code in Players.

Additional Resources: [Recorder](/engine/6000.3/script-reference/unityengine/profiling/recorder.md).

## Constructors

| Constructor                                                                                                                                                                                                                                         | Description                                                   |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| [ProfilerMarker(System.Char\*,System.Int32)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(char*-int\))                                                                                                    | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(System.Char\*,System.Int32,Unity.Profiling.LowLevel.MarkerFlags)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(char*-int-markerflags\))                                                   | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(System.String)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(string\))                                                                                                                    | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(System.String,Unity.Profiling.LowLevel.MarkerFlags)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(string-markerflags\))                                                                   | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(Unity.Profiling.ProfilerCategory,System.Char\*,System.Int32)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(profilercategory-char*-int\))                                                  | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(Unity.Profiling.ProfilerCategory,System.Char\*,System.Int32,Unity.Profiling.LowLevel.MarkerFlags)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(profilercategory-char*-int-markerflags\)) | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(Unity.Profiling.ProfilerCategory,System.String)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(profilercategory-string\))                                                                  | Constructs a new performance marker for code instrumentation. |
| [ProfilerMarker(Unity.Profiling.ProfilerCategory,System.String,Unity.Profiling.LowLevel.MarkerFlags)](/engine/6000.3/script-reference/unity/profiling/profilermarker/ctor.md#profilermarker\(profilercategory-string-markerflags\))                 | Constructs a new performance marker for code instrumentation. |

## Properties

| Property                                                                           | Description                                                                                                    |
| ---------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| [Handle](/engine/6000.3/script-reference/unity/profiling/profilermarker/handle.md) | Gets native handle of the [ProfilerMarker](/engine/6000.3/script-reference/unity/profiling/profilermarker.md). |

## Methods

| Method                                                                           | Description                                                                                                                                                                |
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Auto](/engine/6000.3/script-reference/unity/profiling/profilermarker/auto.md)   | Creates a helper struct for the scoped **using** blocks.                                                                                                                   |
| [Begin](/engine/6000.3/script-reference/unity/profiling/profilermarker/begin.md) | Begin profiling a piece of code marked with a custom name defined by this instance of [ProfilerMarker](/engine/6000.3/script-reference/unity/profiling/profilermarker.md). |
| [End](/engine/6000.3/script-reference/unity/profiling/profilermarker/end.md)     | End profiling a piece of code marked with a custom name defined by this instance of [ProfilerMarker](/engine/6000.3/script-reference/unity/profiling/profilermarker.md).   |

## Structs

| Struct                                                                                                  | Description                                                                                                                           |
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| [ProfilerMarker.AutoScope](/engine/6000.3/script-reference/unity/profiling/profilermarker/autoscope.md) | Helper IDisposable struct for use with [ProfilerMarker.Auto](/engine/6000.3/script-reference/unity/profiling/profilermarker/auto.md). |
