未验证 提交 9e72d424 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #40888 from sharwell/compile-stats

Add /compilerStats option for AnalyzerRunner
......@@ -19,6 +19,7 @@ internal sealed class Options
public readonly bool ReportSuppressedDiagnostics;
public readonly bool ApplyChanges;
public readonly bool ShowStats;
public readonly bool ShowCompilerDiagnostics;
public readonly bool UseAll;
public readonly int Iterations;
public readonly bool TestDocuments;
......@@ -41,6 +42,7 @@ internal sealed class Options
bool reportSuppressedDiagnostics,
bool applyChanges,
bool showStats,
bool showCompilerDiagnostics,
bool useAll,
int iterations,
bool testDocuments,
......@@ -60,6 +62,7 @@ internal sealed class Options
ReportSuppressedDiagnostics = reportSuppressedDiagnostics;
ApplyChanges = applyChanges;
ShowStats = showStats;
ShowCompilerDiagnostics = showCompilerDiagnostics;
UseAll = useAll;
Iterations = iterations;
TestDocuments = testDocuments;
......@@ -82,6 +85,7 @@ internal static Options Create(string[] args)
bool reportSuppressedDiagnostics = false;
bool applyChanges = false;
bool showStats = false;
bool showCompilerDiagnostics = false;
bool useAll = false;
int iterations = 1;
bool testDocuments = false;
......@@ -107,6 +111,9 @@ internal static Options Create(string[] args)
case "/stats":
showStats = true;
break;
case "/compilerStats":
showCompilerDiagnostics = true;
break;
case "/concurrent":
runConcurrent = true;
break;
......@@ -189,6 +196,7 @@ internal static Options Create(string[] args)
reportSuppressedDiagnostics: reportSuppressedDiagnostics,
applyChanges: applyChanges,
showStats: showStats,
showCompilerDiagnostics: showCompilerDiagnostics,
useAll: useAll,
iterations: iterations,
testDocuments: testDocuments,
......
......@@ -106,6 +106,37 @@ public static async Task Main(string[] args)
Console.WriteLine("Number of syntax trivia:\t" + statistics.NumberOfTrivia);
}
if (options.ShowCompilerDiagnostics)
{
var projects = solution.Projects.Where(project => project.Language == LanguageNames.CSharp || project.Language == LanguageNames.VisualBasic).ToList();
var diagnosticStatistics = new Dictionary<string, (string description, DiagnosticSeverity severity, int count)>();
foreach (var project in projects)
{
var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
foreach (var diagnostic in compilation.GetDiagnostics(cancellationToken))
{
diagnosticStatistics.TryGetValue(diagnostic.Id, out var existing);
var description = existing.description;
if (string.IsNullOrEmpty(description))
{
description = diagnostic.Descriptor?.Title.ToString();
if (string.IsNullOrEmpty(description))
{
description = diagnostic.Descriptor?.MessageFormat.ToString();
}
}
diagnosticStatistics[diagnostic.Id] = (description, diagnostic.Descriptor.DefaultSeverity, existing.count + 1);
}
}
foreach (var pair in diagnosticStatistics)
{
Console.WriteLine($" {pair.Value.severity} {pair.Key}: {pair.Value.count} instances ({pair.Value.description})");
}
}
Console.WriteLine("Pausing 5 seconds before starting analysis...");
await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
......
......@@ -2,7 +2,7 @@
"profiles": {
"IDE Analyzers": {
"commandName": "Project",
"commandLineArgs": "$(OutDir) $(SolutionDir)Roslyn.sln /concurrent /stats"
"commandLineArgs": "$(OutDir) $(SolutionDir)Roslyn.sln /concurrent /stats /compilerStats"
},
"CSharpEditorFeatures Analyzers": {
"commandName": "Project",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册