Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ProfilerRecorder

Constructs ProfilerRecorder instance with a Profiler metric name.
Read time 3 minutesLast updated 4 days ago

Definition

  • Type: Constructor
  • Namespace: Unity.Profiling
  • Assembly: UnityEngine.CoreModule

ProfilerRecorder(string, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name.
public ProfilerRecorder(string statName, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)

Parameters

statName

Profiler marker or counter name.

capacity

Maximum amount of samples to be collected.

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.
public ProfilerRecorder(string categoryName, string statName, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)

Parameters

categoryName

Profiler category name.

statName

Profiler marker or counter name.

capacity

Maximum amount of samples to be collected.

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 to enable collection together with ProfilerRecorder construction. Alternatively, use ProfilerRecorder.Start method after construction.
If the ProfilerRecorder.CurrentValue 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 and Profiler counters reference.
Note:
ProfilerRecorder allocates memory and must be disposed when it is no longer needed.
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.

ProfilerRecorder(ProfilerCategory, string, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name and category.
public ProfilerRecorder(ProfilerCategory category, string statName, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)

Parameters

Profiler category identifier.

statName

Profiler marker or counter name.

capacity

Maximum amount of samples to be collected.

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 to enable collection together with ProfilerRecorder construction. Alternatively, use ProfilerRecorder.Start method after construction.
If the ProfilerRecorder.CurrentValue 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 and Profiler counters reference.
Note:
ProfilerRecorder allocates memory and must be disposed when it is no longer needed.
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.

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

Constructs ProfilerRecorder instance with a Profiler metric name pointer or other unsafe handles.
public ProfilerRecorder(ProfilerCategory category, char* statName, int statNameLen, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)

Parameters

Profiler category identifier.

statName

Profiler marker or counter name pointer.

statNameLen

Profiler marker or counter name length.

capacity

Maximum amount of samples to be collected.

Profiler recorder options.

ProfilerRecorder(ProfilerMarker, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name pointer or other unsafe handles.
public ProfilerRecorder(ProfilerMarker marker, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)

Parameters

Profiler marker instance.

capacity

Maximum amount of samples to be collected.

Profiler recorder options.

ProfilerRecorder(ProfilerRecorderHandle, int, ProfilerRecorderOptions)

Constructs ProfilerRecorder instance with a Profiler metric name pointer or other unsafe handles.
public ProfilerRecorder(ProfilerRecorderHandle statHandle, int capacity = 1, ProfilerRecorderOptions options = ProfilerRecorderOptions.Default)

Parameters

Profiler recorder handle.

capacity

Maximum amount of samples to be collected.

Profiler recorder options.