CreateMarker
Constructs a new Profiler marker handle for code instrumentation.
Read time 3 minutesLast updated 13 days ago
Definition
- Type: Method
- Namespace: Unity.Profiling.LowLevel.Unsafe
- Assembly: UnityEngine.CoreModule
CreateMarker(string, ushort, MarkerFlags, int)
Constructs a new Profiler marker handle for code instrumentation.
public static IntPtr CreateMarker(string name, ushort categoryId, MarkerFlags flags, int metadataCount)
Parameters
A marker name.
A profiler category identifier.
The marker flags.
The metadata parameters count, or 0 if no parameters are expected.
Returns
Type | Description |
|---|---|
| IntPtr | Returns the marker native handle. |
Remarks
Use profiler marker handle with ProfilerUnsafeUtility methods only.
The categoryId parameter associates the marker with one of the predefined categories in ProfilerCategory struct.
Note: Markers created with CreateMarker automatically get MarkerFlags.Script flag.
using Unity.Collections.LowLevel.Unsafe;using Unity.Profiling.LowLevel;using Unity.Profiling.LowLevel.Unsafe;using System;class Example{ static readonly IntPtr markerHandle = ProfilerUnsafeUtility.CreateMarker("MyMarker", ProfilerUnsafeUtility.CategoryScripts, MarkerFlags.Default, 0); static unsafe void DoWork(int num) { ProfilerUnsafeUtility.BeginSample(markerHandle); //... ProfilerUnsafeUtility.EndSample(markerHandle); }}
Use CreateMarker to set metadata parameter names when passing metadata with :ref::BeginSampleWithMetadata method.
using Unity.Collections.LowLevel.Unsafe;using Unity.Profiling;using Unity.Profiling.LowLevel;using Unity.Profiling.LowLevel.Unsafe;using System;class Example{ static IntPtr MakeMarkerWithIntMetadata(string name, string paramName) { var handle = ProfilerUnsafeUtility.CreateMarker(name, ProfilerUnsafeUtility.CategoryScripts, MarkerFlags.Default, 1); ProfilerUnsafeUtility.SetMarkerMetadata(handle, 0, paramName, (byte)ProfilerMarkerDataType.Int32, (byte)ProfilerMarkerDataUnit.Count); return handle; } static readonly IntPtr markerHandle = MakeMarkerWithIntMetadata("MyMarker", "Work Idx"); static unsafe void DoWork(int num) { var metadata = stackalloc ProfilerMarkerData[1]; metadata[0].Type = (byte)ProfilerMarkerDataType.Int32; metadata[0].Size = (uint)UnsafeUtility.SizeOf<int>(); metadata[0].Ptr = UnsafeUtility.AddressOf(ref num); ProfilerUnsafeUtility.BeginSampleWithMetadata(markerHandle, 1, metadata); //... ProfilerUnsafeUtility.EndSample(markerHandle); }}
Additional Resources: ProfilerCategory, MarkerFlags.
CreateMarker(char*, int, ushort, MarkerFlags, int)
Constructs a new Profiler marker handle for code instrumentation.
public static IntPtr CreateMarker(char* name, int nameLen, ushort categoryId, MarkerFlags flags, int metadataCount)
Parameters
A marker name.
Marker name string length.
A profiler category identifier.
The marker flags.
The metadata parameters count, or 0 if no parameters are expected.
Returns
Type | Description |
|---|---|
| IntPtr | Returns the marker native handle. |
Remarks
Use profiler marker handle with ProfilerUnsafeUtility methods only.
The categoryId parameter associates the marker with one of the predefined categories in ProfilerCategory struct.
Note: Markers created with CreateMarker automatically get MarkerFlags.Script flag.
using Unity.Collections.LowLevel.Unsafe;using Unity.Profiling.LowLevel;using Unity.Profiling.LowLevel.Unsafe;using System;class Example{ static readonly IntPtr markerHandle = ProfilerUnsafeUtility.CreateMarker("MyMarker", ProfilerUnsafeUtility.CategoryScripts, MarkerFlags.Default, 0); static unsafe void DoWork(int num) { ProfilerUnsafeUtility.BeginSample(markerHandle); //... ProfilerUnsafeUtility.EndSample(markerHandle); }}
Use CreateMarker to set metadata parameter names when passing metadata with :ref::BeginSampleWithMetadata method.
using Unity.Collections.LowLevel.Unsafe;using Unity.Profiling;using Unity.Profiling.LowLevel;using Unity.Profiling.LowLevel.Unsafe;using System;class Example{ static IntPtr MakeMarkerWithIntMetadata(string name, string paramName) { var handle = ProfilerUnsafeUtility.CreateMarker(name, ProfilerUnsafeUtility.CategoryScripts, MarkerFlags.Default, 1); ProfilerUnsafeUtility.SetMarkerMetadata(handle, 0, paramName, (byte)ProfilerMarkerDataType.Int32, (byte)ProfilerMarkerDataUnit.Count); return handle; } static readonly IntPtr markerHandle = MakeMarkerWithIntMetadata("MyMarker", "Work Idx"); static unsafe void DoWork(int num) { var metadata = stackalloc ProfilerMarkerData[1]; metadata[0].Type = (byte)ProfilerMarkerDataType.Int32; metadata[0].Size = (uint)UnsafeUtility.SizeOf<int>(); metadata[0].Ptr = UnsafeUtility.AddressOf(ref num); ProfilerUnsafeUtility.BeginSampleWithMetadata(markerHandle, 1, metadata); //... ProfilerUnsafeUtility.EndSample(markerHandle); }}
Additional Resources: ProfilerCategory, MarkerFlags.