I need to know please if I can save the profiler statistics (http://docs.unity3d.com/Manual/ProfilerWindow.html) and/or Unity Rendering Statistics (the overlay window that shows realtime statistics) - http://docs.unity3d.com/Manual/RenderingStatistics.html - into a file like a CSV or an Excel or even a txt file so I can later study them and do some statistical analysis on them.
How can I save Unity Statistics or Unity Profiler Statistics (stats on CPU, Rendering, Memory...) in a file (text or CSV ...)?
Asked Answered
Maybe thisarticle can help you: packtpub.com/mapt/book/game-development/9781785884580/1/… –
Mercurochrome
Yep, you can.
Saving profiler data:
// write FPS to "profilerLog.txt"
Profiler.logFile = Application.persistentDataPath + "/profilerLog.txt";
// write Profiler Data to "profilerLog.txt.data"
Profiler.enableBinaryLog = true;
Profiler.enabled = true;
Then you can show this data in editor:
Profiler.AddFramesFromFile(Application.dataPath + "/profilerLog.txt");
Saving statistics:
You can use any serialization method you want/like. Just use data from UnityEditor.UnityStats
. Remember that it's only available from Editor.
This class looks like this, autocompletion should help:
public sealed class UnityStats {
public static extern int drawCalls
public static extern int batchedDrawCalls
public static extern int batches
public static extern int triangles
public static extern int vertices
public static extern int shadowCasters
public static extern int renderTextureChanges
public static extern float frameTime
public static extern float renderTime
public static extern int renderTextureCount
public static extern int renderTextureBytes
public static extern int usedTextureMemorySize
public static extern int usedTextureCount
public static extern string screenRes
public static extern int screenBytes
public static extern int vboTotal
public static extern int vboTotalBytes
public static extern int vboUploads
public static extern int vboUploadBytes
public static extern int ibUploads
public static extern int ibUploadBytes
public static extern int visibleSkinnedMeshes
public static extern int visibleAnimations
public static extern string GetNetworkStats(int i);
}
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
using UnityEditor;
using UnityEditorInternal;
var firstFrameIndex = ProfilerDriver.firstFrameIndex;
var lastFrameIndex = ProfilerDriver.lastFrameIndex;
var profilerSortColumn = ProfilerColumn.TotalTime;
var viewType = ProfilerViewType.Hierarchy;
var profilerData = new ProfilerData();
for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex)
{
var property = new ProfilerProperty();
property.SetRoot(frameIndex, profilerSortColumn, viewType);
property.onlyShowGPUSamples = false;
bool enterChildren = true;
while (property.Next(enterChildren))
{
// get all the desired ProfilerColumn
var name = property.GetColumn(ProfilerColumn.FunctionName);
var totalTime = property.GetColumn(ProfilerColumn.TotalTime);
// store values somewhere
}
property.Cleanup();
}
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.
© 2022 - 2024 — McMap. All rights reserved.