Search Unity

Profiler.BeginSample vs CustomSampler / Recorder APIs

Discussion in 'Scripting' started by liortal, Jun 6, 2021.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I'm wondering what are the differences between these 2 concepts - Profiler.BeginSampler / EndSample and the newer CustomSampler API that allows creating new profiling labels.

    Is CustomSampler going to replace BeginSample ? what are the typical uses for each of these?
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,460
    It feels a bit like we already had this conversation but:
    We're moving things around under the hood to align the API mostly on ProfilerMarker and ProfilerRecorder. CustomSampler, Recorder and Profiler.BeginSample are very likely to get deprecated in this process over the next major unity releases.

    BeginSmple already uses a static, special, ProfilerMarker under the hood that reports the name as it's string metadata. The Profiler window then shows it as that metadata name. It's not possible to record such samples using the Recorder APIs because they aren't actually using their name as the sample name. It's kind of the "easy way out" for impromptu additions of profiling scopes but also the one with the highest profiling overhead (as it sends the name to native, then as string metadata into the profiler stream, instead of just an ID like CustomSampler and ProfilerMarker would use). So it's kinda like a debug log for temporary debugging. Generally speaking, you should stick with ProfilerMarker and ProfilerRecorder, which have lower overhead, more features, more upcoming features and future safety and are DOTS (or specifically Burst) compatible.
     
    Joserklabater, a436t4ataf and liortal like this.
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Thanks for the answer @MartinTilo !
    Let's discuss this again in a year from now LOL
     
    MartinTilo and fherbst like this.