Skip to content

Commit add8734

Browse files
committed
Add source-level excision time reporting.
1 parent a185be3 commit add8734

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ServerCodeExciser/ServerCodeExcisionProcessor.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Antlr4.Runtime;
22
using ServerCodeExcisionCommon;
33
using System;
4-
using System.Collections;
54
using System.Collections.Generic;
5+
using System.Diagnostics;
66
using System.IO;
77
using System.Linq;
88
using System.Text;
@@ -61,7 +61,7 @@ public ServerCodeExcisionProcessor(ServerCodeExcisionParameters parameters)
6161

6262
public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExcisionLanguage excisionLanguage)
6363
{
64-
var startTime = DateTime.UtcNow;
64+
var globalStopwatch = Stopwatch.StartNew();
6565
var globalStats = new ExcisionStats();
6666

6767
var options = new EnumerationOptions();
@@ -107,30 +107,33 @@ public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExci
107107

108108
try
109109
{
110+
var stopwatch = Stopwatch.StartNew();
110111
var stats = ProcessCodeFile(fileName, inputPath, excisionMode, excisionLanguage);
112+
stopwatch.Stop();
113+
111114
if (stats.CharactersExcised > 0)
112115
{
113116
System.Diagnostics.Debug.Assert(stats.TotalNrCharacters > 0, "Something is terribly wrong. We have excised characters, but no total characters..?");
114117
var excisionRatio = (float)stats.CharactersExcised / (float)stats.TotalNrCharacters * 100.0f;
115-
Console.WriteLine("Excised {0:0.00}% of server only code in file ({1}/{2}): {3}", excisionRatio, fileIdx + 1, allFiles.Length, fileName);
118+
Console.WriteLine($"[{fileIdx + 1}/{allFiles.Length}] Excised {excisionRatio:0.00}% of server only code in file (took {stopwatch.Elapsed.TotalMilliseconds:0.0}ms): {fileName}");
116119
}
117120
else
118121
{
119-
Console.WriteLine("No server only code found in file ({0}/{1}): {2}", fileIdx + 1, allFiles.Length, fileName);
122+
Console.WriteLine($"[{fileIdx + 1}/{allFiles.Length}] No server only code found in file: {fileName}");
120123
}
121124

122125
globalStats.CharactersExcised += stats.CharactersExcised;
123126
globalStats.TotalNrCharacters += stats.TotalNrCharacters;
124127
}
125128
catch (Exception)
126129
{
127-
Console.WriteLine("Failed to parse ({0}/{1}): {2}", fileIdx + 1, allFiles.Length, fileName);
130+
Console.Error.WriteLine($"[{fileIdx + 1}/{allFiles.Length}] Failed to parse: {fileName}");
128131
throw;
129132
}
130133
}
131134
}
132135

133-
var endTime = DateTime.UtcNow;
136+
globalStopwatch.Stop();
134137

135138
// In verification mode error codes reverse the normal behavior of the exciser.
136139
// Modifications required -> error
@@ -157,8 +160,7 @@ public EExciserReturnValues ExciseServerCode(string filePattern, IServerCodeExci
157160
Console.WriteLine("Excised {0:0.00}% ({1}/{2} characters) of server only code from the script files.",
158161
totalExcisionRatio, globalStats.CharactersExcised, globalStats.TotalNrCharacters);
159162

160-
var timeTaken = endTime - startTime;
161-
Console.WriteLine("Excision took {0:0} hours, {1:0} minutes and {2:0.0} seconds.\n\n", timeTaken.Hours, timeTaken.Minutes, timeTaken.Seconds);
163+
Console.WriteLine($"Excision took {globalStopwatch.Elapsed.TotalSeconds:0.0}s.");
162164

163165
if (_parameters.RequiredExcisionRatio > 0.0f && totalExcisionRatio < _parameters.RequiredExcisionRatio)
164166
{

0 commit comments

Comments
 (0)