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. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Automate back and forth between Profiler and Profile Analyzer

Discussion in 'Profiler Previews' started by Ruhan-_-, Jul 4, 2020.

  1. Ruhan-_-


    Sep 14, 2016
    I've searched a lot but can't find the API to call. Basically when using the profile analyzer from live play we have to first hit the record button on profiler, record some data, turn off record button, switch to profile analyzer, click "pull data".

    That is a lot of manual steps to continuously reprofile. I am hoping this becomes cleaner in the future but for now I would like some help with a couple of API calls

    I would like to automate this.
    Two steps I can't figure out in code are:
    1. Toggle profiler record button in code (there is a shortcut with F9 so I know it can be scripted)
    2. Click "Pull Data" on profile analyzer via script

    It'll make the workflow much smoother for me to reiterate small changes in code to see what performs faster.

  2. lyndon_unity


    Unity Technologies

    Nov 2, 2017
    Hi, I worked on the Profiler Analyzer and can help you with some advice.
    I should start by mentioning that 1.0.2 removes the need to 'turn off record button' in the flow you listed above. This was a step we introduced in 1.0.0 but have since removed the need for, after getting useful feedback on it being one extra step that was undesirable.

    To toggle the Profiler record button in code in Unity versions higher than 2017.4 you can use

    ProfilerDriver.enabled = true;

    Currently we only expose a very small amount of Profiler Analyzer API to code.
    See here:

    Its on the backlog to add more API to allow driving via script.
    I'll raise the priority based on your feedback.

    In the short term you could copy the Profiler Analyzer package into your Assets folder and modify Editor\ProfilerAnalyzerWindow.cs to expose a new public API. E.g adding

    public bool PullDataFromProfiler()
    if (IsAnalysisRunning())
    return false;

    if (!IsProfilerWindowOpen())
    return false;

    if (m_PullFirstFrameindex == 0 && m_PullLastFrameindex == 0)
    return false; // No data

    PullFromProfiler(m_PullFirstFrameindex, m_PullLastFrameindex, m_ProfileSingleView, m_FrameTimeGraph);
    UpdateActiveTab(true, false);

    return true;

    Then your Analyze function could then be augmented with

    UnityEngine.Object[] windows = Resources.FindObjectsOfTypeAll(typeof(ProfileAnalyzerWindow));
    if (windows != null && windows.Length > 0)
    ProfileAnalyzerWindow profileAnalyzerWindow = windows[0] as ProfileAnalyzerWindow;
  3. Ruhan-_-


    Sep 14, 2016
    @lyndon_unity Thanks a lot for the quick response!

    That was exactly what I was looking for, but updating to 1.0.2 no longer warrants a need for any API calls :D at least for me.

    I can still see some use out of "Pull Data" being accessible via a shortcut key. Is there one already? Otherwise if possible please expose it via the method you described in a future release. Not a fan of manually editing packages only to have custom changes removed when next update is required :p

    And I can see you guys fixed that weird issue in 1.0.2 with double profiler windows appearing when docked next to profile analyzer which made the first docked profiler window break and show "Failed to load". I am not sure if that one was on your radar, didn't find a post on it but loving this update! Anywho, thanks again!

    Also is there a possibility of showing garbage collection amount on profile analyzer? In order to see differences? I think this is BADLY necessary since the tool aims at helping us improve game performance
    Right now the only way to see garbage is on profiler window, no way to compare two sessions
    Last edited: Jul 4, 2020