From 5fddfc48da41a344388cadebf4eb368f278a24a8 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Thu, 16 Jan 2020 16:22:14 -0800 Subject: [PATCH] Track the number of bytes allocated per edit --- .../AnalyzerRunner/DiagnosticAnalyzerRunner.cs | 17 ++++++++--------- src/Tools/AnalyzerRunner/PerformanceTracker.cs | 6 ++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Tools/AnalyzerRunner/DiagnosticAnalyzerRunner.cs b/src/Tools/AnalyzerRunner/DiagnosticAnalyzerRunner.cs index 34db334d69d..18db955dee5 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 40bd37fcccc..54207aefffc 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 -- GitLab