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

Path(s) to root

Discussion in 'Profiler Previews' started by Skittlebrau, May 7, 2019.

  1. Skittlebrau

    Skittlebrau

    Joined:
    Jan 8, 2013
    Posts:
    34
    Is there some way to easily see a managed object's path(s) to root? If not, this would be a very useful feature for finding leaks. Best I figure out now is to guess my way through the references, which often get too convoluted to follow to root, unless I'm lucky/have a good idea of what's going on already.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,324
    These are displayed in the panel in the lower-right, as shown in this screenshot:
    https://forum.unity.com/attachments/cs_objects_view-png.275667/

    If it's empty, the object either has no path to root or it's another bug in Unity's Memory Profiling API, or an issue in Heap Explorer. You can also try Unity's new Memory Profiler to see if it works there:
    https://forum.unity.com/threads/new...ew-package-available-for-unity-2018-3.597271/

    Do you use .NET4 scripting runtime? This contained various bugs in the memory profiling API the last time I tested it.
     
  3. Skittlebrau

    Skittlebrau

    Joined:
    Jan 8, 2013
    Posts:
    34
    Hey Peter. I was asking about the new Unity profiler. I have used Heap Explorer in the past, and it's been great (so thanks for your efforts there!), but it's been having issues recently (so maybe .NET 4 runtime which we do use or Unity 2018.3 changes). I do get a lot of errors from Heap Explorer like the following, so that might have something to do with it. I know you have stopped development and open-sourced it, but I have not had time to try to debug what's going on.

    Code (CSharp):
    1. ERROR: 'System.Collections.Generic.Dictionary.Entry<System.Int32,System.Globalization.CultureInfo>[].baseOrElementTypeIndex' = -1 is out of range, ignoring. Details in second line
    2. arrayRank=1, isArray=True, typeInfoAddress=4239CAA0, address=3C337BD0, memoryreader=MemoryReader, isValueType=False
    3. UnityEngine.Debug:LogErrorFormat(String, Object[])
    4. HeapExplorer.AbstractMemoryReader:ReadObjectSize(UInt64, PackedManagedType) (at Assets/HeapExplorer/Editor/Scripts/MemoryReader.cs:447)
    5. HeapExplorer.PackedManagedObjectCrawler:SetObjectSize(PackedManagedObject&, PackedManagedType) (at Assets/HeapExplorer/Editor/Scripts/PackedTypes/PackedManagedObjectCrawler.cs:595)
    6. HeapExplorer.PackedManagedObjectCrawler:CrawlManagedObjects() (at Assets/HeapExplorer/Editor/Scripts/PackedTypes/PackedManagedObjectCrawler.cs:335)
    7. HeapExplorer.PackedManagedObjectCrawler:Crawl(PackedMemorySnapshot, List`1) (at Assets/HeapExplorer/Editor/Scripts/PackedTypes/PackedManagedObjectCrawler.cs:77)
    8. HeapExplorer.PackedMemorySnapshot:Initialize(String) (at Assets/HeapExplorer/Editor/Scripts/PackedTypes/PackedMemorySnapshotEx.cs:1088)
    9. HeapExplorer.HeapExplorerWindow:ReceiveHeapThreaded(Object) (at Assets/HeapExplorer/Editor/Scripts/HeapExplorerWindow.cs:983)
    10. HeapExplorer.ReceiveThreadJob:ThreadFunc() (at Assets/HeapExplorer/Editor/Scripts/HeapExplorerWindow.cs:1034)
    11. HeapExplorer.HeapExplorerWindow:ThreadLoop() (at Assets/HeapExplorer/Editor/Scripts/HeapExplorerWindow.cs:783)
    12. System.Threading.ThreadHelper:ThreadStart()
    13.  
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,324
    Oh yeah, sorry I totally missed that. For some reason, I thought you private messaged me. I didn't recall I subscribed to the Profiler forum. My fault :confused:
     
    MartinTilo likes this.
  5. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,904
    Path to root is in our backlog and needed to reach feature parity with the old BitBucket memory profiler so we'll need it before we'll move out of preview. I can't give an ETA though.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,324
    A learning from Heap Explorer: Finding root paths in more complex projects can take a really long time. In Heap Explorer, that loop can make a lot of iterations, often taking multiple seconds to finish.

    I normally add "loop guards" to while(true) kinda loops to avoid that a bug causes the application to run forever and I assumed at the beginning that this loop should not run more than 10000 iterations or so. I then increased it to 100000, 200000, and users still reported the loop guard kicks in. Then I increased the limit to 1000000 iterations and moved it to a separate thread. I should actually remove the loop-guard altogether now as I'm thinking about it, because it's not needed anymore.

    In order to not block the UI, I scan them on a separate thread and show "Please wait" and a cancel button in the "Paths to root" panel. All other functionality still works while it tries to find the roots, so you can use the tool while it's scanning the paths. If the user selects a different item, while it's still scanning, I abort the task and start it for the new selected item to have no awful UI responsiveness.

    The "Please wait" is also not a great solution, a better solution would have been to update the UI with the paths while it's scanning for further ones.
     
    alexrvn likes this.
  7. Skittlebrau

    Skittlebrau

    Joined:
    Jan 8, 2013
    Posts:
    34
    Having not thought about the problem, so perhaps I am being super ignorant here, but isn't "path to root" essentially the same check that Garbage Collector does? Basically a full traversal of object graph?

    Is the new Unity profiler not open source? I could not find anything but the old one.
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,904
  9. Skittlebrau

    Skittlebrau

    Joined:
    Jan 8, 2013
    Posts:
    34
    Ah I found that it's buried in the Library directory. I had no idea and thought the packages we're a binary delivery of DLLs. Just in case anyone else reading this is confused.
     
    MartinTilo likes this.