4 using System.Collections.Generic;
5 using System.Diagnostics;
9 namespace SiliconStudio.
Paradox.Shaders.Parser.Performance
13 private static int globalCount;
14 private static int loadingCount;
15 private static int typeAnalysisCount;
16 private static int semanticAnalysisCount;
17 private static int mixCount;
18 private static int deepCloneCount;
19 private static int astParsingCount;
21 private static readonly List<long> GlobalTimes =
new List<long>();
22 private static readonly List<long> LoadingTimes =
new List<long>();
23 private static readonly List<long> TypeAnalysisTimes =
new List<long>();
24 private static readonly List<long> SemanticAnalysisTimes =
new List<long>();
25 private static readonly List<long> MixTimes =
new List<long>();
26 private static readonly List<long> DeepcloneTimes =
new List<long>();
27 private static readonly List<long> AstParsingTimes =
new List<long>();
29 private static Stopwatch globalWatch =
new Stopwatch();
30 private static Stopwatch loadingWatch =
new Stopwatch();
31 private static Stopwatch typeAnalysisWatch =
new Stopwatch();
32 private static Stopwatch semanticAnalysisWatch =
new Stopwatch();
33 private static Stopwatch mixWatch =
new Stopwatch();
34 private static Stopwatch deepCloneWatch =
new Stopwatch();
35 private static Stopwatch astParsingWatch =
new Stopwatch();
41 case PerformanceStage.Global:
44 case PerformanceStage.Loading:
47 case PerformanceStage.TypeAnalysis:
48 typeAnalysisWatch.Start();
50 case PerformanceStage.SemanticAnalysis:
51 semanticAnalysisWatch.Start();
53 case PerformanceStage.Mix:
56 case PerformanceStage.DeepClone:
57 deepCloneWatch.Start();
59 case PerformanceStage.AstParsing:
60 astParsingWatch.Start();
69 case PerformanceStage.Global:
72 case PerformanceStage.Loading:
75 case PerformanceStage.TypeAnalysis:
76 typeAnalysisWatch.Stop();
78 case PerformanceStage.SemanticAnalysis:
79 semanticAnalysisWatch.Stop();
81 case PerformanceStage.Mix:
84 case PerformanceStage.DeepClone:
85 deepCloneWatch.Stop();
87 case PerformanceStage.AstParsing:
88 astParsingWatch.Stop();
97 case PerformanceStage.Global:
99 GlobalTimes.Add(globalWatch.ElapsedMilliseconds);
102 case PerformanceStage.Loading:
104 LoadingTimes.Add(loadingWatch.ElapsedMilliseconds);
107 case PerformanceStage.TypeAnalysis:
108 typeAnalysisWatch.Stop();
109 TypeAnalysisTimes.Add(typeAnalysisWatch.ElapsedMilliseconds);
112 case PerformanceStage.SemanticAnalysis:
113 semanticAnalysisWatch.Stop();
114 SemanticAnalysisTimes.Add(semanticAnalysisWatch.ElapsedMilliseconds);
115 ++semanticAnalysisCount;
117 case PerformanceStage.Mix:
119 MixTimes.Add(mixWatch.ElapsedMilliseconds);
122 case PerformanceStage.DeepClone:
123 deepCloneWatch.Stop();
124 DeepcloneTimes.Add(deepCloneWatch.ElapsedMilliseconds);
127 case PerformanceStage.AstParsing:
128 astParsingWatch.Stop();
129 AstParsingTimes.Add(astParsingWatch.ElapsedMilliseconds);
138 loadingWatch.Reset();
139 typeAnalysisWatch.Reset();
140 semanticAnalysisWatch.Reset();
142 deepCloneWatch.Reset();
143 astParsingWatch.Reset();
149 Console.WriteLine(
@"--------------------------TOTAL PERFORMANCE ANALYZER---------------------------");
150 Console.WriteLine(
@"Loading took {0} ms for {1} shader(s)", LoadingTimes.Aggregate((long)0, (agg, next) => agg + next), loadingCount);
151 Console.WriteLine(
@"Type analysis took {0} ms for {1} shader(s)", TypeAnalysisTimes.Aggregate((long)0, (agg, next) => agg + next), typeAnalysisCount);
152 Console.WriteLine(
@"Semantic analysis took {0} ms for {1} shader(s)", SemanticAnalysisTimes.Aggregate((long)0, (agg, next) => agg + next), semanticAnalysisCount);
153 Console.WriteLine(
@"Mix took {0} ms for {1} shader(s)", MixTimes.Aggregate((long)0, (agg, next) => agg + next), mixCount);
154 Console.WriteLine(
@"DeepClone took {0} ms for {1} shader(s)", DeepcloneTimes.Aggregate((long)0, (agg, next) => agg + next), deepCloneCount);
155 Console.WriteLine(
@"Ast parsing took {0} ms for {1} shader(s)", AstParsingTimes.Aggregate((long)0, (agg, next) => agg + next), astParsingCount);
156 Console.WriteLine(
@"-------------------------------------------------------------------------------");
162 Console.WriteLine(
@"--------------------------LAST PERFORMANCE ANALYZER---------------------------");
163 Console.WriteLine(
@"Process took {0} ms", globalWatch.ElapsedMilliseconds);
164 Console.WriteLine(
@"Loading took {0} ms", loadingWatch.ElapsedMilliseconds);
165 Console.WriteLine(
@"Type analysis took {0} ms", typeAnalysisWatch.ElapsedMilliseconds);
166 Console.WriteLine(
@"Semantic analysis took {0} ms", semanticAnalysisWatch.ElapsedMilliseconds);
167 Console.WriteLine(
@"Mix took {0} ms", mixWatch.ElapsedMilliseconds);
168 Console.WriteLine(
@"DeepClone took {0} ms", deepCloneWatch.ElapsedMilliseconds);
169 Console.WriteLine(
@"Ast parsing took {0} ms", astParsingWatch.ElapsedMilliseconds);
170 Console.WriteLine(
@"------------------------------------------------------------------------------");
177 if (globalCount == limit)
180 TextWriter tw =
new StreamWriter(
"performance.csv");
181 tw.WriteLine(
"loading,type,semantic,mix,deepclone,global");
183 for (var i = 0; i < limit; ++i)
185 tw.WriteLine(
"{0},{1},{2},{3},{4},{5}", LoadingTimes[i], TypeAnalysisTimes[i], SemanticAnalysisTimes[i], MixTimes[i], DeepcloneTimes[i], GlobalTimes[i]);