Skip to content

Commit a190aca

Browse files
Cleanup refactor
1 parent 5afe3dd commit a190aca

File tree

10 files changed

+805
-958
lines changed

10 files changed

+805
-958
lines changed

UnityPerformanceBenchmarkReporter/Entities/PerformanceTestRun.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class QualitySettings
7373
public class PlayerSettings
7474
{
7575
public string ScriptingBackend;
76+
public string ScriptingRuntimeVersion;
7677
public bool VrSupported;
7778
public bool MtRendering;
7879
public bool GraphicsJobs;

UnityPerformanceBenchmarkReporter/Entities/PerformanceTestRunResult.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ public class PerformanceTestRunResult
1717
public List<TestResult> TestResults = new List<TestResult>();
1818
public bool IsBaseline;
1919
public string ResultName;
20+
21+
public bool TestRunMetadataExists()
22+
{
23+
return PlayerSystemInfo != null
24+
|| PlayerSettings != null
25+
|| QualitySettings != null
26+
|| ScreenSettings != null
27+
|| BuildSettings != null
28+
|| EditorVersion != null;
29+
}
2030
}
2131
}

UnityPerformanceBenchmarkReporter/MetadataValidator.cs

Lines changed: 0 additions & 444 deletions
This file was deleted.

UnityPerformanceBenchmarkReporter/OptionsParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ private OptionSet GetOptions(PerformanceBenchmark performanceBenchmark)
6565
.Add("results|testresultsxmlsource=", "REQUIRED - Path to a test result XML filename OR directory. Directories are searched resursively. You can repeat this option with multiple result file or directory paths.",
6666
xmlsource =>
6767
{
68-
performanceBenchmark.AddXmlSourcePath(xmlsource, "testresultsxmlsource", ResultType.Test);
68+
performanceBenchmark.AddXmlSourcePath(xmlsource, "results", ResultType.Test);
6969
})
7070
.Add("baseline|baselinexmlsource:", "OPTIONAL - Path to a baseline XML filename.",
7171
xmlsource =>
7272
{
73-
performanceBenchmark.AddXmlSourcePath(xmlsource, "baselinexmlsource", ResultType.Baseline);
73+
performanceBenchmark.AddXmlSourcePath(xmlsource, "baseline", ResultType.Baseline);
7474
})
7575
.Add("report|reportdirpath:", "OPTIONAL - Path to where the report will be written. Default is current working directory.",
7676
performanceBenchmark.AddReportDirPath);

UnityPerformanceBenchmarkReporter/PerformanceBenchmark.cs

Lines changed: 53 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,61 @@ namespace UnityPerformanceBenchmarkReporter
99
{
1010
public class PerformanceBenchmark
1111
{
12-
public HashSet<string> ResultXmlFilePaths { get; } = new HashSet<string>();
13-
public HashSet<string> ResultXmlDirectoryPaths { get; } = new HashSet<string>();
14-
public HashSet<string> BaselineXmlFilePaths { get; } = new HashSet<string>();
15-
public HashSet<string> BaselineXmlDirectoryPaths { get; } = new HashSet<string>();
16-
public uint SigFig { get; private set; }
17-
public string ReportDirPath { get; private set; }
18-
19-
public readonly MetadataValidator MetadataValidator = new MetadataValidator();
20-
21-
private bool firstResult = true;
22-
private string firstTestRunResultPath;
23-
private PerformanceTestRun firstTestRun = new PerformanceTestRun();
2412
private readonly PerformanceTestRunProcessor performanceTestRunProcessor = new PerformanceTestRunProcessor();
25-
private readonly string xmlFileExtension = ".xml";
26-
private readonly Dictionary<string, string[]> excludedConfigFieldNames = new Dictionary<string, string[]>();
27-
28-
29-
public bool BaselineResultFilesExist => BaselineXmlFilePaths.Any() || BaselineXmlDirectoryPaths.Any();
3013

31-
public bool ResultFilesExist => ResultXmlFilePaths.Any() || ResultXmlDirectoryPaths.Any();
14+
public readonly TestRunMetadataProcessor TestRunMetadataProcessor;
15+
private readonly string xmlFileExtension = ".xml";
3216

33-
public PerformanceBenchmark(Dictionary<string, string[]> configFieldNames = null)
17+
public PerformanceBenchmark(Dictionary<Type, string[]> configFieldNames = null)
3418
{
3519
// Default significant figures to use for non-integer metrics if user doesn't specify another value.
3620
// Most values are in milliseconds or a count of something, so using more often creates an artificial baseline
3721
// failure based on insignificant digits equating to a microsecond, or less, time difference. The Unity Profiler only shows
3822
// up to 2 significant figures for milliseconds as well, so this is what folks are used to working with.
3923
SigFig = 2;
40-
41-
if (configFieldNames != null)
42-
{
43-
excludedConfigFieldNames = configFieldNames;
44-
}
24+
TestRunMetadataProcessor = new TestRunMetadataProcessor(configFieldNames);
4525
}
4626

27+
public HashSet<string> ResultXmlFilePaths { get; } = new HashSet<string>();
28+
public HashSet<string> ResultXmlDirectoryPaths { get; } = new HashSet<string>();
29+
public HashSet<string> BaselineXmlFilePaths { get; } = new HashSet<string>();
30+
public uint SigFig { get; }
31+
public string ReportDirPath { get; private set; }
32+
33+
34+
public bool BaselineResultFilesExist => BaselineXmlFilePaths.Any();
35+
36+
public bool ResultFilesExist => ResultXmlFilePaths.Any() || ResultXmlDirectoryPaths.Any();
37+
4738
public void AddPerformanceTestRunResults(
48-
TestResultXmlParser testResultXmlParser,
49-
List<PerformanceTestRunResult> performanceTestRunResults,
50-
List<TestResult> testResults,
39+
TestResultXmlParser testResultXmlParser,
40+
List<PerformanceTestRunResult> performanceTestRunResults,
41+
List<TestResult> testResults,
5142
List<TestResult> baselineTestResults)
5243
{
53-
AddTestResults(testResultXmlParser, performanceTestRunResults, testResults, baselineTestResults, ResultXmlDirectoryPaths, ResultXmlFilePaths);
44+
AddTestResults(testResultXmlParser, performanceTestRunResults, testResults, baselineTestResults,
45+
ResultXmlDirectoryPaths, ResultXmlFilePaths);
5446
}
5547

5648
public void AddBaselinePerformanceTestRunResults(
57-
TestResultXmlParser testResultXmlParser,
58-
List<PerformanceTestRunResult> baselinePerformanceTestRunResults,
49+
TestResultXmlParser testResultXmlParser,
50+
List<PerformanceTestRunResult> baselinePerformanceTestRunResults,
5951
List<TestResult> baselineTestResults)
6052
{
61-
AddTestResults(testResultXmlParser, baselinePerformanceTestRunResults, baselineTestResults, baselineTestResults, BaselineXmlDirectoryPaths, BaselineXmlFilePaths, true);
53+
AddTestResults(testResultXmlParser, baselinePerformanceTestRunResults, baselineTestResults,
54+
baselineTestResults, null, BaselineXmlFilePaths, true);
6255
}
6356

6457
private void AddTestResults(
65-
TestResultXmlParser testResultXmlParser,
66-
List<PerformanceTestRunResult> runResults,
67-
List<TestResult> testResults,
58+
TestResultXmlParser testResultXmlParser,
59+
List<PerformanceTestRunResult> testRunResults,
60+
List<TestResult> testResults,
6861
List<TestResult> baselineTestResults,
69-
HashSet<string> xmlDirectoryPaths,
62+
HashSet<string> xmlDirectoryPaths,
7063
HashSet<string> xmlFileNamePaths,
7164
bool isBaseline = false)
7265
{
73-
if (!isBaseline && xmlDirectoryPaths.Any())
66+
if (!isBaseline && xmlDirectoryPaths != null && xmlDirectoryPaths.Any())
7467
{
7568
foreach (var xmlDirectory in xmlDirectoryPaths)
7669
{
@@ -92,36 +85,44 @@ private void AddTestResults(
9285
var performanceTestRun = testResultXmlParser.GetPerformanceTestRunFromXml(xmlFileNamePath);
9386
if (performanceTestRun != null && performanceTestRun.Results.Any())
9487
{
95-
perfTestRuns.Add( new KeyValuePair<string, PerformanceTestRun>(xmlFileNamePath, performanceTestRun));
88+
perfTestRuns.Add(
89+
new KeyValuePair<string, PerformanceTestRun>(xmlFileNamePath, performanceTestRun));
9690
}
9791
}
9892

99-
perfTestRuns.Sort((run1, run2) => run1.Value.StartTime.CompareTo(run2.Value.StartTime));
100-
var resultFilesOrderByStartTime = perfTestRuns.ToArray();
93+
perfTestRuns.Sort((run1, run2) => string.Compare(run1.Key, run2.Key, StringComparison.Ordinal));
94+
var resultFilesOrderedByResultName = perfTestRuns.ToArray();
10195

102-
for (var i = 0; i < resultFilesOrderByStartTime.Length; i++)
96+
for (var i = 0; i < resultFilesOrderedByResultName.Length; i++)
10397
{
104-
var performanceTestRun = testResultXmlParser.GetPerformanceTestRunFromXml(resultFilesOrderByStartTime[i].Key);
98+
var performanceTestRun =
99+
testResultXmlParser.GetPerformanceTestRunFromXml(resultFilesOrderedByResultName[i].Key);
105100

106101
if (performanceTestRun != null && performanceTestRun.Results.Any())
107102
{
108103
var results = performanceTestRunProcessor.GetTestResults(performanceTestRun);
109104
if (!results.Any())
110105
{
111106
Console.ForegroundColor = ConsoleColor.Yellow;
112-
Console.WriteLine("No performance test data found to report in: {0}", resultFilesOrderByStartTime[i].Key);
107+
Console.WriteLine("No performance test data found to report in: {0}",
108+
resultFilesOrderedByResultName[i].Key);
113109
Console.ResetColor();
110+
continue;
114111
}
112+
115113
testResults.AddRange(results);
116114

117-
performanceTestRunProcessor.UpdateTestResultsBasedOnBaselineResults(baselineTestResults, testResults, SigFig);
115+
performanceTestRunProcessor.UpdateTestResultsBasedOnBaselineResults(baselineTestResults,
116+
testResults, SigFig);
118117

119-
ValidateMetadata(performanceTestRun, resultFilesOrderByStartTime[i].Key);
120-
runResults.Add(performanceTestRunProcessor.CreateTestRunResult
118+
TestRunMetadataProcessor.ProcessMetadata(performanceTestRun,
119+
resultFilesOrderedByResultName[i].Key);
120+
121+
testRunResults.Add(performanceTestRunProcessor.CreateTestRunResult
121122
(
122123
performanceTestRun,
123124
results,
124-
Path.GetFileNameWithoutExtension(resultFilesOrderByStartTime[i].Key),
125+
Path.GetFileNameWithoutExtension(resultFilesOrderedByResultName[i].Key),
125126
isBaseline)
126127
);
127128
}
@@ -132,36 +133,11 @@ private void AddTestResults(
132133
private IEnumerable<string> GetAllXmlFileNames(string xmlDirectory)
133134
{
134135
var dir = new DirectoryInfo(xmlDirectory);
135-
var xmlFileNames = dir.GetFiles("*" + xmlFileExtension, SearchOption.AllDirectories).Select(f => f.FullName);
136+
var xmlFileNames = dir.GetFiles("*" + xmlFileExtension, SearchOption.AllDirectories)
137+
.Select(f => f.FullName);
136138
return xmlFileNames;
137139
}
138140

139-
private void ValidateMetadata(PerformanceTestRun performanceTestRun, string xmlFileNamePath)
140-
{
141-
if (firstResult)
142-
{
143-
firstTestRunResultPath = xmlFileNamePath;
144-
firstTestRun = performanceTestRun;
145-
firstResult = false;
146-
}
147-
else
148-
{
149-
MetadataValidator.ValidatePlayerSystemInfo(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath, ExcludedFieldNames<PlayerSystemInfo>());
150-
MetadataValidator.ValidatePlayerSettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath, ExcludedFieldNames<PlayerSettings>());
151-
MetadataValidator.ValidateQualitySettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath, ExcludedFieldNames<QualitySettings>());
152-
MetadataValidator.ValidateScreenSettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath, ExcludedFieldNames<ScreenSettings>());
153-
MetadataValidator.ValidateBuildSettings(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath, ExcludedFieldNames<BuildSettings>());
154-
MetadataValidator.ValidateEditorVersion(firstTestRun, performanceTestRun, firstTestRunResultPath, xmlFileNamePath, ExcludedFieldNames<EditorVersion>());
155-
}
156-
}
157-
158-
private string[] ExcludedFieldNames<T>()
159-
{
160-
return excludedConfigFieldNames.ContainsKey(typeof(T).Name)
161-
? excludedConfigFieldNames[typeof(T).Name]
162-
: null;
163-
}
164-
165141
public void AddXmlSourcePath(string xmlSourcePath, string optionName, OptionsParser.ResultType resultType)
166142
{
167143
if (string.IsNullOrEmpty(xmlSourcePath))
@@ -196,21 +172,12 @@ private void ProcessAsXmlDirectory(string xmlSourcePath, string optionName, Opti
196172
var xmlFileNames = GetAllXmlFileNames(xmlSourcePath).ToArray();
197173
if (!xmlFileNames.Any())
198174
{
199-
throw new ArgumentException(string.Format("{0} directory `{1}` doesn't contain any .xml files.", optionName,
175+
throw new ArgumentException(string.Format("{0} directory `{1}` doesn't contain any .xml files.",
176+
optionName,
200177
xmlSourcePath));
201178
}
202179

203-
switch (resultType)
204-
{
205-
case OptionsParser.ResultType.Test:
206-
ResultXmlDirectoryPaths.Add(xmlSourcePath);
207-
break;
208-
case OptionsParser.ResultType.Baseline:
209-
BaselineXmlDirectoryPaths.Add(xmlSourcePath);
210-
break;
211-
default:
212-
throw new InvalidEnumArgumentException(resultType.ToString());
213-
}
180+
ResultXmlDirectoryPaths.Add(xmlSourcePath);
214181
}
215182

216183
private void ProcessAsXmlFile(string xmlSourcePath, string optionName, OptionsParser.ResultType resultType)
@@ -237,10 +204,5 @@ public void AddReportDirPath(string reportDirectoryPath)
237204
{
238205
ReportDirPath = reportDirectoryPath;
239206
}
240-
241-
public void AddSigFig(uint sigFig)
242-
{
243-
SigFig = sigFig;
244-
}
245207
}
246-
}
208+
}

UnityPerformanceBenchmarkReporter/Program.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ namespace UnityPerformanceBenchmarkReporter
88
{
99
internal class Program
1010
{
11-
private static readonly Dictionary<string, string[]> ExcludedConfigFieldNames = new Dictionary<string, string[]>
11+
private static readonly Dictionary<Type, string[]> ExcludedConfigFieldNames = new Dictionary<Type, string[]>
1212
{
13-
{typeof(EditorVersion).Name, new []{"DateSeconds", "RevisionValue", "Branch"}},
14-
{typeof(PlayerSettings).Name, new []{"MtRendering", "GraphicsJobs"}}
13+
{typeof(EditorVersion), new []
14+
{
15+
"DateSeconds",
16+
"RevisionValue",
17+
"Branch"
18+
}},
19+
{typeof(PlayerSettings), new []
20+
{
21+
"MtRendering", // Hidden because we have a calculated field, RenderThreadingMode, that provides a more succinct value (SingleThreaded, MultiThreaded, GfxJobs)
22+
"GraphicsJobs", // Hidden because we have a calculated field, RenderThreadingMode, that provides a more succinct value (SingleThreaded, MultiThreaded, GfxJobs)
23+
"VrSupported" // Hidden because this value doesn't seem to be coming through as 'True' when it should be true.
24+
}}
1525
};
1626

1727
private static void Main(string[] args)
@@ -55,10 +65,29 @@ private static void Main(string[] args)
5565
}
5666
}
5767

58-
var reportWriter = new ReportWriter(ExcludedConfigFieldNames);
68+
var performanceTestResults = new PerformanceTestRunResult[0];
69+
70+
if (aggregateTestRunResults.Any(a => a.IsBaseline))
71+
{
72+
Array.Resize(ref performanceTestResults, 1);
73+
performanceTestResults[0] = aggregateTestRunResults.First(a => a.IsBaseline);
74+
}
75+
76+
var nonBaselineTestRunResults = aggregateTestRunResults.Where(a => !a.IsBaseline).ToList();
77+
78+
nonBaselineTestRunResults.Sort((run1, run2) => string.Compare(run1.ResultName, run2.ResultName, StringComparison.Ordinal));
79+
80+
81+
foreach (var performanceTestRunResult in nonBaselineTestRunResults)
82+
{
83+
Array.Resize(ref performanceTestResults, performanceTestResults.Length + 1);
84+
performanceTestResults[performanceTestResults.Length - 1] = performanceTestRunResult;
85+
}
86+
87+
88+
var reportWriter = new ReportWriter(performanceBenchmark.TestRunMetadataProcessor);
5989
reportWriter.WriteReport(
60-
aggregateTestRunResults,
61-
performanceBenchmark.MetadataValidator,
90+
performanceTestResults,
6291
performanceBenchmark.SigFig,
6392
performanceBenchmark.ReportDirPath,
6493
performanceBenchmark.BaselineResultFilesExist);

0 commit comments

Comments
 (0)