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

Save Profiler Details to File

Discussion in 'Editor & General Support' started by R-Type, Apr 11, 2013.

  1. R-Type

    R-Type

    Joined:
    Oct 31, 2012
    Posts:
    44
    Is it somehow possible to save the Profiler Details to a file to do statistics on it? I need to do some performance measurements especially on GPU usage. Therefore I need to have a longer sequence of values saved to do some calculation on it.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    It looks like you can only export the Fps per frame (sounds kind of wired) to a file via

    Code (csharp):
    1. Profiler.logFile = "testlogfile.txt";
    But it appears that this is the only data that you can get from the profiler.
     
  3. R-Type

    R-Type

    Joined:
    Oct 31, 2012
    Posts:
    44
    Ok, this is a big deficiency, since details over 300 frames can be inspected directly during runtime. I believe it would be no big effort to provide a save button.
     
  4. FlolF

    FlolF

    Joined:
    Nov 20, 2012
    Posts:
    14
    You can save the output of the profiler (binary data and frames per second) in seperate files. It worked for me on iOS.

    Code (csharp):
    1.  
    2. // write FPS to "profilerLog.txt"
    3. // persistentDataPath, because dataPath seems to be readOnly under iOS
    4. Profiler.logFile = Application.persistentDataPath + "/profilerLog.txt";        
    5. // write Profiler Data to "profilerLog.txt.data"                                                                                        
    6. Profiler.enableBinaryLog = true;                                                 
    7. Profiler.enabled = true;
    8.  
    If you attach the written data file to the asset folder of your unity project, you can display the data in the profiler:

    Code (csharp):
    1.  
    2. Profiler.AddFramesFromFile(Application.dataPath + "/profilerLog.txt");
    3.  
     
    forestrf and liortal like this.
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    How can you store the profiler data *IN THE EDITOR* to a file and then reload it ?
     
  6. Sparrowfc

    Sparrowfc

    Joined:
    Jan 31, 2013
    Posts:
    100
    Still there's no way to resolve the binary data file the extract specific statistics?
    It would be very useful when you want to get the average values of some statistics throughout the time
     
  7. bteitler

    bteitler

    Joined:
    May 11, 2014
    Posts:
    52
    I don't see GPU data when I record data from the player to a log file and load it back into editor. I see CPU and most of the other stats, including Rendering, but not GPU Usage.
     
  8. steve3003

    steve3003

    Joined:
    Nov 5, 2015
    Posts:
    1
    With a look into the ProfilerWindow class on the decompiled unity code (which you may find online) you can easily write a script that exports the data you need.

    The script might look like this

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditorInternal;
    3.  
    4. var firstFrameIndex = ProfilerDriver.firstFrameIndex;
    5. var lastFrameIndex = ProfilerDriver.lastFrameIndex;
    6. var profilerSortColumn = ProfilerColumn.TotalTime;
    7. var viewType = ProfilerViewType.Hierarchy;
    8.  
    9. var profilerData = new ProfilerData();
    10. for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex)
    11. {
    12.     var property = new ProfilerProperty();
    13.     property.SetRoot(frameIndex, profilerSortColumn, viewType);
    14.     property.onlyShowGPUSamples = false;
    15.     bool enterChildren = true;
    16.  
    17.     while (property.Next(enterChildren))
    18.     {
    19.          // get all the desired ProfilerColumn
    20.          var name = property.GetColumn(ProfilerColumn.FunctionName);
    21.          var totalTime = property.GetColumn(ProfilerColumn.TotalTime);
    22.          // store values somewhere
    23.     }
    24.  
    25.     property.Cleanup();
    26. }
    If you want, you can use this script that allows you to export the data as a JSON file and provides also some useful stats when you are profiling.
    https://github.com/steve3003/unity-profiler-data-exporter
     
    Last edited: Feb 6, 2017