Skip to content

Instantly share code, notes, and snippets.

@rdavisau
Created April 3, 2023 20:04
Show Gist options
  • Save rdavisau/c8009ddf01987c5a8b52eb0683614e7a to your computer and use it in GitHub Desktop.
Save rdavisau/c8009ddf01987c5a8b52eb0683614e7a to your computer and use it in GitHub Desktop.
Quick and dirty extraction of aot compile times from a diagnostic build log ("Dealing with AOT-unfriendly assemblies" in https://ryandavis.io/improving-dotnet-ios-release-build-times-on-apple-silicon/)
void Main()
{
var logPath = /* path to build log produced using -flp:v=diag -flp:logfile=mylog.log */ ;
foreach (var aotTime in ParseFile(logPath))
Console.WriteLine($"{aotTime.TotalTime:N2}\t\t\t\t{aotTime.Assembly}");
}
public List<AOTTime> ParseFile(string path)
{
const string opener = "Mono Ahead of Time compiler - compiling assembly ";
const string closer = "JIT time:";
return
File.ReadLines(path)
.BatchBy(open: x => x.Trim().StartsWith(opener), close: x => x.Trim().StartsWith(closer))
.Select(x =>
{
var asm = Path.GetFileName(x[0].Split(opener, StringSplitOptions.RemoveEmptyEntries)[1]);
var stats =
x.Last()[..^1]
.Split(',')
.Select(y => y.Trim().Replace(" ms", ""))
.Select(y => y.Split(' ').Last())
.ToList();
return new AOTTime
{
Assembly = asm,
JitTime = Int32.Parse(stats[0]) / 1000.0,
GenTime = Int32.Parse(stats[1]) / 1000.0,
LinkTime = Int32.Parse(stats[2]) / 1000.0,
Lines = x
};
})
.OrderBy(x => x.Assembly)
.OrderByDescending(x => x.TotalTime)
.ToList();
}
public class AOTTime
{
public string Assembly { get; set; }
public double JitTime { get; set; }
public double GenTime { get; set; }
public double LinkTime { get; set; }
public double TotalTime => Math.Round(JitTime + GenTime + LinkTime, 2);
internal List<string> Lines { get; set; }
}
public static class BatchExtensions
{
public static IEnumerable<List<T>> BatchBy<T>(this IEnumerable<T> items, Func<T, bool> open, Func<T, bool> close)
{
var curr = new List<T>();
foreach (var item in items)
{
if (close(item))
{
curr.Add(item);
yield return curr;
curr = new();
continue;
}
if (open(item))
{
// not expecting to see an open when we have any curr
if (curr.Any())
Debugger.Break();
curr.Add(item);
continue;
}
// don't add if we haven't seen an open
if (curr.Any())
curr.Add(item);
}
if (curr.Any())
Debugger.Break();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment