Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Possible to sort profiler data by a sample section's total time without slicing by call stack?

Discussion in 'Scripting' started by graybear209, Dec 12, 2021.

  1. graybear209

    graybear209

    Joined:
    Nov 18, 2018
    Posts:
    11
    TLDR:
    forums-post.png

    I'm interested in identifying "lower level" methods that account for an outsized proportion of CPU usage each frame that are called typically called many times from different places in my game's code base.

    Suppose I've instrumented each method in my code and it looks like below:

    Code (CSharp):
    1. void OuterMethod1()
    2. {
    3.     LowLevelMethod();
    4. }
    5.  
    6. void OuterMethod2()
    7. {
    8.     LowLevelMethod();
    9. }
    The profiler hierarchy view would show something like:

    OuterMethod1 (4.2ms)
    > LowLevelMethod (4ms)
    OuterMethod2 (5.2ms)
    > LowLevelMethod (4ms)

    The "Time ms" data column for each instance of "LowLevelMethod" method would only show the time used by that method for that particular trace, it wouldn't sum across all invocations of LowLevelMethod across all traces.

    Is there any way I can sort profiler data by "Time ms" across ALL instances of a method/profiling sample name?

    Given the example above, I'd want it to look something like:

    OuterMethod1 (4.2ms)
    OuterMethod2 (5.2ms)
    LowLevelMethod (8ms)

    It seems like this data is collected. If I select a row in the profiler with "Show calls" enabled, there is an entry with the total time aggregated across all invocations of that method. But is there some way to sort the table data by that single aggregated value?
     
    alexeyzakharov likes this.
  2. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    508
    Thanks for the question and detailed usecase explanation!

    We have an extra tool on top of profiler which I believe can help you with total values analysis - https://docs.unity3d.com/Packages/com.unity.performance.profile-analyzer@1.1/manual/single-view.html

    You can pull the data into Profile Analyzer and in single view sort samples by total aggregated time.
    That would give you exactly the timings you want to see:
    OuterMethod1 (4.2ms)
    OuterMethod2 (5.2ms)
    LowLevelMethod (8ms)

    Thanks!
     
    a436t4ataf and graybear209 like this.
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,517
    Thank you for the feedback. I'd like to clarify something a bit. Did you mean you want to only have to filter for "LowLevelMethod" and still see the different calling scopes, like "OuterMethod1" and "OuterMethod2" without having to explicitly filter for them, and just seeing the LowLevelMethod time split across these?

    Profile Analyzer can probably help you somewhat but not in this regard, as it discards the hierarchical aspect of the profiler data beyond the call depth. It's an interesting point though and I think I have some ideas how that can be achieved. It's gonna be a while until we get to that but I'm noting it down with a fitting feature idea we have :)
     
  4. graybear209

    graybear209

    Joined:
    Nov 18, 2018
    Posts:
    11
    The core of the question was just the aggregate `LowLevelMethod` time without the need for calling scopes. It would be pretty sweet if I could see something like a stacked line graph of all the different calling scopes adding up to the total time but for the moment I'm happy with jumping back and forth between the Profile Analyzer (if I need the aggregate) and the Profiler (if I want to see by scopes, even if only for a single frame at a time)
     
    MartinTilo likes this.