Skip to content

Commit 9e45f6c

Browse files
committed
Added method to parse data version from commandline
Implemented parsing of V2 data format Updated IParser interface to pass down Data Version
1 parent 1f3d75c commit 9e45f6c

File tree

4 files changed

+140
-9
lines changed

4 files changed

+140
-9
lines changed

UnityPerformanceBenchmarkReporter/IParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace UnityPerformanceBenchmarkReporter
44
{
55
public interface IParser
66
{
7-
public PerformanceTestRun Parse(string path);
7+
public PerformanceTestRun Parse(string path,int version);
88
}
99
}

UnityPerformanceBenchmarkReporter/PerformanceBenchmark.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class PerformanceBenchmark
1414
public readonly TestRunMetadataProcessor TestRunMetadataProcessor;
1515
private ESupportedFileTypes fileExtension = ESupportedFileTypes.xml;
1616
public ESupportedFileTypes FileType { get { return fileExtension; } }
17+
18+
public int DataVersion { get; private set; } = 2;
1719
public PerformanceBenchmark(Dictionary<Type, string[]> configFieldNames = null)
1820
{
1921
// Default significant figures to use for non-integer metrics if user doesn't specify another value.
@@ -84,7 +86,7 @@ private void AddTestResults(
8486

8587
foreach (var fileNamePath in fileNamePaths)
8688
{
87-
var performanceTestRun = testResultParser.Parse(fileNamePath);
89+
var performanceTestRun = testResultParser.Parse(fileNamePath,DataVersion);
8890
if (performanceTestRun != null && performanceTestRun.Results.Any())
8991
{
9092
perfTestRuns.Add(
@@ -98,7 +100,7 @@ private void AddTestResults(
98100
for (var i = 0; i < resultFilesOrderedByResultName.Length; i++)
99101
{
100102
var performanceTestRun =
101-
testResultParser.Parse(resultFilesOrderedByResultName[i].Key);
103+
testResultParser.Parse(resultFilesOrderedByResultName[i].Key,DataVersion);
102104

103105
if (performanceTestRun != null && performanceTestRun.Results.Any())
104106
{
@@ -129,7 +131,16 @@ private void AddTestResults(
129131
}
130132
}
131133

132-
internal void SetFileType(string filetype)
134+
public void SetDataVersion(string version)
135+
{
136+
if(int.TryParse(version,out int result)){
137+
DataVersion = result;
138+
}else{
139+
throw new ArgumentException($"{version} is not a valid data format version");
140+
}
141+
}
142+
143+
public void SetFileType(string filetype)
133144
{
134145
if (String.IsNullOrEmpty(filetype))
135146
return;
@@ -140,7 +151,7 @@ internal void SetFileType(string filetype)
140151
}
141152
else
142153
{
143-
System.Console.WriteLine($"Failed to Parse FileType Parameter {filetype}");
154+
throw new ArgumentException($"{filetype} is not a valid file format");
144155
}
145156
}
146157

UnityPerformanceBenchmarkReporter/TestResultJsonParser.cs

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace UnityPerformanceBenchmarkReporter
1212
{
1313
public class TestResultJsonParser : IParser
1414
{
15-
public PerformanceTestRun Parse(string path)
15+
public PerformanceTestRun Parse(string path, int version)
1616
{
1717
string report = "";
1818
try
@@ -34,13 +34,22 @@ public PerformanceTestRun Parse(string path)
3434
throw;
3535
}
3636

37-
return ParseJson(report);
37+
switch (version)
38+
{
39+
case 1:
40+
return ParseJsonV1(report);
41+
case 2:
42+
return ParseJsonV2(report);
43+
default:
44+
return null;
45+
}
3846
}
3947

40-
private static PerformanceTestRun ParseJson(string json)
48+
private static PerformanceTestRun ParseJsonV1(string json)
4149
{
4250

4351
PerformanceTestRun result;
52+
4453
try
4554
{
4655
result = JsonConvert.DeserializeObject<PerformanceTestRun>(json);
@@ -55,6 +64,117 @@ private static PerformanceTestRun ParseJson(string json)
5564
return result;
5665
}
5766

67+
private static PerformanceTestRun ParseJsonV2(string json)
68+
{
69+
70+
Run run = null;
71+
try
72+
{
73+
run = JsonConvert.DeserializeObject<Run>(json);
74+
}
75+
catch (System.Exception)
76+
{
77+
throw;
78+
}
79+
80+
if (run != null)
81+
{
82+
var testRun = new PerformanceTestRun()
83+
{
84+
BuildSettings = new BuildSettings()
85+
{
86+
Platform = run.Player.Platform,
87+
BuildTarget = run.Player.BuildTarget,
88+
DevelopmentPlayer = true,
89+
AndroidBuildSystem = run.Player.AndroidBuildSystem
90+
},
91+
EditorVersion = new EditorVersion()
92+
{
93+
Branch = run.Editor.Branch,
94+
DateSeconds = run.Editor.Date,
95+
FullVersion = $"{run.Editor.Version} ({run.Editor.Changeset})",
96+
RevisionValue = 0
97+
},
98+
PlayerSettings = new PlayerSettings()
99+
{
100+
GpuSkinning = run.Player.GpuSkinning,
101+
GraphicsApi = run.Player.GraphicsApi,
102+
RenderThreadingMode = run.Player.RenderThreadingMode,
103+
ScriptingBackend = run.Player.ScriptingBackend,
104+
AndroidTargetSdkVersion = run.Player.AndroidTargetSdkVersion,
105+
EnabledXrTargets = new List<string>(),
106+
ScriptingRuntimeVersion = "",
107+
StereoRenderingPath = run.Player.StereoRenderingPath
108+
},
109+
QualitySettings = new QualitySettings()
110+
{
111+
Vsync = run.Player.Vsync,
112+
AntiAliasing = run.Player.AntiAliasing,
113+
AnisotropicFiltering = run.Player.AnisotropicFiltering,
114+
BlendWeights = run.Player.BlendWeights,
115+
ColorSpace = run.Player.ColorSpace
116+
},
117+
ScreenSettings = new ScreenSettings()
118+
{
119+
Fullscreen = run.Player.Fullscreen,
120+
ScreenHeight = run.Player.ScreenHeight,
121+
ScreenWidth = run.Player.ScreenWidth,
122+
ScreenRefreshRate = run.Player.ScreenRefreshRate
123+
},
124+
PlayerSystemInfo = new Entities.PlayerSystemInfo()
125+
{
126+
DeviceModel = run.Hardware.DeviceModel,
127+
DeviceName = run.Hardware.DeviceName,
128+
OperatingSystem = run.Hardware.OperatingSystem,
129+
ProcessorCount = run.Hardware.ProcessorCount,
130+
ProcessorType = run.Hardware.ProcessorType,
131+
GraphicsDeviceName = run.Hardware.GraphicsDeviceName,
132+
SystemMemorySize = run.Hardware.SystemMemorySizeMB,
133+
XrDevice = run.Hardware.XrDevice,
134+
XrModel = run.Hardware.XrModel
135+
},
136+
StartTime = run.Date,
137+
TestSuite = run.TestSuite,
138+
Results = new List<PerformanceTestResult>()
139+
};
140+
141+
testRun.EndTime = DateTime.Now.ToUniversalTime()
142+
.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
143+
.TotalMilliseconds;
144+
145+
foreach (var res in run.Results)
146+
{
147+
var pt = new PerformanceTestResult()
148+
{
149+
TestCategories = res.Categories,
150+
TestName = res.Name,
151+
TestVersion = res.Version,
152+
SampleGroups = res.SampleGroups.Select(sg => new Entities.SampleGroup
153+
{
154+
Samples = sg.Samples,
155+
Average = sg.Average,
156+
Max = sg.Max,
157+
Median = sg.Median,
158+
Min = sg.Min,
159+
Sum = sg.Sum,
160+
StandardDeviation = sg.StandardDeviation,
161+
SampleCount = sg.Samples.Count,
162+
Definition = new SampleGroupDefinition()
163+
{
164+
Name = sg.Name,
165+
SampleUnit = (Entities.SampleUnit)sg.Unit,
166+
IncreaseIsBetter = sg.IncreaseIsBetter
167+
}
168+
}).ToList()
169+
};
170+
testRun.Results.Add(pt);
171+
}
172+
173+
return testRun;
174+
}
175+
176+
return null;
177+
}
58178

59179
}
60180
}

UnityPerformanceBenchmarkReporter/TestResultXmlParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace UnityPerformanceBenchmarkReporter
1212
{
1313
public class TestResultXmlParser : IParser
1414
{
15-
public PerformanceTestRun Parse(string path)
15+
public PerformanceTestRun Parse(string path,int version)
1616
{
1717
var xmlDocument = XDocument.Load(path);
1818
return Parse(xmlDocument);

0 commit comments

Comments
 (0)