@@ -9,68 +9,61 @@ namespace UnityPerformanceBenchmarkReporter
9
9
{
10
10
public class PerformanceBenchmark
11
11
{
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 ( ) ;
24
12
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 ( ) ;
30
13
31
- public bool ResultFilesExist => ResultXmlFilePaths . Any ( ) || ResultXmlDirectoryPaths . Any ( ) ;
14
+ public readonly TestRunMetadataProcessor TestRunMetadataProcessor ;
15
+ private readonly string xmlFileExtension = ".xml" ;
32
16
33
- public PerformanceBenchmark ( Dictionary < string , string [ ] > configFieldNames = null )
17
+ public PerformanceBenchmark ( Dictionary < Type , string [ ] > configFieldNames = null )
34
18
{
35
19
// Default significant figures to use for non-integer metrics if user doesn't specify another value.
36
20
// Most values are in milliseconds or a count of something, so using more often creates an artificial baseline
37
21
// failure based on insignificant digits equating to a microsecond, or less, time difference. The Unity Profiler only shows
38
22
// up to 2 significant figures for milliseconds as well, so this is what folks are used to working with.
39
23
SigFig = 2 ;
40
-
41
- if ( configFieldNames != null )
42
- {
43
- excludedConfigFieldNames = configFieldNames ;
44
- }
24
+ TestRunMetadataProcessor = new TestRunMetadataProcessor ( configFieldNames ) ;
45
25
}
46
26
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
+
47
38
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 ,
51
42
List < TestResult > baselineTestResults )
52
43
{
53
- AddTestResults ( testResultXmlParser , performanceTestRunResults , testResults , baselineTestResults , ResultXmlDirectoryPaths , ResultXmlFilePaths ) ;
44
+ AddTestResults ( testResultXmlParser , performanceTestRunResults , testResults , baselineTestResults ,
45
+ ResultXmlDirectoryPaths , ResultXmlFilePaths ) ;
54
46
}
55
47
56
48
public void AddBaselinePerformanceTestRunResults (
57
- TestResultXmlParser testResultXmlParser ,
58
- List < PerformanceTestRunResult > baselinePerformanceTestRunResults ,
49
+ TestResultXmlParser testResultXmlParser ,
50
+ List < PerformanceTestRunResult > baselinePerformanceTestRunResults ,
59
51
List < TestResult > baselineTestResults )
60
52
{
61
- AddTestResults ( testResultXmlParser , baselinePerformanceTestRunResults , baselineTestResults , baselineTestResults , BaselineXmlDirectoryPaths , BaselineXmlFilePaths , true ) ;
53
+ AddTestResults ( testResultXmlParser , baselinePerformanceTestRunResults , baselineTestResults ,
54
+ baselineTestResults , null , BaselineXmlFilePaths , true ) ;
62
55
}
63
56
64
57
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 ,
68
61
List < TestResult > baselineTestResults ,
69
- HashSet < string > xmlDirectoryPaths ,
62
+ HashSet < string > xmlDirectoryPaths ,
70
63
HashSet < string > xmlFileNamePaths ,
71
64
bool isBaseline = false )
72
65
{
73
- if ( ! isBaseline && xmlDirectoryPaths . Any ( ) )
66
+ if ( ! isBaseline && xmlDirectoryPaths != null && xmlDirectoryPaths . Any ( ) )
74
67
{
75
68
foreach ( var xmlDirectory in xmlDirectoryPaths )
76
69
{
@@ -92,36 +85,44 @@ private void AddTestResults(
92
85
var performanceTestRun = testResultXmlParser . GetPerformanceTestRunFromXml ( xmlFileNamePath ) ;
93
86
if ( performanceTestRun != null && performanceTestRun . Results . Any ( ) )
94
87
{
95
- perfTestRuns . Add ( new KeyValuePair < string , PerformanceTestRun > ( xmlFileNamePath , performanceTestRun ) ) ;
88
+ perfTestRuns . Add (
89
+ new KeyValuePair < string , PerformanceTestRun > ( xmlFileNamePath , performanceTestRun ) ) ;
96
90
}
97
91
}
98
92
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 ( ) ;
101
95
102
- for ( var i = 0 ; i < resultFilesOrderByStartTime . Length ; i ++ )
96
+ for ( var i = 0 ; i < resultFilesOrderedByResultName . Length ; i ++ )
103
97
{
104
- var performanceTestRun = testResultXmlParser . GetPerformanceTestRunFromXml ( resultFilesOrderByStartTime [ i ] . Key ) ;
98
+ var performanceTestRun =
99
+ testResultXmlParser . GetPerformanceTestRunFromXml ( resultFilesOrderedByResultName [ i ] . Key ) ;
105
100
106
101
if ( performanceTestRun != null && performanceTestRun . Results . Any ( ) )
107
102
{
108
103
var results = performanceTestRunProcessor . GetTestResults ( performanceTestRun ) ;
109
104
if ( ! results . Any ( ) )
110
105
{
111
106
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 ) ;
113
109
Console . ResetColor ( ) ;
110
+ continue ;
114
111
}
112
+
115
113
testResults . AddRange ( results ) ;
116
114
117
- performanceTestRunProcessor . UpdateTestResultsBasedOnBaselineResults ( baselineTestResults , testResults , SigFig ) ;
115
+ performanceTestRunProcessor . UpdateTestResultsBasedOnBaselineResults ( baselineTestResults ,
116
+ testResults , SigFig ) ;
118
117
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
121
122
(
122
123
performanceTestRun ,
123
124
results ,
124
- Path . GetFileNameWithoutExtension ( resultFilesOrderByStartTime [ i ] . Key ) ,
125
+ Path . GetFileNameWithoutExtension ( resultFilesOrderedByResultName [ i ] . Key ) ,
125
126
isBaseline )
126
127
) ;
127
128
}
@@ -132,36 +133,11 @@ private void AddTestResults(
132
133
private IEnumerable < string > GetAllXmlFileNames ( string xmlDirectory )
133
134
{
134
135
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 ) ;
136
138
return xmlFileNames ;
137
139
}
138
140
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
-
165
141
public void AddXmlSourcePath ( string xmlSourcePath , string optionName , OptionsParser . ResultType resultType )
166
142
{
167
143
if ( string . IsNullOrEmpty ( xmlSourcePath ) )
@@ -196,21 +172,12 @@ private void ProcessAsXmlDirectory(string xmlSourcePath, string optionName, Opti
196
172
var xmlFileNames = GetAllXmlFileNames ( xmlSourcePath ) . ToArray ( ) ;
197
173
if ( ! xmlFileNames . Any ( ) )
198
174
{
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 ,
200
177
xmlSourcePath ) ) ;
201
178
}
202
179
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 ) ;
214
181
}
215
182
216
183
private void ProcessAsXmlFile ( string xmlSourcePath , string optionName , OptionsParser . ResultType resultType )
@@ -237,10 +204,5 @@ public void AddReportDirPath(string reportDirectoryPath)
237
204
{
238
205
ReportDirPath = reportDirectoryPath ;
239
206
}
240
-
241
- public void AddSigFig ( uint sigFig )
242
- {
243
- SigFig = sigFig ;
244
- }
245
207
}
246
- }
208
+ }
0 commit comments