@@ -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+ }
0 commit comments