Skip to content

Instantly share code, notes, and snippets.

@lbussell
Created May 29, 2025 21:13
Show Gist options
  • Select an option

  • Save lbussell/aef28719f57bc4dc6d7bcc9449dcf2ec to your computer and use it in GitHub Desktop.

Select an option

Save lbussell/aef28719f57bc4dc6d7bcc9449dcf2ec to your computer and use it in GitHub Desktop.
Analyze dotnet containers build output
var lines = File.ReadAllLines("your raw pipeline output.txt");
// The file contains lots of lines, but we care about lines of the form:
//
// -- EXECUTING: docker info
// a bunch of other lines...
// commmand output, etc...
// -- EXECUTION ELAPSED TIME: 00:00:00.0179437
//
// We want to extract the command and the elapsed time from each of these pairings.
var commands = new List<Command>();
string? currentCommand = null;
// <copilot>
foreach (var line in lines)
{
// Check if this is an executing line
if (line.Contains("-- EXECUTING: "))
{
// Extract the command after "-- EXECUTING: "
var executingIndex = line.IndexOf("-- EXECUTING: ");
currentCommand = line.Substring(executingIndex + "-- EXECUTING: ".Length).Trim();
}
// Check if this is an elapsed time line and we have a current command
else if (line.Contains("-- EXECUTION ELAPSED TIME: ") && currentCommand != null)
{
// Extract the time after "-- EXECUTION ELAPSED TIME: "
var timeIndex = line.IndexOf("-- EXECUTION ELAPSED TIME: ");
var timeString = line.Substring(timeIndex + "-- EXECUTION ELAPSED TIME: ".Length).Trim();
// Parse the TimeSpan
if (TimeSpan.TryParse(timeString, out var elapsed))
{
commands.Add(new Command(currentCommand, elapsed));
currentCommand = null; // Reset for next command
}
}
}
// </copilot>
var buildCommands = commands
.Where(command => command.Name.StartsWith("docker build"))
.Select(command => command with
{
Name = command.Name
.Split(' ')
.Where(s => s.Contains("Dockerfile"))
.Last()
.Replace("dotnet-dotnet-buildtools-prereqs-docker/", "")
})
.OrderByDescending(command => command.Elapsed);
var totalBuildTime =
buildCommands
.Aggregate(TimeSpan.Zero, (acc, c) => acc + c.Elapsed)
.ToString("hh\\:mm\\:ss\\.fff");
var buildCommandsList =
string.Join(Environment.NewLine,
buildCommands.Select(command =>
$"{command.Elapsed:hh\\:mm\\:ss\\.fff} - {command.Name}"));
Console.WriteLine(
$"""
Sum of dotnet build commands: {totalBuildTime}
Commands:
{buildCommandsList}
""");
record Command(string Name, TimeSpan Elapsed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment