diff --git a/src/Tools/AnalyzerRunner/DiagnosticAnalyzerRunner.cs b/src/Tools/AnalyzerRunner/DiagnosticAnalyzerRunner.cs index 34db334d69debccdce3f7168927e2ad1e5fb428e..18db955dee58fc54d0cb5f9bd0617fb2d33d9b9a 100644 --- a/src/Tools/AnalyzerRunner/DiagnosticAnalyzerRunner.cs +++ b/src/Tools/AnalyzerRunner/DiagnosticAnalyzerRunner.cs @@ -98,7 +98,7 @@ public async Task RunAsync(Workspace workspace, CancellationToken cancellationTo } var currentDocumentPerformance = await TestDocumentPerformanceAsync(_analyzers, project, documentId, _options, cancellationToken).ConfigureAwait(false); - Console.WriteLine($"{document.FilePath ?? document.Name}: {currentDocumentPerformance.EditsPerSecond:0.00}"); + Console.WriteLine($"{document.FilePath ?? document.Name}: {currentDocumentPerformance.EditsPerSecond:0.00} ({currentDocumentPerformance.AllocatedBytesPerEdit} bytes)"); documentPerformance.Add(documentId, currentDocumentPerformance); } @@ -118,7 +118,7 @@ public async Task RunAsync(Workspace workspace, CancellationToken cancellationTo foreach (var pair in projectGroup.Take(5)) { var document = solution.GetDocument(pair.Key); - Console.WriteLine($" {document.FilePath ?? document.Name}: {pair.Value.EditsPerSecond:0.00}"); + Console.WriteLine($" {document.FilePath ?? document.Name}: {pair.Value.EditsPerSecond:0.00} ({pair.Value.AllocatedBytesPerEdit} bytes)"); } } @@ -163,7 +163,7 @@ private static async Task TestDocumentPerformanceAs Compilation compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); - var stopwatch = Stopwatch.StartNew(); + var stopwatch = PerformanceTracker.StartNew(); for (int i = 0; i < analyzerOptionsInternal.TestDocumentIterations; i++) { var workspaceAnalyzerOptions = new WorkspaceAnalyzerOptions(project.AnalyzerOptions, project.Solution); @@ -174,7 +174,7 @@ private static async Task TestDocumentPerformanceAs await compilationWithAnalyzers.GetAnalyzerSemanticDiagnosticsAsync(compilation.GetSemanticModel(tree), null, cancellationToken).ConfigureAwait(false); } - return new DocumentAnalyzerPerformance(analyzerOptionsInternal.TestDocumentIterations / stopwatch.Elapsed.TotalSeconds); + return new DocumentAnalyzerPerformance(analyzerOptionsInternal.TestDocumentIterations / stopwatch.Elapsed.TotalSeconds, stopwatch.AllocatedBytes / Math.Max(1, analyzerOptionsInternal.TestDocumentIterations)); } private static void WriteDiagnosticResults(ImmutableArray> diagnostics, string fileName) @@ -458,15 +458,14 @@ private static void WriteExecutionTimes(string analyzerName, int longestAnalyzer private struct DocumentAnalyzerPerformance { - public DocumentAnalyzerPerformance(double editsPerSecond) + public DocumentAnalyzerPerformance(double editsPerSecond, long allocatedBytesPerEdit) { EditsPerSecond = editsPerSecond; + AllocatedBytesPerEdit = allocatedBytesPerEdit; } - public double EditsPerSecond - { - get; - } + public double EditsPerSecond { get; } + public long AllocatedBytesPerEdit { get; } } } } diff --git a/src/Tools/AnalyzerRunner/PerformanceTracker.cs b/src/Tools/AnalyzerRunner/PerformanceTracker.cs index 40bd37fccccaecd67c3d5d983cabd62c817aeefc..54207aefffcc4067564adf11e5343f223ba88bc3 100644 --- a/src/Tools/AnalyzerRunner/PerformanceTracker.cs +++ b/src/Tools/AnalyzerRunner/PerformanceTracker.cs @@ -33,6 +33,12 @@ public static PerformanceTracker StartNew(bool preciseMemory = true) public TimeSpan Elapsed => _stopwatch.Elapsed; +#if NETCOREAPP + public long AllocatedBytes => GC.GetTotalAllocatedBytes(true) - _initialTotalAllocatedBytes; +#else + public long AllocatedBytes => 0; +#endif + public string GetSummary(bool preciseMemory = true) { #if NETCOREAPP