forked from steve3003/unity-profiler-data-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfilerData.cs
125 lines (111 loc) · 3.95 KB
/
ProfilerData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using UnityEditorInternal;
using UnityEngine;
namespace ProfilerDataExporter
{
[Serializable]
public class ProfilerData
{
public List<FrameData> frames = new List<FrameData>();
public override string ToString()
{
return JsonUtility.ToJson(this);
}
public static ProfilerData GetProfilerData(int firstFrameIndex, int lastFrameIndex, string selectedPropertyPath = "")
{
var profilerSortColumn = ProfilerColumn.TotalTime;
var viewType = ProfilerViewType.Hierarchy;
var property = new ProfilerProperty();
var profilerData = new ProfilerData();
for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex)
{
property.SetRoot(frameIndex, profilerSortColumn, viewType);
property.onlyShowGPUSamples = false;
var frameData = new FrameData();
const bool enterChildren = true;
while (property.Next(enterChildren))
{
bool shouldSaveProperty = string.IsNullOrEmpty(selectedPropertyPath) || property.propertyPath == selectedPropertyPath;
if (shouldSaveProperty)
{
var functionData = FunctionData.Create(property);
frameData.functions.Add(functionData);
//Debug.Log(functionData.ToString());
}
}
property.Cleanup();
profilerData.frames.Add(frameData);
//Debug.Log(frameData.ToString());
}
//Debug.Log(profilerData.ToString());
return profilerData;
}
}
[Serializable]
public class FrameData
{
public List<FunctionData> functions = new List<FunctionData>();
public override string ToString()
{
return JsonUtility.ToJson(this);
}
}
[Serializable]
public class FunctionData
{
private static readonly string[] ColumnNames = Enum.GetNames(typeof(ProfilerColumn));
public string functionPath;
public FunctionDataValue[] values;
public string GetValue(ProfilerColumn column)
{
var columnName = ColumnNames[(int)column];
return FindDataValue(columnName).value;
}
private FunctionDataValue FindDataValue(string columnName)
{
int length = values.Length;
for (int i = 0; i < length; ++i)
{
var value = values[i];
if (value.column == columnName)
{
return value;
}
}
return default(FunctionDataValue);
}
public override string ToString()
{
return JsonUtility.ToJson(this);
}
public static FunctionData Create(ProfilerProperty property)
{
var functionData = new FunctionData();
var columns = Enum.GetValues(typeof(ProfilerColumn));
functionData.values = new FunctionDataValue[columns.Length];
functionData.functionPath = property.propertyPath;
for (int i = 0; i < columns.Length; ++i)
{
var column = (ProfilerColumn)columns.GetValue(i);
#if UNITY_5_5_OR_NEWER
if (column == ProfilerColumn.DontSort)
{
continue;
}
#endif
var functionDataValue = new FunctionDataValue();
functionDataValue.column = column.ToString();
functionDataValue.value = property.GetColumn(column);
functionData.values[i] = functionDataValue;
}
return functionData;
}
}
[Serializable]
public class FunctionDataValue
{
public string column;
public string value;
}
}