Skip to content

Commit 1645e7b

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tests] Improve Time Elapsed processing (#968)
Attempt to quasi-"optimize" `Builder.BuildInternal()`: if we're going to read `buildLogFullPath` a line at a time *anyway* -- to collect the log file for later parsing into `Builder.LastBuildOutput` -- then we should also do any associated line-oriented parsing as well. Update `buildLogFullPath` processing to use a `StringBuilder` instead of string concatenation, and search for the `Time Elapsed` message while reading the file, instead of separately, *after* having read the entire build log into memory.
1 parent 927d66d commit 1645e7b

File tree

1 file changed

+23
-10
lines changed
  • src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common

1 file changed

+23
-10
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/Builder.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,31 @@ protected bool BuildInternal (string projectOrSolution, string target, string []
239239

240240
LastBuildTime = DateTime.UtcNow - start;
241241

242-
LastBuildOutput = psi.FileName + " " + args.ToString () + Environment.NewLine;
242+
var sb = new StringBuilder ();
243+
sb.AppendLine ( psi.FileName + " " + args.ToString () + Environment.NewLine);
243244
if (!ranToCompletion)
244-
LastBuildOutput += "Build Timed Out!";
245-
if (buildLogFullPath != null && File.Exists (buildLogFullPath))
246-
LastBuildOutput += File.ReadAllText (buildLogFullPath);
247-
LastBuildOutput += string.Format ("\n#stdout begin\n{0}\n#stdout end\n", p.StandardOutput.ReadToEnd ());
248-
LastBuildOutput += string.Format ("\n#stderr begin\n{0}\n#stderr end\n", p.StandardError.ReadToEnd ());
249-
250-
var match = timeElapsedRegEx.Match (LastBuildOutput);
251-
if (match.Success) {
252-
LastBuildTime = TimeSpan.Parse (match.Groups ["TimeSpan"].Value);
245+
sb.AppendLine ("Build Timed Out!");
246+
if (buildLogFullPath != null && File.Exists (buildLogFullPath)) {
247+
using (var fs = File.OpenRead (buildLogFullPath)) {
248+
using (var sr = new StreamReader (fs, Encoding.UTF8, true, 65536)) {
249+
string line;
250+
while ((line = sr.ReadLine ()) != null) {
251+
sb.AppendLine (line);
252+
if (line.StartsWith ("Time Elapsed", StringComparison.OrdinalIgnoreCase)) {
253+
var match = timeElapsedRegEx.Match (line);
254+
if (match.Success) {
255+
LastBuildTime = TimeSpan.Parse (match.Groups ["TimeSpan"].Value);
256+
Console.WriteLine ($"Found Time Elapsed {LastBuildTime}");
257+
}
258+
}
259+
}
260+
}
261+
}
253262
}
263+
sb.AppendFormat ("\n#stdout begin\n{0}\n#stdout end\n", p.StandardOutput.ReadToEnd ());
264+
sb.AppendFormat ("\n#stderr begin\n{0}\n#stderr end\n", p.StandardError.ReadToEnd ());
265+
266+
LastBuildOutput = sb.ToString ();
254267

255268
if (buildLogFullPath != null) {
256269
Directory.CreateDirectory (Path.GetDirectoryName (buildLogFullPath));

0 commit comments

Comments
 (0)