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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Viewing a longer profiler sample time?

Discussion in 'Editor & General Support' started by Lawlcat, Aug 8, 2016.

  1. Lawlcat

    Lawlcat

    Joined:
    Jul 24, 2015
    Posts:
    1
    I'm attempting to do a long profile of my application... it will run in a demo mode and switch scenes every 60 seconds or so, orbiting the camera during that time. I am recording profiling data to a file via

    Profiler.enableBinaryLog = true;
    Profiler.logFile = logPath;
    Profiler.enabled = true;

    And I can record hundreds of megabytes of data. However when I try to view this data using an editor script to call Profiler.AddFramesFromFile() on this, I am unable to actually view all of this data.

    After the full demo is run, the profiler data shows 12417 frames, however the earliest frame I can look at is 12,119. This is about 4-5 seconds worth of frame data, despite recording 500 megabytes and for over 3 minutes.

    Where is the rest of the frames? How can I view them? Am I really going to just have to close and restart the profiler every 4 seconds in my app and generate a hundred log files?
     
    rh_galaxy likes this.
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    I think the profiler window is hard-wired to only show a very small portion of the captured profiling data.

    You *may* be able to hack out something on your own by reverse engineering how the profiler window works (using any C# decompiler such as Reflector, DotPeek or even MonoDevelop's decompilation capabilities).

    Having a quick look, there are many different classes involved. One of them is ProfilerDriver, which seems to some properties related to the first and last frame index. It would be interesting to see what these point to after loading your profile data file (simply print ProfilerDriver.lastFrameIndex and ProfilerDriver.firstFrameIndex).

    Another interesting thing to look at is the ProfilerWindow class. This is actually the class that draws the profiler window (well, with the help of other auxiliary classes).

    In this method you can see how it repaints all profiler windows (i guess you can have multiple ones), based on a private field (m_LastFrameFromTick) which gets synced up from the property in ProfilerDriver.

    Perhaps you can use some reflection hackery to manually set this index every time to a different value, causing the profiler window to actually show data from a different location in your file ?

    Let me know how the hacking went :)

    upload_2016-8-10_1-31-31.png
     
  3. pachash

    pachash

    Joined:
    Apr 2, 2014
    Posts:
    55
  4. rh_galaxy

    rh_galaxy

    Joined:
    Jan 13, 2019
    Posts:
    8
    It seems it is true, you have to generate hundreds of log files in order to view more than a few frames.

    I did this:

    Code (CSharp):
    1. Declaration
    2. #if LOGPROFILERDATA
    3.     int logProfilerFrameCnt = 0;
    4.     int logProfilerFileCnt = 0;
    5. #endif
    6.  
    7. Awake()
    8. #if LOGPROFILERDATA
    9.         Profiler.logFile = "log" + logProfilerFileCnt.ToString();
    10.         Profiler.enableBinaryLog = true;
    11.         Profiler.enabled = true;
    12. #endif
    13.  
    14. Update()
    15. #if LOGPROFILERDATA
    16.         //unity profiler log files can only be viewed 300 frames at a time!?
    17.         logProfilerFrameCnt++;
    18.         if(logProfilerFrameCnt>300)
    19.         {
    20.             logProfilerFileCnt++;
    21.             logProfilerFrameCnt = 0;
    22.             Profiler.logFile = "log" + logProfilerFileCnt.ToString();
    23.         }
    24. #endif