# ProfilerRecorder

> Constructs ProfilerRecorder instance with a Profiler metric name.

## Definition

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

## ProfilerRecorder(string, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name.

```csharp
public ProfilerRecorder(string statName, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Profiler marker or counter name.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum amount of samples to be collected.**** (\[ProfilerRecorderOptions]\(/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions)): Profiler recorder options.

### Remarks

Use to initialize ProfilerRecorder with a metric name only. Unity searches for the metric name across all categories, and as such, initialization is slower than if you specify a category.

## ProfilerRecorder(string, string, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name and category.

```csharp
public ProfilerRecorder(string categoryName, string statName, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Profiler category name.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Profiler marker or counter name.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum amount of samples to be collected.**** (\[ProfilerRecorderOptions]\(/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions)): Profiler recorder options.

### Remarks

Use to initialize ProfilerRecorder and associate it with a specific Profiler metric.

By default, ProfilerRecorder does not start collecting data immediately. Use [ProfilerRecorderOptions.StartImmediately](/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions/startimmediately.md) to enable collection together with ProfilerRecorder construction.  Alternatively, use [ProfilerRecorder.Start](/engine/6000.7/script-reference/unity/profiling/profilerrecorder/start.md) method after construction.

If the [ProfilerRecorder.CurrentValue](/engine/6000.7/script-reference/unity/profiling/profilerrecorder/currentvalue.md) is the only data you are interested in, you don't need to start ProfilerRecorder or allocate sample storage. In this case, use 0 as a `capacity` parameter when creating ProfilerRecorder.

Using a negative number as a `capacity` parameter throws `ArgumentException`.

For a list of built-in Profiler markers and counters available, refer to [Profiler markers reference](/engine/6000.7/manual/analysis/profiler/markers.md) and [Profiler counters reference](/engine/6000.7/manual/analysis/profiler/counters-reference.md).

**Note:**

ProfilerRecorder allocates memory and must be disposed when it is no longer needed.

```csharp
using Unity.Profiling;
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    ProfilerRecorder systemMemoryRecorder;
    ProfilerRecorder gcMemoryRecorder;
    ProfilerRecorder mainThreadTimeRecorder;

    void OnEnable()
    {
        systemMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "System Used Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately);
        gcMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "GC Reserved Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately);
        mainThreadTimeRecorder = new ProfilerRecorder(ProfilerCategory.Internal, "Main Thread", 15);
        mainThreadTimeRecorder.Start();
    }

    void OnDisable()
    {
        systemMemoryRecorder.Dispose();
        gcMemoryRecorder.Dispose();
        mainThreadTimeRecorder.Dispose();
    }
}
```

Additional Resources: [ProfilerRecorder.StartNew](/engine/6000.7/script-reference/unity/profiling/profilerrecorder/startnew.md).

## ProfilerRecorder(ProfilerCategory, string, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name and category.

```csharp
public ProfilerRecorder(ProfilerCategory category, string statName, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)
```

### Parameters

**** (\[ProfilerCategory]\(/engine/6000.7/script-reference/unity/profiling/profilercategory)): Profiler category identifier.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Profiler marker or counter name.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum amount of samples to be collected.**** (\[ProfilerRecorderOptions]\(/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions)): Profiler recorder options.

### Remarks

Use to initialize ProfilerRecorder and associate it with a specific Profiler metric.

By default, ProfilerRecorder does not start collecting data immediately. Use [ProfilerRecorderOptions.StartImmediately](/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions/startimmediately.md) to enable collection together with ProfilerRecorder construction.  Alternatively, use [ProfilerRecorder.Start](/engine/6000.7/script-reference/unity/profiling/profilerrecorder/start.md) method after construction.

If the [ProfilerRecorder.CurrentValue](/engine/6000.7/script-reference/unity/profiling/profilerrecorder/currentvalue.md) is the only data you are interested in, you don't need to start ProfilerRecorder or allocate sample storage. In this case, use 0 as a `capacity` parameter when creating ProfilerRecorder.

Using a negative number as a `capacity` parameter throws `ArgumentException`.

For a list of built-in Profiler markers and counters available, refer to [Profiler markers reference](/engine/6000.7/manual/analysis/profiler/markers.md) and [Profiler counters reference](/engine/6000.7/manual/analysis/profiler/counters-reference.md).

**Note:**

ProfilerRecorder allocates memory and must be disposed when it is no longer needed.

```csharp
using Unity.Profiling;
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    ProfilerRecorder systemMemoryRecorder;
    ProfilerRecorder gcMemoryRecorder;
    ProfilerRecorder mainThreadTimeRecorder;

    void OnEnable()
    {
        systemMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "System Used Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately);
        gcMemoryRecorder = new ProfilerRecorder(ProfilerCategory.Memory, "GC Reserved Memory", 1, ProfilerRecorderOptions.Default | ProfilerRecorderOptions.StartImmediately);
        mainThreadTimeRecorder = new ProfilerRecorder(ProfilerCategory.Internal, "Main Thread", 15);
        mainThreadTimeRecorder.Start();
    }

    void OnDisable()
    {
        systemMemoryRecorder.Dispose();
        gcMemoryRecorder.Dispose();
        mainThreadTimeRecorder.Dispose();
    }
}
```

Additional Resources: [ProfilerRecorder.StartNew](/engine/6000.7/script-reference/unity/profiling/profilerrecorder/startnew.md).

## ProfilerRecorder(ProfilerCategory, char\*, int, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name pointer or other unsafe handles.

```csharp
public ProfilerRecorder(ProfilerCategory category, char* statName, int statNameLen, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)
```

### Parameters

**** (\[ProfilerCategory]\(/engine/6000.7/script-reference/unity/profiling/profilercategory)): Profiler category identifier.**** (\[char\*]\(https\://learn.microsoft.com/dotnet/api/system.char)): Profiler marker or counter name pointer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Profiler marker or counter name length.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum amount of samples to be collected.**** (\[ProfilerRecorderOptions]\(/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions)): Profiler recorder options.

## ProfilerRecorder(ProfilerMarker, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name pointer or other unsafe handles.

```csharp
public ProfilerRecorder(ProfilerMarker marker, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)
```

### Parameters

**** (\[ProfilerMarker]\(/engine/6000.7/script-reference/unity/profiling/profilermarker)): Profiler marker instance.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum amount of samples to be collected.**** (\[ProfilerRecorderOptions]\(/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions)): Profiler recorder options.

## ProfilerRecorder(ProfilerRecorderHandle, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name pointer or other unsafe handles.

```csharp
public ProfilerRecorder(ProfilerRecorderHandle statHandle, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)
```

### Parameters

**** (\[ProfilerRecorderHandle]\(/engine/6000.7/script-reference/unity/profiling/lowlevel/unsafe/profilerrecorderhandle)): Profiler recorder handle.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Maximum amount of samples to be collected.**** (\[ProfilerRecorderOptions]\(/engine/6000.7/script-reference/unity/profiling/profilerrecorderoptions)): Profiler recorder options.
