Search Unity

Feedback Is there a way to flag frames in the profiler from code?

Discussion in 'Scripting' started by JasonC_, May 27, 2021.

  1. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    Sometimes I have a really hard time finding the specific frame I'm looking for in the profiler.

    Is there some way, in code, to set some kind of marker or flag or something on the current frame so that that frame becomes more conspicuous in the profiler window?

    Unity 2020.3.9f1, Windows 64-bit
     
    Ali_V_Quest likes this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
  3. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    Hey thanks!! Well... I just spent a while playing with it, and I guess I can't figure out how to use it effectively, or it just doesn't work or is super buggy. Or both, lol.

    I created a new marker, and did `Begin()` + `End()` around a fairly long block of code and some short inner blocks but... they randomly seem to not show up at all (or sometimes they seem to show up but not with the assigned name). I messed around with `Auto()` and all sorts of strategies for creating new markers, and different profiler settings, but, I couldn't make them behave in a consistent way.

    Also, it's not quite what I was looking for. You still have to hunt through all of the frames and threads for a marker (why the Profiler doesn't have a search function to search every frame and thread is kind of a mystery -- unless it does and I couldn't find it; all I found was the search selected frame + selected thread in the hierarchy view).

    What I was hoping for was a way to make it so I didn't have to spend so much time hunting for events. Just like, a very visible vertical bar in the timing window or something.

    Ah well.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    Unfortunately I think it's the best you can do at the moment. Have you at least played with changing the color for your custom marker? That's an option in the "category" you pass in.
     
    JasonC_ likes this.
  5. MartinTilo

    MartinTilo

    Unity Technologies

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

    Both cross-frame, cross-thread and timeline view search as well as "bookmarks" are on our feature request backlog. And yes, we don't have anything there yet except placing markers.

    Those should work though, so, I'd try debugging your code to see if it executes. Double check that it's running on the main thread and that your hierarchy is set to show the main thread. (If its on a Job Thread, it can can be tricky as that work can be assigned to different job Threads in different frames, using the category for coloring might help finding it in Timeline view though. Otherwise, check the thread you're expecting it on.)
     
    Last edited: May 28, 2021
    JasonC_ likes this.
  6. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    @MartinTilo Thanks!!

    I was just about to come back and post that I had just done a lot of profiler testing, and the reason mine were randomly working was because cross-frame and cross-thread markers didn't seem to be supported. Thanks for validating that and glad to hear that's on the todo list somewhere.

    I think, though, in the mean time, maybe it should be a priority to at least update the LTS documentation to mention those limitations. It's too late to save me, lol, but maybe it'll save somebody else a day of head-scratching.

    I'm super looking forward to bookmarks, because I'm already tired of my workaround of picking an unused category and sleeping for 5ms in a marker to make a bookmark spike...

    Well, since you mentioned it (lol), here's a couple thread-related profiler bugs and requests (2020.3.9f1, didn't grab 10f1 yet):
    • Bug: The list of threads in the timeline doesn't clear when the profiler is cleared, so threads that existed in previous runs build up indefinitely, cluttering the list until you restart the editor. The easiest way to reproduce this is probably to just play any project for a few seconds then stop it, and repeat a few times, and watch, say, the number of Script Threads -> Domain Unloader timelines increase. If you've got a project that creates new System.Threads, you'll notice it right away, too.
    • Bug: The thread selector dropdown in the hierarchy view seems to treat '/' in thread names as some sort of subcategory thing or something, which leads to strange results for the stock "Thread Pool I/O Selector" thread (in scripting threads section).
    • FR: FOR THE LOVE OF GOD AND ALL THAT IS HOLY, CAN SOMEBODY PLEASE SHOW THREAD ID NUMBERS NEXT TO EVERY THREAD. :D In both timeline and hierarchy views. Managed and/or native IDs, the former probably being more useful for typical debugging cases.
    • FR: Let the search box in the hierarchy view search every thread for the selected frame. Even better, a search box that searches every thread for every frame in the buffer. That'd be as helpful as bookmarks (to me, anyways).
    Here's a screenshot that shows all of that at once, heh:

    upload_2021-5-28_8-47-17.png

    Let me know if you'd rather me file those through the report tool instead of just spamming them here.

    ---

    PS Is it just me or does "O Selector" sound vaguely NSFW? Guess it's better than "I/O Face"...
     
    Last edited: May 28, 2021
    One1Guy likes this.
  7. JasonC_

    JasonC_

    Joined:
    Oct 27, 2019
    Posts:
    66
    Oh neat! That does help a small bit, at least, thanks for the tip!
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,460
    oh right, that's different from search but yes, markers need to be ended in the same frame and thread (actually, they need to be ended in the same stack frame/sample scope or they will cause errors due to Miss-matching Begin End calls.). For cross thread relationships, we have FlowEvents. The Render Thread is special and allowed to stretch into the next frame and then flip to the next frame at its own pace. (Background) Job threads can overlap somewhat but we're also working on a fix where they get properly split if they are overlapping the main frame boundary and then if selected in timeline view, the tooltip shows how much sliced of time they spend in surrounding frames.

    however, it sounds a bit like what you want is scope detatched "Async" markers that can start in any scope and end in another and kinda get their own track? If so, that is needed for Async profiling and also in the Feature Request backlog, right next to Bookmarks.


    Thanks for flagging these bugs, can you please enter them through the Bug Reporter (Help > Report a Bug) so we (you and us) can track them better?

    that is what I meant with cross thread, cross frame search and I know that it is kinda "masking" as the "I need Bookmarks" request, at least to a certain extent. I.e. if we implement bookmarks before search, we get a new mess of unsearchable bookmarks. If we implement search first, less bookmarks are needed and the ones that are placed can be searched for the same way as markers.

    Exposing thread Ids is a good ask, I'm gonna throw that into our feature request backlog :)
    Also noted that ProfilerMarker API docs need to clarify the scope restriction.

    Thanks for all the feedback :)