# GetMarkerId(string)

> Get Profiler marker identifier for a specific name.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Profiling](/engine/6000.0/script-reference/unityeditor/profiling.md)
* **Assembly:** UnityEditor

```csharp
public int GetMarkerId(string markerName)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Marker name.

### Returns

| Type                                                       | Description                                                                                                |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Returns marker identifier as integer. Returns *invalidMarkerId* if there is no such marker in the capture. |

### Remarks

Use marker identifier to avoid string allocations when traversing Profiler data.

The Profiler uses a unique identifier for each marker it creates during a profiling session. The markers can generate many samples which [HierarchyFrameDataView](/engine/6000.0/script-reference/unityeditor/profiling/hierarchyframedataview.md) and [RawFrameDataView](/engine/6000.0/script-reference/unityeditor/profiling/rawframedataview.md) can access.

All samples that the same marker generates have the same integer marker identifier and the same name.

Marker identifiers are persistent for the entire profiling session.

```csharp
using System;
using Unity.Collections;
using UnityEditor.Profiling;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Profiling;

public class Example
{
    public static long GetGCAllocs(int frameIndex)
    {
        long totalGcAllocSize = 0;

        int gcAllocMarkerId = FrameDataView.invalidMarkerId;

        for (int threadIndex = 0;; ++threadIndex)
        {
            using (RawFrameDataView frameData = ProfilerDriver.GetRawFrameDataView(frameIndex, threadIndex))
            {
                if (!frameData.valid)
                    break;

                if (gcAllocMarkerId == FrameDataView.invalidMarkerId)
                {
                    gcAllocMarkerId = frameData.GetMarkerId("GC.Alloc");
                    if (gcAllocMarkerId == FrameDataView.invalidMarkerId)
                        break;
                }

                int sampleCount = frameData.sampleCount;
                for (int i = 0; i < sampleCount; ++i)
                {
                    if (gcAllocMarkerId != frameData.GetSampleMarkerId(i))
                        continue;

                    long gcAllocSize = frameData.GetSampleMetadataAsLong(i, 0);
                    totalGcAllocSize += gcAllocSize;
                }
            }
        }

        return totalGcAllocSize;
    }
}
```

Additional Resources: [FrameDataView.GetMarkerName](/engine/6000.0/script-reference/unityeditor/profiling/framedataview/getmarkername.md), [HierarchyFrameDataView.GetItemMarkerID](/engine/6000.0/script-reference/unityeditor/profiling/hierarchyframedataview/getitemmarkerid.md), [RawFrameDataView.GetSampleMarkerId](/engine/6000.0/script-reference/unityeditor/profiling/rawframedataview/getsamplemarkerid.md).
