Skip to content

Commit

Permalink
Add support for chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomorgado committed Oct 15, 2020
1 parent 389b673 commit b151926
Show file tree
Hide file tree
Showing 8 changed files with 1,345 additions and 18 deletions.
946 changes: 946 additions & 0 deletions DotnetMSBuildLog/Binlog/BinlogEnumerator.cs

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions DotnetMSBuildLog/Binlog/BuildEventArgsFieldFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Logging.StructuredLogger;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;

namespace PauloMorgado.DotnetMSBuildLog.Binlog
{
/// <summary>
/// A bitmask to specify which fields on a BuildEventArgs object are present; used in serialization
/// </summary>
[Flags]
internal enum BuildEventArgsFieldFlags
{
None = 0,
BuildEventContext = 1 << 0,
HelpHeyword = 1 << 1,
Message = 1 << 2,
SenderName = 1 << 3,
ThreadId = 1 << 4,
Timestamp = 1 << 5,
Subcategory = 1 << 6,
Code = 1 << 7,
File = 1 << 8,
ProjectFile = 1 << 9,
LineNumber = 1 << 10,
ColumnNumber = 1 << 11,
EndLineNumber = 1 << 12,
EndColumnNumber = 1 << 13
}
}
35 changes: 35 additions & 0 deletions DotnetMSBuildLog/Binlog/BuildEventArgsFields.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Logging.StructuredLogger;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;

namespace PauloMorgado.DotnetMSBuildLog.Binlog
{
/// <summary>
/// Represents a collective set of common properties on BuildEventArgs. Used for deserialization.
/// </summary>
internal class BuildEventArgsFields
{
public BuildEventArgsFieldFlags Flags { get; set; }

public string? Message { get; set; }
public BuildEventContext? BuildEventContext { get; set; }
public int ThreadId { get; set; }
public string? HelpKeyword { get; set; }
public string? SenderName { get; set; }
public DateTime Timestamp { get; set; }

public string? Subcategory { get; set; }
public string? Code { get; set; }
public string? File { get; set; }
public string? ProjectFile { get; set; }
public int LineNumber { get; set; }
public int ColumnNumber { get; set; }
public int EndLineNumber { get; set; }
public int EndColumnNumber { get; set; }
}
}
19 changes: 17 additions & 2 deletions DotnetMSBuildLog/CommandLine/Commands/ConvertCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal sealed class ConvertCommandArguments
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public MSBuildLogFileFormat Format { get; set; }
public FileInfo? OutputFileName { get; set; }
public bool IncludeAllTasks { get; set; }
}

internal static class ConvertCommandHandler
Expand Down Expand Up @@ -45,7 +46,12 @@ public static int ConvertFile(ConvertCommandArguments arguments)
arguments.OutputFileName = arguments.InputFileName;
}

MSBuildLogFileFormatConverter.ConvertToFormat(arguments.Console, arguments.Format, arguments.InputFileName.FullName, arguments.OutputFileName.FullName);
MSBuildLogFileFormatConverter.ConvertToFormat(
arguments.Console,
arguments.Format,
arguments.InputFileName.FullName,
arguments.OutputFileName.FullName,
arguments.IncludeAllTasks);

return 0;
}
Expand All @@ -62,6 +68,7 @@ public static Command ConvertCommand() =>
InputFileArgument(),
ConvertFormatOption(),
OutputOption(),
IncludeAllTasksOption(),
};

private static Argument InputFileArgument() =>
Expand All @@ -73,7 +80,7 @@ private static Argument InputFileArgument() =>

public static Option ConvertFormatOption() =>
new Option(
alias: "--format",
aliases: new[] { "-f", "--format" },
description: $"Sets the output format for the trace file conversion.")
{
Argument = new Argument<MSBuildLogFileFormat>(name: "trace-file-format")
Expand All @@ -86,5 +93,13 @@ private static Option OutputOption() =>
{
Argument = new Argument<FileInfo>(name: "output-filename")
};

private static Option IncludeAllTasksOption() =>
new Option(
aliases: new[] { "-t", "--tasks" },
description: "Include all tasks.")
{
Argument = new Argument<bool>(name: "include-all-tasks")
};
}
}
9 changes: 9 additions & 0 deletions DotnetMSBuildLog/Converters/MSBuildLogFileFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace PauloMorgado.DotnetMSBuildLog.Converters
{
internal enum MSBuildLogFileFormat
{
MSBuildBinaryLog,
Speedscope,
Chromium,
};
}
27 changes: 16 additions & 11 deletions DotnetMSBuildLog/Converters/MSBuildLogFileFormatConverter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using Microsoft.Build.Logging.StructuredLogger;
using PauloMorgado.DotnetMSBuildLog.Binlog;
using PauloMorgado.DotnetMSBuildLog.Writers.Chromium;
using PauloMorgado.DotnetMSBuildLog.Writers.Speedscope;
using System;
using System.Collections.Immutable;
using System.CommandLine;
using System.CommandLine.IO;
using System.IO;
using Microsoft.Build.Logging.StructuredLogger;
using PauloMorgado.DotnetMSBuildLog.Writers;

namespace PauloMorgado.DotnetMSBuildLog.Converters
{
internal enum MSBuildLogFileFormat { MSBuildBinaryLog, Speedscope };

internal static class MSBuildLogFileFormatConverter
{
private static ImmutableDictionary<MSBuildLogFileFormat, string> TraceFileFormatExtensions = GetTraceFileFormatExtensions();
Expand All @@ -19,10 +19,11 @@ private static ImmutableDictionary<MSBuildLogFileFormat, string> GetTraceFileFor
var builder = ImmutableDictionary.CreateBuilder<MSBuildLogFileFormat, string>();
builder.Add(MSBuildLogFileFormat.MSBuildBinaryLog, "binlog");
builder.Add(MSBuildLogFileFormat.Speedscope, "speedscope.json");
builder.Add(MSBuildLogFileFormat.Chromium, "chromium.json");
return builder.ToImmutable();
}

internal static void ConvertToFormat(IConsole console, MSBuildLogFileFormat format, string fileToConvertFilePath, string outputFilePath)
internal static void ConvertToFormat(IConsole console, MSBuildLogFileFormat format, string fileToConvertFilePath, string outputFilePath, bool includeAllTasks)
{
if (string.IsNullOrWhiteSpace(outputFilePath))
{
Expand All @@ -36,8 +37,9 @@ internal static void ConvertToFormat(IConsole console, MSBuildLogFileFormat form
{
case MSBuildLogFileFormat.MSBuildBinaryLog:
break;
case MSBuildLogFileFormat.Chromium:
case MSBuildLogFileFormat.Speedscope:
Convert(format, fileToConvertFilePath, outputFilePath);
Convert(format, fileToConvertFilePath, outputFilePath, includeAllTasks);
break;
default:
// Validation happened way before this, so we shoud never reach this...
Expand All @@ -47,14 +49,17 @@ internal static void ConvertToFormat(IConsole console, MSBuildLogFileFormat form
console.Out.WriteLine("Conversion complete");
}

private static void Convert(MSBuildLogFileFormat format, string fileToConvertFilePath, string outputFilePath)
private static void Convert(MSBuildLogFileFormat format, string fileToConvertFilePath, string outputFilePath, bool includeAllTasks)
{
var build = Serialization.Read(fileToConvertFilePath);

switch (format)
{
case MSBuildLogFileFormat.Chromium:
var buildEnumerator = new BinlogEnumerable(fileToConvertFilePath);
ChromiumMSBuildLogWriter.WriteTo(buildEnumerator, outputFilePath, includeAllTasks);
break;
case MSBuildLogFileFormat.Speedscope:
SpeedscopeMSBuildLogWriter.WriteTo(build, outputFilePath);
var build = Serialization.Read(fileToConvertFilePath);
SpeedscopeMSBuildLogWriter.WriteTo(build, outputFilePath, includeAllTasks);
break;
default:
// we should never get here
Expand Down
Loading

0 comments on commit b151926

Please sign in to comment.