未验证 提交 cf91608b 编写于 作者: H Heejae Chang 提交者: GitHub

added partial solution telemetry (#31478)

* renamed LogSummary to ReportTelemetry

* added telemetry to see how often partial solutoin is used
上级 e21202b0
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Logging;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Versions;
......@@ -196,8 +197,9 @@ protected override void Dispose(bool disposing)
private void ReportSessionWideTelemetry()
{
PersistedVersionStampLogger.LogSummary();
PersistedVersionStampLogger.ReportTelemetry();
LinkedFileDiffMergingLogger.ReportTelemetry();
SolutionLogger.ReportTelemetry();
}
private void DisposeVisualStudioServices()
......
......@@ -81,6 +81,7 @@ internal enum FunctionId
Workspace_TryGetDocumentFromInProgressSolution,
Workspace_Solution_LinkedFileDiffMergingSession,
Workspace_Solution_LinkedFileDiffMergingSession_LinkedFileGroup,
Workspace_Solution_Info,
EndConstruct_DoStatement,
EndConstruct_XmlCData,
......
......@@ -54,7 +54,7 @@ public static void LogPersistedDependentProjectVersionUsage(bool succeeded)
s_logAggregator.IncreaseCount(DependentProject);
}
public static void LogSummary()
public static void ReportTelemetry()
{
Logger.Log(FunctionId.PersistedSemanticVersion_Info, KeyValueLogMessage.Create(m =>
{
......
// 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 Microsoft.CodeAnalysis.Internal.Log;
namespace Microsoft.CodeAnalysis.Logging
{
internal static class SolutionLogger
{
private static readonly LogAggregator s_logAggregator = new LogAggregator();
public static void UseExistingPartialProjectState()
{
s_logAggregator.IncreaseCount(nameof(UseExistingPartialProjectState));
}
public static void UseExistingFullProjectState()
{
s_logAggregator.IncreaseCount(nameof(UseExistingFullProjectState));
}
public static void CreatePartialProjectState()
{
s_logAggregator.IncreaseCount(nameof(CreatePartialProjectState));
}
public static void UseExistingPartialSolution()
{
s_logAggregator.IncreaseCount(nameof(UseExistingPartialSolution));
}
public static void CreatePartialSolution()
{
s_logAggregator.IncreaseCount(nameof(CreatePartialSolution));
}
public static void ReportTelemetry()
{
Logger.Log(FunctionId.Workspace_Solution_Info, KeyValueLogMessage.Create(m =>
{
m[nameof(UseExistingPartialProjectState)] = s_logAggregator.GetCount(nameof(UseExistingPartialProjectState));
m[nameof(UseExistingFullProjectState)] = s_logAggregator.GetCount(nameof(UseExistingFullProjectState));
m[nameof(CreatePartialProjectState)] = s_logAggregator.GetCount(nameof(CreatePartialProjectState));
m[nameof(UseExistingPartialSolution)] = s_logAggregator.GetCount(nameof(UseExistingPartialSolution));
m[nameof(CreatePartialSolution)] = s_logAggregator.GetCount(nameof(CreatePartialSolution));
}));
}
}
}
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Logging;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
......@@ -209,6 +210,8 @@ public CompilationTracker FreezePartialStateWithTree(SolutionState solution, Doc
inProgressState.IntermediateProjects.All(t => IsTouchDocumentActionForDocument(t, id)))
{
inProgressProject = this.ProjectState;
SolutionLogger.UseExistingPartialProjectState();
return;
}
......@@ -217,6 +220,7 @@ public CompilationTracker FreezePartialStateWithTree(SolutionState solution, Doc
// if we already have a final compilation we are done.
if (inProgressCompilation != null && state is FinalState)
{
SolutionLogger.UseExistingFullProjectState();
return;
}
......@@ -276,8 +280,9 @@ public CompilationTracker FreezePartialStateWithTree(SolutionState solution, Doc
}
inProgressProject = inProgressProject.AddProjectReferences(newProjectReferences);
inProgressCompilation = UpdateCompilationWithNewReferencesAndRecordAssemblySymbols(inProgressCompilation, metadataReferences, metadataReferenceToProjectId);
SolutionLogger.CreatePartialProjectState();
}
private static bool IsTouchDocumentActionForDocument(ValueTuple<ProjectState, CompilationTranslationAction> tuple, DocumentId id)
......
......@@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Logging;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Serialization;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -1658,27 +1659,34 @@ public SolutionState WithFrozenPartialCompilationIncludingSpecificDocument(Docum
_latestSolutionWithPartialCompilation.TryGetTarget(out currentPartialSolution);
}
// if we don't have one or it is stale, create a new partial solution
if (currentPartialSolution == null
|| (DateTime.UtcNow - _timeOfLatestSolutionWithPartialCompilation).TotalSeconds >= 0.1
|| _documentIdOfLatestSolutionWithPartialCompilation != documentId)
var reuseExistingPartialSolution =
currentPartialSolution != null &&
(DateTime.UtcNow - _timeOfLatestSolutionWithPartialCompilation).TotalSeconds < 0.1 &&
_documentIdOfLatestSolutionWithPartialCompilation == documentId;
if (reuseExistingPartialSolution)
{
var tracker = this.GetCompilationTracker(documentId.ProjectId);
var newTracker = tracker.FreezePartialStateWithTree(this, doc, tree, cancellationToken);
SolutionLogger.UseExistingPartialSolution();
return currentPartialSolution;
}
var newIdToProjectStateMap = _projectIdToProjectStateMap.SetItem(documentId.ProjectId, newTracker.ProjectState);
var newIdToTrackerMap = _projectIdToTrackerMap.SetItem(documentId.ProjectId, newTracker);
// if we don't have one or it is stale, create a new partial solution
var tracker = this.GetCompilationTracker(documentId.ProjectId);
var newTracker = tracker.FreezePartialStateWithTree(this, doc, tree, cancellationToken);
currentPartialSolution = this.Branch(
idToProjectStateMap: newIdToProjectStateMap,
projectIdToTrackerMap: newIdToTrackerMap,
dependencyGraph: CreateDependencyGraph(_projectIds, newIdToProjectStateMap));
var newIdToProjectStateMap = _projectIdToProjectStateMap.SetItem(documentId.ProjectId, newTracker.ProjectState);
var newIdToTrackerMap = _projectIdToTrackerMap.SetItem(documentId.ProjectId, newTracker);
_latestSolutionWithPartialCompilation = new WeakReference<SolutionState>(currentPartialSolution);
_timeOfLatestSolutionWithPartialCompilation = DateTime.UtcNow;
_documentIdOfLatestSolutionWithPartialCompilation = documentId;
}
currentPartialSolution = this.Branch(
idToProjectStateMap: newIdToProjectStateMap,
projectIdToTrackerMap: newIdToTrackerMap,
dependencyGraph: CreateDependencyGraph(_projectIds, newIdToProjectStateMap));
_latestSolutionWithPartialCompilation = new WeakReference<SolutionState>(currentPartialSolution);
_timeOfLatestSolutionWithPartialCompilation = DateTime.UtcNow;
_documentIdOfLatestSolutionWithPartialCompilation = documentId;
SolutionLogger.CreatePartialSolution();
return currentPartialSolution;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册