ProfilerRecorder and Custom Samples

Hi, I have some code that looks like this:

Profiler.BeginSample("Custom Code");

// Some code

Profiler.EndSample();

Is it possible to access the profiling data of this block using the ProfilerRecorder in script? I tried using the ProfilerRecorderHandle.GetAvailable but it didn’t seem to have anything that looked like the custom block above.

For some context, I was hoping to record and export this data with a script while the game is running.

Use ProfilerMarker API to mark up your code instead. That registers the name with native and then effectively only sends an int over to native for Begin and End calls, whereas Profiler.BeginSample has to Marshall the string every time and technically only reports it as metadata for a sample used by all Profiler.BeginSample calls. All of those then only get their name back on processing the data for display in the Profiler, i.e. the name is not available for ProfilerRecorder at runtime.

So ProfilerMarker API also has a way lowered overhead, plus it allows for writing e.g.

{
  using var _ = marker.Auto();
  // ...
}