提交 2714017c 编写于 作者: H Heejae Chang

Merge pull request #11640 from heejaechang/telemetry2

fix issue with telemetry.
......@@ -16,7 +16,7 @@
namespace Microsoft.CodeAnalysis.Diagnostics
{
[ExportIncrementalAnalyzerProvider(
highPriorityForActiveFile: true, name: WellKnownSolutionCrawlerAnalyzers.Diagnostic,
highPriorityForActiveFile: true, name: WellKnownSolutionCrawlerAnalyzers.Diagnostic,
workspaceKinds: new string[] { WorkspaceKind.Host, WorkspaceKind.Interactive })]
internal partial class DiagnosticAnalyzerService : IIncrementalAnalyzerProvider
{
......@@ -188,6 +188,11 @@ public override Task SynchronizeWithBuildAsync(Workspace workspace, ImmutableDic
}
#endregion
public override void LogAnalyzerCountSummary()
{
Analyzer.LogAnalyzerCountSummary();
}
public void TurnOff(bool useV2)
{
var turnedOffAnalyzer = GetAnalyzer(!useV2);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Diagnostics.Telemetry;
namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2
{
/// <summary>
/// Basically typed tuple.
/// </summary>
internal struct CompilerAnalysisResult
{
public readonly ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult> AnalysisResult;
public readonly ImmutableDictionary<DiagnosticAnalyzer, AnalyzerTelemetryInfo> TelemetryInfo;
public CompilerAnalysisResult(
ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult> analysisResult,
ImmutableDictionary<DiagnosticAnalyzer, AnalyzerTelemetryInfo> telemetryInfo)
{
AnalysisResult = analysisResult;
TelemetryInfo = telemetryInfo;
}
}
}
......@@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics.EngineV2
/// </summary>
internal static class CompilerDiagnosticExecutor
{
public static async Task<ImmutableDictionary<DiagnosticAnalyzer, AnalysisResult>> AnalyzeAsync(this CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
public static async Task<CompilerAnalysisResult> AnalyzeAsync(this CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
{
var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
......@@ -61,7 +61,7 @@ internal static class CompilerDiagnosticExecutor
builder.Add(analyzer, result.ToResult());
}
return builder.ToImmutable();
return new CompilerAnalysisResult(builder.ToImmutable(), analysisResult.AnalyzerTelemetryInfo);
}
/// <summary>
......
......@@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics.Log;
using Microsoft.CodeAnalysis.Diagnostics.Telemetry;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Options;
......@@ -152,10 +153,11 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
if (analyzerDriverOpt != null)
{
// calculate regular diagnostic analyzers diagnostics
result = await analyzerDriverOpt.AnalyzeAsync(project, cancellationToken).ConfigureAwait(false);
var compilerResult = await analyzerDriverOpt.AnalyzeAsync(project, cancellationToken).ConfigureAwait(false);
result = compilerResult.AnalysisResult;
// record telemetry data
await UpdateAnalyzerTelemetryDataAsync(analyzerDriverOpt, project, cancellationToken).ConfigureAwait(false);
UpdateAnalyzerTelemetryData(compilerResult, project, cancellationToken);
}
// check whether there is IDE specific project diagnostic analyzer
......@@ -389,24 +391,11 @@ public IEnumerable<DiagnosticData> ConvertToLocalDiagnostics(Document targetDocu
}
}
private async Task UpdateAnalyzerTelemetryDataAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken)
private void UpdateAnalyzerTelemetryData(CompilerAnalysisResult analysisResult, Project project, CancellationToken cancellationToken)
{
foreach (var analyzer in analyzerDriver.Analyzers)
foreach (var kv in analysisResult.TelemetryInfo)
{
await UpdateAnalyzerTelemetryDataAsync(analyzerDriver, analyzer, project, cancellationToken).ConfigureAwait(false);
}
}
private async Task UpdateAnalyzerTelemetryDataAsync(CompilationWithAnalyzers analyzerDriver, DiagnosticAnalyzer analyzer, Project project, CancellationToken cancellationToken)
{
try
{
var analyzerTelemetryInfo = await analyzerDriver.GetAnalyzerTelemetryInfoAsync(analyzer, cancellationToken).ConfigureAwait(false);
DiagnosticAnalyzerLogger.UpdateAnalyzerTypeCount(analyzer, analyzerTelemetryInfo, project, _owner.DiagnosticLogAggregator);
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
DiagnosticAnalyzerLogger.UpdateAnalyzerTypeCount(kv.Key, kv.Value, project, _owner.DiagnosticLogAggregator);
}
}
......
......@@ -210,6 +210,7 @@
<Compile Include="Diagnostics\EngineV1\DiagnosticIncrementalAnalyzer_GetDiagnostics.cs" />
<Compile Include="Diagnostics\EngineV1\DiagnosticIncrementalAnalyzer_GetLatestDiagnosticsForSpan.cs" />
<Compile Include="Diagnostics\EngineV1\MemberRangeMap.cs" />
<Compile Include="Diagnostics\EngineV2\CompilerAnalysisResult.cs" />
<Compile Include="Diagnostics\EngineV2\DiagnosticDataSerializer.cs" />
<Compile Include="Diagnostics\EngineV2\DiagnosticIncrementalAnalyzer.AnalysisData.cs" />
<Compile Include="Diagnostics\EngineV2\DiagnosticIncrementalAnalyzer.AnalysisKind.cs" />
......
......@@ -249,7 +249,7 @@ public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId,
foreach (var analyzer in analyzers)
{
var diagIncrementalAnalyzer = analyzer as BaseDiagnosticIncrementalAnalyzer;
var diagIncrementalAnalyzer = analyzer as DiagnosticAnalyzerService.IncrementalAnalyzerDelegatee;
if (diagIncrementalAnalyzer != null)
{
diagIncrementalAnalyzer.LogAnalyzerCountSummary();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册