提交 5fddfc48 编写于 作者: S Sam Harwell

Track the number of bytes allocated per edit

上级 e9f4524a
......@@ -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<DocumentAnalyzerPerformance> 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<DocumentAnalyzerPerformance> 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<Tuple<ProjectId, Diagnostic>> 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; }
}
}
}
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册