Search Unity

ProfilerRecorder doesn't work with every statname

Discussion in 'Scripting' started by TheFudge, Mar 24, 2022.

  1. TheFudge

    TheFudge

    Joined:
    Apr 28, 2014
    Posts:
    39
    Hey all,
    I'm currently developing a tiny performance panel for our builds.
    What I want it to do:
    They need to have render timings and script timings as well as memory.
    I want to display those stats in a release build.
    Problem:
    I've bee using the ProfilerRecorder and it kind of works great. I followed the docs and the video tutorial from unity to get it to work. My main struggle is to get Render Times working.
    This is how I start all of the recorders.
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         #if UNITY_EDITOR || DEVELOPMENT_BUILD || SPELLS_ENABLED
    4.        
    5.         systemMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "System Used Memory");
    6.         gcMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "GC Reserved Memory");
    7.         setpassTimeRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "SetPass Calls Count", 15);
    8.         renderThread = ProfilerRecorder.StartNew(ProfilerCategory.Internal, "Render Thread", 32);
    9.         mainthread = ProfilerRecorder.StartNew(ProfilerCategory.Internal, "Main Thread", 32);
    10.         VertsRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Vertices Count", 16);
    11.        
    12.         StartCoroutine(PostEverySecond());
    13.        
    14.        
    15. #else
    16.         Destroy(gameobject);
    17. #endif
    18.     }
    19.  
    20.     void OnDestroy()
    21.     {
    22.         systemMemoryRecorder.Dispose();
    23.         gcMemoryRecorder.Dispose();
    24.         setpassTimeRecorder.Dispose();
    25.         renderThread.Dispose();
    26.         VertsRecorder.Dispose();
    27.         mainthread.Dispose();
    28.     }
    29.  
    30.  
    And here is the corde where the values are read and displayed into a text element.
    Code (CSharp):
    1.             builder.AppendLine($"Render Thread: {GetRecorderFrameAverage(renderThread) * (1e-6d):F2} ms");
    2.             builder.AppendLine($"Main Thread: {GetRecorderFrameAverage(mainthread) * (1e-6d):F2} ms");
    3.            
    4.             builder.AppendLine($"Vertices count: {VertsRecorder.LastValue}");
    5.             builder.AppendLine($"System Memory: {systemMemoryRecorder.LastValue / (1024 * 1024)} MB");
    6.  
    As you can see render thread is not printing any values (this is from the editor, but it also doesn't work in the builds)
    upload_2022-3-24_11-53-53.png
    What am I doing wrong? I can't find any clues... I copied the stats name directly from the
    ProfilerRecorderHandle.GetAvailable() list.

    I use URP.

    Regards,
    Kasimir
     
  2. Vince-Chimp

    Vince-Chimp

    Joined:
    May 28, 2018
    Posts:
    43
    I am actually seeing the same issue, and am also using URP. I can't seem to get Render Thread to actually spit out a number reliably. It occasionally works in editor though, but the example code (same i used as well) starts spitting out -3242598439 like numbers as well on that.
    The specific things i am looking for are actually available in the normal profiler while profiling the device, and the stat is logged as available AND is valid checked before i append the line on screen as well.

    Bumping for help.

    PS: Looks like if you are profiling the device in unity, Render Thread suddenly turns up, mostly accurate (90% of the time) the rest just turns 0's again
     
    Last edited: Jun 2, 2022
  3. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    Last edited: Oct 7, 2022
  4. michael_unity145

    michael_unity145

    Joined:
    Mar 8, 2022
    Posts:
    21
    Any more info regarding this, tried using the profile recorder for rendering (copy pasted the example) which spits out zeros on URP?
     
  5. lh_jouni

    lh_jouni

    Joined:
    Aug 13, 2019
    Posts:
    2
    Having the same issue with built-in rendering pipeline.. sometimes I get rendering thread stats but most of the time not. Every time I connect the Unity profiler to the device build it starts spitting out correct values from rendering thread also.
     
    alexeyzakharov likes this.
  6. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    508
    Hi!

    Sorry for the confusion - the "Render Thread" marker was present among other counters by a mistake and was removed in 2022.2.0a3 to not cause this confusion. Its original purpose was to "name" a thread in Unity Profiler, and as sideeffect of using wrong mechanism it was leaked for ProfilerRecorde's consumption. In most cases the time was equivalent to main thread time and didn't carry any information about any rendering workloads.

    If you want to get information on render thread and/or GPU frame time metrics please use FrameTimingManager api.
    We have a blogpost which describes what each of timings mean - https://blog.unity.com/technology/detecting-performance-bottlenecks-with-unity-frame-timing-manager
    FrameTimingManager data is also available through ProfilerRecorder api
     
    MartinTilo likes this.
  7. bovesan

    bovesan

    Joined:
    Nov 30, 2017
    Posts:
    5
    Very interested to know how. Been spending too much time trying to use the FrameTimingManager in v2021 (before learning it's not actually doing anything although existing). And trying to find the stat name strings for ProfileRecorder is a nightmare.