Search Unity

Question Profiler.FlushMemoryCounters

Discussion in 'Editor & General Support' started by Domarius, May 9, 2023.

  1. Domarius

    Domarius

    Joined:
    Jan 5, 2013
    Posts:
    103
    I see this function taking up about 15% of my frame (in the "Others" category) at 60fps when profiling. It shows up when I uncomment the part where I create about 8000 of my custom sprite particles. (These are not game objects, they're plain C# objects which call DrawMesh to render themselves)

    If this Profiler function is soley responsible for the "Others" contribution, I shouldn't worry about it? Does it look like it's the case from this screenshot?

    I included 2 screenshots - one before selecting the Profiler.FlushMemoryCounters function in the hierarchy, and one after;
    upload_2023-5-9_17-48-9.png
    upload_2023-5-9_17-48-59.png

    Perhaps it's a situation where I don't want it to track these 8000 objects in this way, though it's hard to know how to track down the problem.

    What's wierd is it's just the creation of these custom objects which cause the frame to be consumed by Profiler.FlushMemoryCounters every frame, I've commented out everything else so that these objects are not being updated or rendered. So I guess it's the profiler doing something with them every frame that's causing the performance hit?
     
    alexeyzakharov likes this.
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    Hello,

    This is a cost that should only be incurred when the profiler is attached/enabled with the Memory Profiler Module active, or a custom module or Profiler recorder code in the runtime that relies on these counters. So if you remove the memory Profiler Module, that cost should likely go away?
    (Question marked because I'm currently unsure if there was a bug here, or if GC Alloc profiling for the CPU Usage module might have had an influence on that time, and because I have no idea what Editor & Player version you're using)
     
    alexeyzakharov likes this.
  3. Domarius

    Domarius

    Joined:
    Jan 5, 2013
    Posts:
    103
    Thank you, where would I find this Memory Profiler Module to remove it? I think I may have installed something like this for another contract project. But I can't find anything in the Package Manager by that name, and the dropdowns on the Profiler window just toggles the view of the module outputs.

    This is my version under About (is there any way to click a button to copy this text without having to manually type out each character?)
    upload_2023-5-12_9-39-19.png
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    The Memory Profiler Module is that view that you can toggle off there, and toggling it off deactivates it. I.e. only views that are added to the Profiler Window record data and thereby incur their overhead
     
  5. ferrous

    ferrous

    Joined:
    Dec 31, 2012
    Posts:
    17
    Does it's cost scale with the number of performance counters in my app? I'm seeing a 2.5ms cost on Quest 2, which is pretty brutal, at that point I'm missing Vsync w/ it on, which makes it a catch-22 situation. If I attach the profiler, which I need to do to get profiling information, then the profiler ends up taking a big chunk of my frames and messing up all the timing info.
     
  6. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,457
    I'm unsure what specifically you mean by this but I still think the answer is no?

    It scales with the amount of Native Objects, and in particular those that are reported with counts and (even more so) those with memory amounts per category (i.e. Textures, Meshes, ...)

    That said, depending on what you meant: using a ProfilerRecorder to request data on those memory counters activates gathering data for them even if
    Profiler.SetAreaEnabled(ProfilerCategory.Memory, false)
    was called or the module disabled in the UI.