Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Question Clarifications for the Unity Profiler class api.

Discussion in 'Profiler Previews' started by GalShaffir1, Jun 2, 2022.

  1. GalShaffir1

    GalShaffir1

    Joined:
    Mar 3, 2022
    Posts:
    4
    Hello everyone!
    forwarding my post from documentation forum:

    I have recently started messing around with the unity profiler for the first time, my goal is to monitor GPU and CPU usage in my project through script and display the data on screen.
    I'm using the profiler class in order to achieve this but I have some questions to which I didn't get a full answer when going through the documentation and looking through the forums (all regarding the "memory" category in the profiler):

    1) What is the right stat to get the current ram usage? Is it "Total Used Memory"? What is the difference between this and "System Used Memory"

    2) Is there a way to get the VRAM usage of the graphics card? if not, what is the best way to monitor GPU usage through the profiler api (by monitoring gpu usage i mean what is the current work load of the gpu and how high is it regarding the total workload the gpu can handle)

    3) what is the meaning in "Gfx Used Memory"? this memory is allocated on the RAM or the GPU?
    In addition what is the difference between this stat and "UnityEngine.Profiler.GetAllocatedMemoryForGraphicsDriver"? they both appear to have the same value in my scene

    *) I have used the Memory profiler module in unity api.
    *) My project unity version is 2020.3.29f1


    Some questions might appear trivial but stiil any help would be much appreciated, thank you!
     
    alexeyzakharov likes this.
  2. alexeyzakharov

    alexeyzakharov

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    473
    Hi @GalShaffir1 ,
    Thanks for the questions!

    In 2020 version of Unity "System Used Memory" metric is the closest to RAM usage. It is closest because it reports slightly different values depending on a platform (e.g. PSS on android/linux, RAM on OSX and commited on Windows).
    "Total Used Memory" represents what Unity's engine tracks and what was a) allocated by its memory management system, b) scripting VM heaps, c) estimated GPU allocations. It does not include allocations done in native plugins or any allocations done outside of memory management system.
    We've refined memory metrics in upcoming Unity 2022 version to clearly report resident (RAM) memory via
    "App Resident Memory" (and "System Used Memory" for backwards compatibility), committed memory via
    "App Committed Memory" consistently across platforms.

    For the second part of the question - on Mali GPU you can try the System Metrics Mali Package https://forum.unity.com/threads/introducing-system-metrics-mali-package.1126178/ . If you know the frequency of your device you can calculate the utilization metric based on GPU cycles information.

    Related crossplatform api we have is FrameTimingManager that can answer the question if you are CPU or GPU bound - https://forum.unity.com/threads/update-for-frame-timing-manager.1191877/#post-7623058 :)

    Besides that it is only platform profilers which can give specific device information which we generally don't have access to.

    "Gfx Used Memory" is the estimated amount of memory allocated on GPU - estimated VRAM usage of your game. Is it equivalent to UnityEngine.Profiler.GetAllocatedMemoryForGraphicsDriver API.

    Hope that helps :)
     
    GalShaffir1 and codestage like this.
  3. GalShaffir1

    GalShaffir1

    Joined:
    Mar 3, 2022
    Posts:
    4
    Thank you so much alexey! apperciate the detailed answer!
     
    alexeyzakharov likes this.