Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include generator summary #610

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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