Skip to content

Commit

Permalink
Include generator summary
Browse files Browse the repository at this point in the history
Roslyn recently updated their `/reportAnalyzer` support to include
displaying source generator time in addition to analyzer time. This PR
updates the structured logger viewer to display the newly added
generator time in the same fashion that it displays anaylzer time

Roslyn PR: dotnet/roslyn#61661
  • Loading branch information
jaredpar committed Jul 7, 2022
1 parent 245e216 commit c910ec2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/StructuredLogger/Analyzers/BuildAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BuildAnalyzer
private Dictionary<string, (TimeSpan TotalDuration, Dictionary<string, TimeSpan> ParentDurations)> taskDurations
= new Dictionary<string, (TimeSpan TotalDuration, Dictionary<string, TimeSpan> ParentDurations)>();
private readonly List<Folder> analyzerReports = new List<Folder>();
private readonly List<Folder> generatorReports = new List<Folder>();

public BuildAnalyzer(Build build)
{
Expand Down Expand Up @@ -230,6 +231,12 @@ string Intern(string text)
var analyzerReportSummary = build.GetOrCreateNodeWithName<Folder>(Intern($"Analyzer Summary"));
CscTaskAnalyzer.CreateMergedReport(analyzerReportSummary, analyzerReports.ToArray());
}

if (generatorReports.Count > 0)
{
var generatorReportSummary = build.GetOrCreateNodeWithName<Folder>(Intern($"Generator Summary"));
CscTaskAnalyzer.CreateMergedReport(generatorReportSummary, generatorReports.ToArray());
}
}

private void PostAnalyzeProject(Project project)
Expand Down Expand Up @@ -317,11 +324,16 @@ private void AnalyzeTask(Task task)
}
else if (task.Name == "Csc")
{
var analyzerReport = CscTaskAnalyzer.Analyze(task);
var (analyzerReport, generatorReport) = CscTaskAnalyzer.Analyze(task);
if (analyzerReport is not null)
{
analyzerReports.Add(analyzerReport);
}

if (generatorReport is not null)
{
generatorReports.Add(generatorReport);
}
}

doubleWritesAnalyzer.AnalyzeTask(task);
Expand Down
21 changes: 16 additions & 5 deletions src/StructuredLogger/Analyzers/CscTaskAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand All @@ -7,9 +7,11 @@ namespace Microsoft.Build.Logging.StructuredLogger
{
public class CscTaskAnalyzer
{
public static Folder Analyze(Task task)
public static (Folder Analyzers, Folder Generators) Analyze(Task task)
{
Folder analyzerReport = null;
Folder generatorReport = null;
Folder currentReport = null;
Folder parent = null;

foreach (var message in task.Children.OfType<Message>().ToArray())
Expand All @@ -21,12 +23,21 @@ public static Folder Analyze(Task task)
analyzerReport.Name = Strings.AnalyzerReport;
task.AddChild(analyzerReport);
parent = analyzerReport;
currentReport = analyzerReport;
}
else if (text.Contains(", Version=") && analyzerReport != null)
else if (text.StartsWith(Strings.TotalGeneratorExecutionTime, StringComparison.Ordinal))
{
generatorReport = new Folder();
generatorReport.Name = Strings.GeneratorReport;
task.AddChild(generatorReport);
parent = generatorReport;
currentReport = generatorReport;
}
else if (text.Contains(", Version=") && currentReport != null)
{
var lastAssembly = new Folder();
lastAssembly.Name = text;
analyzerReport.AddChild(lastAssembly);
currentReport.AddChild(lastAssembly);
parent = lastAssembly;

// Remove the message since we are already using the same text for the containing folder
Expand All @@ -47,7 +58,7 @@ public static Folder Analyze(Task task)
}
}

return analyzerReport;
return (analyzerReport, generatorReport);
}

public static void CreateMergedReport(Folder destination, Folder[] analyzerReports)
Expand Down
4 changes: 3 additions & 1 deletion src/StructuredLogger/Strings/Strings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -442,6 +442,7 @@ public static Match IsFoundConflicts(string text)
public static string ToFile => "\" to file \"";

public static string TotalAnalyzerExecutionTime => "Total analyzer execution time:";
public static string TotalGeneratorExecutionTime => "Total generator execution time:";

/// <summary>
/// https://github.com/NuGet/Home/issues/10383
Expand All @@ -466,6 +467,7 @@ public static Match IsFoundConflicts(string text)
public static string Assemblies => "Assemblies";
public static string TargetOutputs => "TargetOutputs";
public static string AnalyzerReport => "Analyzer Report";
public static string GeneratorReport => "Generator Report";
public static string Properties => "Properties";
public static string PropertyReassignmentFolder => "Property reassignment";
public static string Global => "Global";
Expand Down

0 comments on commit c910ec2

Please sign in to comment.