From 7641c77848564be5c7e1a34985c4db59d13b2d12 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Thu, 2 Jun 2022 12:24:35 -0700 Subject: [PATCH 1/6] Allow our statistic/histogram log aggregators to directly take TimeSpans We (mostly) use these to track time, but rather than just letting them directly take a TimeSpan, we were expecting each of the callers to distill it down to milliseconds and the pass it as an integer. This actually clarifies a current surprise that some of our code calls the data points "ticks" but they're actually logging milliseconds, but that wasn't obvious since there were just ints being passed around everywhere. Even for the cases we were passing around milliseconds, what we were often doing is taking a TimeSpan, grabbing it's TotalMilliseconds and then: - casting it to an int to pass around to our logging functions - casting that to a decimal to pass to the log aggregators - doing decimal division to figure out which bucket it goes in - doing a Math.Floor on that result - casting that result back to an int If we just keep everything internally as an int, the division will already round down and we can avoid all the random extra casting. --- .../AsyncCompletion/AsyncCompletionLogger.cs | 29 ++++++++++--------- .../AsyncCompletion/CompletionSource.cs | 6 ++-- .../AsyncCompletion/ItemManager.cs | 4 +-- .../AbstractChangeSignatureService.cs | 2 +- .../ChangeSignatureTelemetryLogger.cs | 7 +++-- .../Log/CompletionProvidersLogger.cs | 11 +++---- ...ExtensionMethodImportCompletionProvider.cs | 7 +++-- .../AbstractTypeImportCompletionProvider.cs | 7 ++--- .../ExtensionMethodImportCompletionHelper.cs | 10 +++---- .../SerializableUnimportedExtensionMethods.cs | 13 +++++---- .../Handler/RequestTelemetryLogger.cs | 4 +-- .../InheritanceMarginLogger.cs | 2 +- .../Portable/Log/HistogramLogAggregator.cs | 14 ++++++--- .../Portable/Log/StatisticLogAggregator.cs | 7 +++++ 14 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs index bcd12a505f7cc..ff3080b8a7d92 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using Microsoft.CodeAnalysis.Internal.Log; namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion @@ -56,8 +57,8 @@ internal static void LogImportCompletionGetContext(bool isBlocking, bool delayed internal static void LogSessionWithDelayedImportCompletionIncludedInUpdate() => s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate); - internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(int count) => - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, count); + internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(TimeSpan timeSpan) => + s_histogramLogAggregator.IncreaseCount((int)ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan); internal static void LogDelayedImportCompletionIncluded() => s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithTypeImportCompletionEnabled); @@ -68,36 +69,36 @@ internal static void LogExpanderUsage() => internal static void LogGetDefaultsMatchTicksDataPoint(int count) => s_statisticLogAggregator.AddDataPoint((int)ActionInfo.GetDefaultsMatchTicks, count); - internal static void LogSourceInitializationTicksDataPoint(int count) + internal static void LogSourceInitializationTicksDataPoint(TimeSpan elapsed) { - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.SourceInitializationTicks, count); - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.SourceInitializationTicks, count); + s_statisticLogAggregator.AddDataPoint((int)ActionInfo.SourceInitializationTicks, elapsed); + s_histogramLogAggregator.IncreaseCount((int)ActionInfo.SourceInitializationTicks, elapsed); } - internal static void LogSourceGetContextTicksDataPoint(int count, bool isCanceled) + internal static void LogSourceGetContextTicksDataPoint(TimeSpan elapsed, bool isCanceled) { var key = isCanceled ? ActionInfo.SourceGetContextCanceledTicks : ActionInfo.SourceGetContextCompletedTicks; - s_statisticLogAggregator.AddDataPoint((int)key, count); - s_histogramLogAggregator.IncreaseCount((int)key, count); + s_statisticLogAggregator.AddDataPoint((int)key, elapsed); + s_histogramLogAggregator.IncreaseCount((int)key, elapsed); } - internal static void LogItemManagerSortTicksDataPoint(int count) + internal static void LogItemManagerSortTicksDataPoint(TimeSpan elapsed) { - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ItemManagerSortTicks, count); - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.ItemManagerSortTicks, count); + s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ItemManagerSortTicks, elapsed); + s_histogramLogAggregator.IncreaseCount((int)ActionInfo.ItemManagerSortTicks, elapsed); } - internal static void LogItemManagerUpdateDataPoint(int count, bool isCanceled) + internal static void LogItemManagerUpdateDataPoint(TimeSpan elapsed, bool isCanceled) { var key = isCanceled ? ActionInfo.ItemManagerUpdateCanceledTicks : ActionInfo.ItemManagerUpdateCompletedTicks; - s_statisticLogAggregator.AddDataPoint((int)key, count); - s_histogramLogAggregator.IncreaseCount((int)key, count); + s_statisticLogAggregator.AddDataPoint((int)key, elapsed); + s_histogramLogAggregator.IncreaseCount((int)key, elapsed); } internal static void ReportTelemetry() diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/CompletionSource.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/CompletionSource.cs index 3119a4534f0b2..6b784a4f8b06a 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/CompletionSource.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/CompletionSource.cs @@ -143,7 +143,7 @@ public AsyncCompletionData.CompletionStartData InitializeCompletion( } finally { - AsyncCompletionLogger.LogSourceInitializationTicksDataPoint((int)stopwatch.Elapsed.TotalMilliseconds); + AsyncCompletionLogger.LogSourceInitializationTicksDataPoint(stopwatch.Elapsed); } } @@ -311,7 +311,7 @@ public async Task GetCompletionContextAsync( // There could be a race around the usage of this stopwatch, I ignored it since we just need a rough idea: // we always log the time even if the stopwatch's not started regardless of whether expand items are included intially // (that number can be obtained via another property.) - AsyncCompletionLogger.LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint((int)stopwatch.ElapsedMilliseconds); + AsyncCompletionLogger.LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(stopwatch.Elapsed); return result; }, cancellationToken); @@ -346,7 +346,7 @@ public async Task GetCompletionContextAsync( } finally { - AsyncCompletionLogger.LogSourceGetContextTicksDataPoint((int)totalStopWatch.Elapsed.TotalMilliseconds, isCanceled: cancellationToken.IsCancellationRequested); + AsyncCompletionLogger.LogSourceGetContextTicksDataPoint(totalStopWatch.Elapsed, isCanceled: cancellationToken.IsCancellationRequested); } static VSCompletionContext CombineCompletionContext(VSCompletionContext context1, VSCompletionContext context2) diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/ItemManager.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/ItemManager.cs index a66f2eaff3c7b..e102cad5684b2 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/ItemManager.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/ItemManager.cs @@ -36,7 +36,7 @@ public Task> SortCompletionListAsync( // Sort by default comparer of Roslyn CompletionItem var sortedItems = data.InitialList.OrderBy(CompletionItemData.GetOrAddDummyRoslynItem).ToImmutableArray(); - AsyncCompletionLogger.LogItemManagerSortTicksDataPoint((int)stopwatch.Elapsed.TotalMilliseconds); + AsyncCompletionLogger.LogItemManagerSortTicksDataPoint(stopwatch.Elapsed); return Task.FromResult(sortedItems); } @@ -101,7 +101,7 @@ public Task> SortCompletionListAsync( } finally { - AsyncCompletionLogger.LogItemManagerUpdateDataPoint((int)stopwatch.Elapsed.TotalMilliseconds, isCanceled: cancellationToken.IsCancellationRequested); + AsyncCompletionLogger.LogItemManagerUpdateDataPoint(stopwatch.Elapsed, isCanceled: cancellationToken.IsCancellationRequested); } } } diff --git a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs index 9f23f66e57ba0..a3b9b8668f7ce 100644 --- a/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs +++ b/src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs @@ -427,7 +427,7 @@ private static async Task> FindChangeSignatureR } telemetryTimer.Stop(); - ChangeSignatureLogger.LogCommitInformation(telemetryNumberOfDeclarationsToUpdate, telemetryNumberOfReferencesToUpdate, (int)telemetryTimer.ElapsedMilliseconds); + ChangeSignatureLogger.LogCommitInformation(telemetryNumberOfDeclarationsToUpdate, telemetryNumberOfReferencesToUpdate, telemetryTimer.Elapsed); return (currentSolution, confirmationMessage); } diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs index 58c09b0537c93..43f2a65db93c6 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs @@ -4,6 +4,7 @@ #nullable disable +using System; using Microsoft.CodeAnalysis.Internal.Log; namespace Microsoft.CodeAnalysis.ChangeSignature @@ -138,15 +139,15 @@ private static void LogTransformationCombination(bool parametersAdded, bool para } } - internal static void LogCommitInformation(int numDeclarationsUpdated, int numCallSitesUpdated, int elapsedMS) + internal static void LogCommitInformation(int numDeclarationsUpdated, int numCallSitesUpdated, TimeSpan elapsedTime) { s_logAggregator.IncreaseCount((int)ActionInfo.ChangeSignatureCommitCompleted); s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSessionNumberOfDeclarationsUpdated, numDeclarationsUpdated); s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSessionNumberOfCallSitesUpdated, numCallSitesUpdated); - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.CommittedSessionCommitElapsedMS, elapsedMS); - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.CommittedSessionCommitElapsedMS, elapsedMS); + s_statisticLogAggregator.AddDataPoint((int)ActionInfo.CommittedSessionCommitElapsedMS, (int)elapsedTime.TotalMilliseconds); + s_histogramLogAggregator.IncreaseCount((int)ActionInfo.CommittedSessionCommitElapsedMS, elapsedTime); } internal static void LogAddedParameterTypeBinds() diff --git a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs index f0f0030f34b4e..e90d53219af3b 100644 --- a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs +++ b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using Microsoft.CodeAnalysis.Internal.Log; namespace Microsoft.CodeAnalysis.Completion.Log @@ -33,10 +34,10 @@ internal enum ActionInfo CommitUsingDotToAddParenthesis } - internal static void LogTypeImportCompletionTicksDataPoint(int count) + internal static void LogTypeImportCompletionTicksDataPoint(TimeSpan elapsed) { - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.TypeImportCompletionTicks, count); - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.TypeImportCompletionTicks, count); + s_histogramLogAggregator.IncreaseCount((int)ActionInfo.TypeImportCompletionTicks, elapsed); + s_statisticLogAggregator.AddDataPoint((int)ActionInfo.TypeImportCompletionTicks, elapsed); } internal static void LogTypeImportCompletionItemCountDataPoint(int count) => @@ -51,14 +52,14 @@ internal static void LogTypeImportCompletionCacheMiss() => internal static void LogCommitOfTypeImportCompletionItem() => s_logAggregator.IncreaseCount((int)ActionInfo.CommitsOfTypeImportCompletionItem); - internal static void LogExtensionMethodCompletionTicksDataPoint(int total, int getSymbols, int createItems, bool isRemote) + internal static void LogExtensionMethodCompletionTicksDataPoint(TimeSpan total, TimeSpan getSymbols, TimeSpan createItems, bool isRemote) { s_histogramLogAggregator.IncreaseCount((int)ActionInfo.ExtensionMethodCompletionTicks, total); s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionTicks, total); if (isRemote) { - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionRemoteTicks, (total - getSymbols - createItems)); + s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionRemoteTicks, total - getSymbols - createItems); } s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionGetSymbolsTicks, getSymbols); diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractExtensionMethodImportCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractExtensionMethodImportCompletionProvider.cs index 53e4aaf73766d..9c8ba4264dfdc 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractExtensionMethodImportCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractExtensionMethodImportCompletionProvider.cs @@ -14,6 +14,7 @@ using Microsoft.CodeAnalysis.LanguageServices; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions.ContextQuery; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Completion.Providers { @@ -43,7 +44,8 @@ protected override async Task AddCompletionItemsAsync( var syntaxFacts = completionContext.Document.GetRequiredLanguageService(); if (TryGetReceiverTypeSymbol(syntaxContext, syntaxFacts, cancellationToken, out var receiverTypeSymbol)) { - var ticks = Environment.TickCount; + var totalTime = SharedStopwatch.StartNew(); + var inferredTypes = completionContext.CompletionOptions.TargetTypedCompletionFilter ? syntaxContext.InferredTypes : ImmutableArray.Empty; @@ -65,9 +67,8 @@ protected override async Task AddCompletionItemsAsync( completionContext.AddItems(result.CompletionItems.Select(i => Convert(i, receiverTypeKey))); // report telemetry: - var totalTicks = Environment.TickCount - ticks; CompletionProvidersLogger.LogExtensionMethodCompletionTicksDataPoint( - totalTicks, result.GetSymbolsTicks, result.CreateItemsTicks, result.IsRemote); + totalTime.Elapsed, result.GetSymbolsTime, result.CreateItemsTime, result.IsRemote); if (result.IsPartialResult) CompletionProvidersLogger.LogExtensionMethodCompletionPartialResultCount(); diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractTypeImportCompletionProvider.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractTypeImportCompletionProvider.cs index 2e39c11984bcf..21b6828393396 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractTypeImportCompletionProvider.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/AbstractTypeImportCompletionProvider.cs @@ -163,7 +163,7 @@ static bool ShouldAddItem( private class TelemetryCounter { - private readonly int _tick; + private readonly SharedStopwatch _elapsedTime; public int ItemsCount { get; set; } public int ReferenceCount { get; set; } @@ -171,7 +171,7 @@ private class TelemetryCounter public TelemetryCounter() { - _tick = Environment.TickCount; + _elapsedTime = SharedStopwatch.StartNew(); } public void Report() @@ -182,8 +182,7 @@ public void Report() } // cache miss still count towards the cost of completion, so we need to log regardless of it. - var delta = Environment.TickCount - _tick; - CompletionProvidersLogger.LogTypeImportCompletionTicksDataPoint(delta); + CompletionProvidersLogger.LogTypeImportCompletionTicksDataPoint(_elapsedTime.Elapsed); CompletionProvidersLogger.LogTypeImportCompletionItemCountDataPoint(ItemsCount); CompletionProvidersLogger.LogTypeImportCompletionReferenceCountDataPoint(ReferenceCount); } diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs index 7eeb953a45410..d7cb5c655c5ed 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/ExtensionMethodImportCompletionHelper.cs @@ -90,7 +90,7 @@ public static async Task GetUnimportedEx bool isRemote, CancellationToken cancellationToken) { - var ticks = Environment.TickCount; + var stopwatch = SharedStopwatch.StartNew(); // First find symbols of all applicable extension methods. // Workspace's syntax/symbol index is used to avoid iterating every method symbols in the solution. @@ -98,15 +98,15 @@ public static async Task GetUnimportedEx document, position, receiverTypeSymbol, namespaceInScope, cancellationToken).ConfigureAwait(false); var (extentsionMethodSymbols, isPartialResult) = await symbolComputer.GetExtensionMethodSymbolsAsync(forceCacheCreation, hideAdvancedMembers, cancellationToken).ConfigureAwait(false); - var getSymbolsTicks = Environment.TickCount - ticks; - ticks = Environment.TickCount; + var getSymbolsTime = stopwatch.Elapsed; + stopwatch = SharedStopwatch.StartNew(); var compilation = await document.Project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false); var items = ConvertSymbolsToCompletionItems(compilation, extentsionMethodSymbols, targetTypes, cancellationToken); - var createItemsTicks = Environment.TickCount - ticks; + var createItemsTime = stopwatch.Elapsed; - return new SerializableUnimportedExtensionMethods(items, isPartialResult, getSymbolsTicks, createItemsTicks, isRemote); + return new SerializableUnimportedExtensionMethods(items, isPartialResult, getSymbolsTime, createItemsTime, isRemote); } public static async ValueTask BatchUpdateCacheAsync(ImmutableSegmentedList projects, CancellationToken cancellationToken) diff --git a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/SerializableUnimportedExtensionMethods.cs b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/SerializableUnimportedExtensionMethods.cs index b8eee20c00241..b7dc7a3362067 100644 --- a/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/SerializableUnimportedExtensionMethods.cs +++ b/src/Features/Core/Portable/Completion/Providers/ImportCompletionProvider/SerializableUnimportedExtensionMethods.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Immutable; using System.Runtime.Serialization; @@ -17,10 +18,10 @@ internal sealed class SerializableUnimportedExtensionMethods public readonly bool IsPartialResult; [DataMember(Order = 2)] - public readonly int GetSymbolsTicks; + public readonly TimeSpan GetSymbolsTime; [DataMember(Order = 3)] - public readonly int CreateItemsTicks; + public readonly TimeSpan CreateItemsTime; [DataMember(Order = 4)] public readonly bool IsRemote; @@ -28,14 +29,14 @@ internal sealed class SerializableUnimportedExtensionMethods public SerializableUnimportedExtensionMethods( ImmutableArray completionItems, bool isPartialResult, - int getSymbolsTicks, - int createItemsTicks, + TimeSpan getSymbolsTime, + TimeSpan createItemsTime, bool isRemote) { CompletionItems = completionItems; IsPartialResult = isPartialResult; - GetSymbolsTicks = getSymbolsTicks; - CreateItemsTicks = createItemsTicks; + GetSymbolsTime = getSymbolsTime; + CreateItemsTime = createItemsTime; IsRemote = isRemote; } } diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs index e53c233f0caa2..36fe409203657 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs @@ -87,10 +87,10 @@ public void UpdateTelemetryData( { // Find the bucket corresponding to the queued duration and update the count of durations in that bucket. // This is not broken down per method as time in queue is not specific to an LSP method. - _queuedDurationLogAggregator.IncreaseCount(QueuedDurationKey, Convert.ToDecimal(queuedDuration.TotalMilliseconds)); + _queuedDurationLogAggregator.IncreaseCount(QueuedDurationKey, queuedDuration); // Store the request time metrics per LSP method. - _requestDurationLogAggregator.IncreaseCount(methodName, Convert.ToDecimal(ComputeLogValue(requestDuration.TotalMilliseconds))); + _requestDurationLogAggregator.IncreaseCount(methodName, (int)ComputeLogValue(requestDuration.TotalMilliseconds)); _requestCounters.GetOrAdd(methodName, (_) => new Counter()).IncrementCount(result); } diff --git a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs index 253e1dc07c4a9..c4ae806c8eec7 100644 --- a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs +++ b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs @@ -19,7 +19,7 @@ private enum ActionInfo public static void LogGenerateBackgroundInheritanceInfo(TimeSpan elapsedTime) => s_histogramLogAggregator.IncreaseCount( - ActionInfo.GetInheritanceMarginMembers, Convert.ToDecimal(elapsedTime.TotalMilliseconds)); + ActionInfo.GetInheritanceMarginMembers, elapsedTime); public static void LogInheritanceTargetsMenuOpen() => Logger.Log(FunctionId.InheritanceMargin_TargetsMenuOpen, KeyValueLogMessage.Create(LogType.UserAction)); diff --git a/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs b/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs index 8643d926ddc15..44fe12dcf106d 100644 --- a/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs +++ b/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs @@ -32,12 +32,18 @@ public HistogramLogAggregator(int bucketSize, int maxBucketValue) protected override HistogramCounter CreateCounter() => new(_bucketSize, _maxBucketValue, _bucketCount); - public void IncreaseCount(object key, decimal value) + public void IncreaseCount(object key, int value) { var counter = GetCounter(key); counter.IncreaseCount(value); } + public void IncreaseCount(object key, TimeSpan timeSpan) + { + var counter = GetCounter(key); + counter.IncreaseCount((int)timeSpan.TotalMilliseconds); + } + public HistogramCounter? GetValue(object key) { TryGetCounter(key, out var counter); @@ -62,7 +68,7 @@ public HistogramCounter(int bucketSize, int maxBucketValue, int bucketCount) _buckets = new int[BucketCount]; } - public void IncreaseCount(decimal value) + public void IncreaseCount(int value) { var bucket = GetBucket(value); _buckets[bucket]++; @@ -86,9 +92,9 @@ public string GetBucketsAsString() return pooledStringBuilder.ToStringAndFree(); } - private int GetBucket(decimal value) + private int GetBucket(int value) { - var bucket = (int)Math.Floor(value / BucketSize); + var bucket = value / BucketSize; if (bucket >= BucketCount) { bucket = BucketCount - 1; diff --git a/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs b/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs index c0dad86c05102..0c5d04a10bd35 100644 --- a/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs +++ b/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs @@ -4,6 +4,8 @@ #nullable disable +using System; + namespace Microsoft.CodeAnalysis.Internal.Log { internal sealed class StatisticLogAggregator : AbstractLogAggregator @@ -17,6 +19,11 @@ public void AddDataPoint(object key, int value) counter.AddDataPoint(value); } + public void AddDataPoint(object key, TimeSpan timeSpan) + { + AddDataPoint(key, (int)timeSpan.TotalMilliseconds); + } + public StatisticResult GetStaticticResult(object key) { if (TryGetCounter(key, out var counter)) From ef5a90a719f4a62b7a4390b2146326adedaf6f14 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Thu, 2 Jun 2022 13:32:13 -0700 Subject: [PATCH 2/6] Make our log aggregators generic on the key --- .../AsyncCompletion/AsyncCompletionLogger.cs | 44 ++++++------- .../ChangeSignatureTelemetryLogger.cs | 62 +++++++++---------- .../Log/CompletionProvidersLogger.cs | 38 ++++++------ .../EditAndContinue/DebuggingSession.cs | 2 +- .../SolutionCrawler/SolutionCrawlerLogger.cs | 47 +++++++------- .../SolutionCrawlerRegistrationService.cs | 2 +- ...oordinator.IncrementalAnalyzerProcessor.cs | 8 ++- .../SolutionCrawler/WorkCoordinator.cs | 4 +- ...sticAnalyzerService_IncrementalAnalyzer.cs | 2 +- .../Handler/RequestTelemetryLogger.cs | 12 ++-- .../InheritanceMarginLogger.cs | 2 +- .../CommonFixAllState.cs | 2 +- .../Portable/Log/HistogramLogAggregator.cs | 8 +-- .../Portable/Log/StatisticLogAggregator.cs | 8 +-- .../Workspace/Solution/SolutionLogger.cs | 2 +- .../Core/Log/AbstractLogAggregator.cs | 14 ++--- .../Workspace/Core/Log/LogAggregator.cs | 10 +-- 17 files changed, 135 insertions(+), 132 deletions(-) diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs index ff3080b8a7d92..5e283a3cd4fd6 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs @@ -9,9 +9,9 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncComplet { internal static class AsyncCompletionLogger { - private static readonly LogAggregator s_logAggregator = new(); - private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); - private static readonly HistogramLogAggregator s_histogramLogAggregator = new(25, 500); + private static readonly LogAggregator s_logAggregator = new(); + private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); + private static readonly HistogramLogAggregator s_histogramLogAggregator = new(25, 500); private enum ActionInfo { @@ -45,34 +45,34 @@ private enum ActionInfo internal static void LogImportCompletionGetContext(bool isBlocking, bool delayed) { - s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithTypeImportCompletionEnabled); + s_logAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); if (isBlocking) - s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithImportCompletionBlocking); + s_logAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionBlocking); if (delayed) - s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithImportCompletionDelayed); + s_logAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionDelayed); } internal static void LogSessionWithDelayedImportCompletionIncludedInUpdate() => - s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate); + s_logAggregator.IncreaseCount(ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate); internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(TimeSpan timeSpan) => - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan); + s_histogramLogAggregator.IncreaseCount(ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan); internal static void LogDelayedImportCompletionIncluded() => - s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithTypeImportCompletionEnabled); + s_logAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); internal static void LogExpanderUsage() => - s_logAggregator.IncreaseCount((int)ActionInfo.ExpanderUsageCount); + s_logAggregator.IncreaseCount(ActionInfo.ExpanderUsageCount); internal static void LogGetDefaultsMatchTicksDataPoint(int count) => - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.GetDefaultsMatchTicks, count); + s_statisticLogAggregator.AddDataPoint(ActionInfo.GetDefaultsMatchTicks, count); internal static void LogSourceInitializationTicksDataPoint(TimeSpan elapsed) { - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.SourceInitializationTicks, elapsed); - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.SourceInitializationTicks, elapsed); + s_statisticLogAggregator.AddDataPoint(ActionInfo.SourceInitializationTicks, elapsed); + s_histogramLogAggregator.IncreaseCount(ActionInfo.SourceInitializationTicks, elapsed); } internal static void LogSourceGetContextTicksDataPoint(TimeSpan elapsed, bool isCanceled) @@ -81,14 +81,14 @@ internal static void LogSourceGetContextTicksDataPoint(TimeSpan elapsed, bool is ? ActionInfo.SourceGetContextCanceledTicks : ActionInfo.SourceGetContextCompletedTicks; - s_statisticLogAggregator.AddDataPoint((int)key, elapsed); - s_histogramLogAggregator.IncreaseCount((int)key, elapsed); + s_statisticLogAggregator.AddDataPoint(key, elapsed); + s_histogramLogAggregator.IncreaseCount(key, elapsed); } internal static void LogItemManagerSortTicksDataPoint(TimeSpan elapsed) { - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ItemManagerSortTicks, elapsed); - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.ItemManagerSortTicks, elapsed); + s_statisticLogAggregator.AddDataPoint(ActionInfo.ItemManagerSortTicks, elapsed); + s_histogramLogAggregator.IncreaseCount(ActionInfo.ItemManagerSortTicks, elapsed); } internal static void LogItemManagerUpdateDataPoint(TimeSpan elapsed, bool isCanceled) @@ -97,8 +97,8 @@ internal static void LogItemManagerUpdateDataPoint(TimeSpan elapsed, bool isCanc ? ActionInfo.ItemManagerUpdateCanceledTicks : ActionInfo.ItemManagerUpdateCompletedTicks; - s_statisticLogAggregator.AddDataPoint((int)key, elapsed); - s_histogramLogAggregator.IncreaseCount((int)key, elapsed); + s_statisticLogAggregator.AddDataPoint(key, elapsed); + s_histogramLogAggregator.IncreaseCount(key, elapsed); } internal static void ReportTelemetry() @@ -107,7 +107,7 @@ internal static void ReportTelemetry() { foreach (var kv in s_statisticLogAggregator) { - var info = ((ActionInfo)kv.Key).ToString("f"); + var info = kv.Key.ToString("f"); var statistics = kv.Value.GetStatisticResult(); m[CreateProperty(info, nameof(StatisticResult.Maximum))] = statistics.Maximum; @@ -119,13 +119,13 @@ internal static void ReportTelemetry() foreach (var kv in s_logAggregator) { - var mergeInfo = ((ActionInfo)kv.Key).ToString("f"); + var mergeInfo = kv.Key.ToString("f"); m[mergeInfo] = kv.Value.GetCount(); } foreach (var kv in s_histogramLogAggregator) { - var info = ((ActionInfo)kv.Key).ToString("f"); + var info = kv.Key.ToString("f"); m[$"{info}.BucketSize"] = kv.Value.BucketSize; m[$"{info}.MaxBucketValue"] = kv.Value.MaxBucketValue; m[$"{info}.Buckets"] = kv.Value.GetBucketsAsString(); diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs index 43f2a65db93c6..161a9fbd0cf4c 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs @@ -15,9 +15,9 @@ internal class ChangeSignatureLogger private const string Minimum = nameof(Minimum); private const string Mean = nameof(Mean); - private static readonly LogAggregator s_logAggregator = new(); - private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); - private static readonly HistogramLogAggregator s_histogramLogAggregator = new(bucketSize: 1000, maxBucketValue: 30000); + private static readonly LogAggregator s_logAggregator = new(); + private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); + private static readonly HistogramLogAggregator s_histogramLogAggregator = new(bucketSize: 1000, maxBucketValue: 30000); internal enum ActionInfo { @@ -63,31 +63,31 @@ internal enum ActionInfo } internal static void LogChangeSignatureDialogLaunched() => - s_logAggregator.IncreaseCount((int)ActionInfo.ChangeSignatureDialogLaunched); + s_logAggregator.IncreaseCount(ActionInfo.ChangeSignatureDialogLaunched); internal static void LogChangeSignatureDialogCommitted() => - s_logAggregator.IncreaseCount((int)ActionInfo.ChangeSignatureDialogCommitted); + s_logAggregator.IncreaseCount(ActionInfo.ChangeSignatureDialogCommitted); internal static void LogAddParameterDialogLaunched() => - s_logAggregator.IncreaseCount((int)ActionInfo.AddParameterDialogLaunched); + s_logAggregator.IncreaseCount(ActionInfo.AddParameterDialogLaunched); internal static void LogAddParameterDialogCommitted() => - s_logAggregator.IncreaseCount((int)ActionInfo.AddParameterDialogCommitted); + s_logAggregator.IncreaseCount(ActionInfo.AddParameterDialogCommitted); internal static void LogTransformationInformation(int numOriginalParameters, int numParametersAdded, int numParametersRemoved, bool anyParametersReordered) { LogTransformationCombination(numParametersAdded > 0, numParametersRemoved > 0, anyParametersReordered); - s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSession_OriginalParameterCount, numOriginalParameters); + s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSession_OriginalParameterCount, numOriginalParameters); if (numParametersAdded > 0) { - s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSessionWithAdded_NumberAdded, numParametersAdded); + s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionWithAdded_NumberAdded, numParametersAdded); } if (numParametersRemoved > 0) { - s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSessionWithRemoved_NumberRemoved, numParametersRemoved); + s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionWithRemoved_NumberRemoved, numParametersRemoved); } } @@ -96,88 +96,88 @@ private static void LogTransformationCombination(bool parametersAdded, bool para // All three transformations if (parametersAdded && parametersRemoved && parametersReordered) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionAddedRemovedReordered); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedRemovedReordered); return; } // Two transformations if (parametersAdded && parametersRemoved) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionAddedRemovedOnly); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedRemovedOnly); return; } if (parametersAdded && parametersReordered) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionAddedReorderedOnly); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedReorderedOnly); return; } if (parametersRemoved && parametersReordered) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionRemovedReorderedOnly); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionRemovedReorderedOnly); return; } // One transformation if (parametersAdded) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionAddedOnly); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedOnly); return; } if (parametersRemoved) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionRemovedOnly); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionRemovedOnly); return; } if (parametersReordered) { - s_logAggregator.IncreaseCount((int)ActionInfo.CommittedSessionReorderedOnly); + s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionReorderedOnly); return; } } internal static void LogCommitInformation(int numDeclarationsUpdated, int numCallSitesUpdated, TimeSpan elapsedTime) { - s_logAggregator.IncreaseCount((int)ActionInfo.ChangeSignatureCommitCompleted); + s_logAggregator.IncreaseCount(ActionInfo.ChangeSignatureCommitCompleted); - s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSessionNumberOfDeclarationsUpdated, numDeclarationsUpdated); - s_logAggregator.IncreaseCountBy((int)ActionInfo.CommittedSessionNumberOfCallSitesUpdated, numCallSitesUpdated); + s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfDeclarationsUpdated, numDeclarationsUpdated); + s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfCallSitesUpdated, numCallSitesUpdated); - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.CommittedSessionCommitElapsedMS, (int)elapsedTime.TotalMilliseconds); - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.CommittedSessionCommitElapsedMS, elapsedTime); + s_statisticLogAggregator.AddDataPoint(ActionInfo.CommittedSessionCommitElapsedMS, (int)elapsedTime.TotalMilliseconds); + s_histogramLogAggregator.IncreaseCount(ActionInfo.CommittedSessionCommitElapsedMS, elapsedTime); } internal static void LogAddedParameterTypeBinds() { - s_logAggregator.IncreaseCount((int)ActionInfo.AddedParameterTypeBinds); + s_logAggregator.IncreaseCount(ActionInfo.AddedParameterTypeBinds); } internal static void LogAddedParameterRequired() { - s_logAggregator.IncreaseCount((int)ActionInfo.AddedParameterRequired); + s_logAggregator.IncreaseCount(ActionInfo.AddedParameterRequired); } internal static void LogAddedParameter_ValueExplicit() { - s_logAggregator.IncreaseCount((int)ActionInfo.AddedParameterValueExplicit); + s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueExplicit); } internal static void LogAddedParameter_ValueExplicitNamed() { - s_logAggregator.IncreaseCount((int)ActionInfo.AddedParameterValueExplicitNamed); + s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueExplicitNamed); } internal static void LogAddedParameter_ValueTODO() { - s_logAggregator.IncreaseCount((int)ActionInfo.AddedParameterValueTODO); + s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueTODO); } internal static void LogAddedParameter_ValueOmitted() { - s_logAggregator.IncreaseCount((int)ActionInfo.AddedParameterValueOmitted); + s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueOmitted); } internal static void ReportTelemetry() @@ -186,13 +186,13 @@ internal static void ReportTelemetry() { foreach (var kv in s_logAggregator) { - var info = ((ActionInfo)kv.Key).ToString("f"); + var info = kv.Key.ToString("f"); m[info] = kv.Value.GetCount(); } foreach (var kv in s_statisticLogAggregator) { - var info = ((ActionInfo)kv.Key).ToString("f"); + var info = kv.Key.ToString("f"); var statistics = kv.Value.GetStatisticResult(); m[CreateProperty(info, Maximum)] = statistics.Maximum; @@ -202,7 +202,7 @@ internal static void ReportTelemetry() foreach (var kv in s_histogramLogAggregator) { - var info = ((ActionInfo)kv.Key).ToString("f"); + var info = kv.Key.ToString("f"); m[$"{info}.BucketSize"] = kv.Value.BucketSize; m[$"{info}.MaxBucketValue"] = kv.Value.MaxBucketValue; m[$"{info}.Buckets"] = kv.Value.GetBucketsAsString(); diff --git a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs index e90d53219af3b..c001419ddad92 100644 --- a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs +++ b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs @@ -9,10 +9,10 @@ namespace Microsoft.CodeAnalysis.Completion.Log { internal static class CompletionProvidersLogger { - private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); - private static readonly LogAggregator s_logAggregator = new(); + private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); + private static readonly LogAggregator s_logAggregator = new(); - private static readonly HistogramLogAggregator s_histogramLogAggregator = new(bucketSize: 50, maxBucketValue: 1000); + private static readonly HistogramLogAggregator s_histogramLogAggregator = new(bucketSize: 50, maxBucketValue: 1000); internal enum ActionInfo { @@ -36,50 +36,50 @@ internal enum ActionInfo internal static void LogTypeImportCompletionTicksDataPoint(TimeSpan elapsed) { - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.TypeImportCompletionTicks, elapsed); - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.TypeImportCompletionTicks, elapsed); + s_histogramLogAggregator.IncreaseCount(ActionInfo.TypeImportCompletionTicks, elapsed); + s_statisticLogAggregator.AddDataPoint(ActionInfo.TypeImportCompletionTicks, elapsed); } internal static void LogTypeImportCompletionItemCountDataPoint(int count) => - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.TypeImportCompletionItemCount, count); + s_statisticLogAggregator.AddDataPoint(ActionInfo.TypeImportCompletionItemCount, count); internal static void LogTypeImportCompletionReferenceCountDataPoint(int count) => - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.TypeImportCompletionReferenceCount, count); + s_statisticLogAggregator.AddDataPoint(ActionInfo.TypeImportCompletionReferenceCount, count); internal static void LogTypeImportCompletionCacheMiss() => - s_logAggregator.IncreaseCount((int)ActionInfo.TypeImportCompletionCacheMissCount); + s_logAggregator.IncreaseCount(ActionInfo.TypeImportCompletionCacheMissCount); internal static void LogCommitOfTypeImportCompletionItem() => - s_logAggregator.IncreaseCount((int)ActionInfo.CommitsOfTypeImportCompletionItem); + s_logAggregator.IncreaseCount(ActionInfo.CommitsOfTypeImportCompletionItem); internal static void LogExtensionMethodCompletionTicksDataPoint(TimeSpan total, TimeSpan getSymbols, TimeSpan createItems, bool isRemote) { - s_histogramLogAggregator.IncreaseCount((int)ActionInfo.ExtensionMethodCompletionTicks, total); - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionTicks, total); + s_histogramLogAggregator.IncreaseCount(ActionInfo.ExtensionMethodCompletionTicks, total); + s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionTicks, total); if (isRemote) { - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionRemoteTicks, total - getSymbols - createItems); + s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionRemoteTicks, total - getSymbols - createItems); } - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionGetSymbolsTicks, getSymbols); - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionCreateItemsTicks, createItems); + s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionGetSymbolsTicks, getSymbols); + s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionCreateItemsTicks, createItems); } internal static void LogExtensionMethodCompletionMethodsProvidedDataPoint(int count) => - s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ExtensionMethodCompletionMethodsProvided, count); + s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionMethodsProvided, count); internal static void LogCommitOfExtensionMethodImportCompletionItem() => - s_logAggregator.IncreaseCount((int)ActionInfo.CommitsOfExtensionMethodImportCompletionItem); + s_logAggregator.IncreaseCount(ActionInfo.CommitsOfExtensionMethodImportCompletionItem); internal static void LogExtensionMethodCompletionPartialResultCount() => - s_logAggregator.IncreaseCount((int)ActionInfo.ExtensionMethodCompletionPartialResultCount); + s_logAggregator.IncreaseCount(ActionInfo.ExtensionMethodCompletionPartialResultCount); internal static void LogCommitUsingSemicolonToAddParenthesis() => - s_logAggregator.IncreaseCount((int)ActionInfo.CommitUsingSemicolonToAddParenthesis); + s_logAggregator.IncreaseCount(ActionInfo.CommitUsingSemicolonToAddParenthesis); internal static void LogCommitUsingDotToAddParenthesis() => - s_logAggregator.IncreaseCount((int)ActionInfo.CommitUsingDotToAddParenthesis); + s_logAggregator.IncreaseCount(ActionInfo.CommitUsingDotToAddParenthesis); internal static void LogCustomizedCommitToAddParenthesis(char? commitChar) { diff --git a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs index 1f80311fa17b0..401dc3b8feab8 100644 --- a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs +++ b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs @@ -1042,7 +1042,7 @@ async Task GetTaskAsync(ProjectId projectId) private static void ReportTelemetry(DebuggingSessionTelemetry.Data data) { // report telemetry (fire and forget): - _ = Task.Run(() => DebuggingSessionTelemetry.Log(data, Logger.Log, LogAggregator.GetNextId)); + _ = Task.Run(() => DebuggingSessionTelemetry.Log(data, Logger.Log, LogAggregator.GetNextId)); } internal TestAccessor GetTestAccessor() diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs index 181cef3b13f01..df6c28bd75de4 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs @@ -134,10 +134,10 @@ public static void LogWorkCoordinatorShutdownTimeout(int correlationId) })); } - public static void LogWorkspaceEvent(LogAggregator logAggregator, int kind) + public static void LogWorkspaceEvent(LogAggregator logAggregator, WorkspaceChangeKind kind) => logAggregator.IncreaseCount(kind); - public static void LogWorkCoordinatorShutdown(int correlationId, LogAggregator logAggregator) + public static void LogWorkCoordinatorShutdown(int correlationId, LogAggregator logAggregator) { Logger.Log(FunctionId.WorkCoordinator_Shutdown, KeyValueLogMessage.Create(m => { @@ -145,23 +145,23 @@ public static void LogWorkCoordinatorShutdown(int correlationId, LogAggregator l foreach (var kv in logAggregator) { - var change = ((WorkspaceChangeKind)kv.Key).ToString(); + var change = kv.Key.ToString(); m[change] = kv.Value.GetCount(); } })); } - public static void LogGlobalOperation(LogAggregator logAggregator) + public static void LogGlobalOperation(LogAggregator logAggregator) => logAggregator.IncreaseCount(GlobalOperation); - public static void LogActiveFileEnqueue(LogAggregator logAggregator) + public static void LogActiveFileEnqueue(LogAggregator logAggregator) => logAggregator.IncreaseCount(ActiveFileEnqueue); - public static void LogWorkItemEnqueue(LogAggregator logAggregator, ProjectId _) + public static void LogWorkItemEnqueue(LogAggregator logAggregator, ProjectId _) => logAggregator.IncreaseCount(ProjectEnqueue); public static void LogWorkItemEnqueue( - LogAggregator logAggregator, string language, DocumentId? documentId, InvocationReasons reasons, bool lowPriority, SyntaxPath? activeMember, bool added) + LogAggregator logAggregator, string language, DocumentId? documentId, InvocationReasons reasons, bool lowPriority, SyntaxPath? activeMember, bool added) { logAggregator.IncreaseCount(language); logAggregator.IncreaseCount(added ? NewWorkItem : UpdateWorkItem); @@ -183,16 +183,16 @@ public static void LogWorkItemEnqueue( } } - public static void LogHigherPriority(LogAggregator logAggregator, Guid documentId) + public static void LogHigherPriority(LogAggregator logAggregator, Guid documentId) { logAggregator.IncreaseCount(HigherPriority); logAggregator.IncreaseCount(ValueTuple.Create(HigherPriority, documentId)); } - public static void LogResetStates(LogAggregator logAggregator) + public static void LogResetStates(LogAggregator logAggregator) => logAggregator.IncreaseCount(ResetStates); - public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, LogAggregator logAggregator, ImmutableArray analyzers) + public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, LogAggregator logAggregator, ImmutableArray analyzers) { Logger.Log(FunctionId.IncrementalAnalyzerProcessor_Shutdown, KeyValueLogMessage.Create(m => { @@ -207,22 +207,21 @@ public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, if (key is string stringKey) { m[stringKey] = counter.GetCount(); - continue; } - - if (key is ValueTuple propertyNameAndId) + else if (key is ValueTuple propertyNameAndId) { var list = statMap.GetOrAdd(propertyNameAndId.Item1, _ => new List()); list.Add(counter.GetCount()); - continue; } - - throw ExceptionUtilities.Unreachable; + else + { + throw ExceptionUtilities.Unreachable; + } } foreach (var (propertyName, propertyValues) in statMap) { - var result = LogAggregator.GetStatistics(propertyValues); + var result = LogAggregator.GetStatistics(propertyValues); m[CreateProperty(propertyName, Max)] = result.Maximum; m[CreateProperty(propertyName, Min)] = result.Minimum; @@ -253,19 +252,19 @@ private static int GetSolutionHash(Solution solution) private static string CreateProperty(string parent, string child) => parent + "." + child; - public static void LogProcessCloseDocument(LogAggregator logAggregator, Guid documentId) + public static void LogProcessCloseDocument(LogAggregator logAggregator, Guid documentId) { logAggregator.IncreaseCount(CloseDocument); logAggregator.IncreaseCount(ValueTuple.Create(CloseDocument, documentId)); } - public static void LogProcessOpenDocument(LogAggregator logAggregator, Guid documentId) + public static void LogProcessOpenDocument(LogAggregator logAggregator, Guid documentId) { logAggregator.IncreaseCount(OpenDocument); logAggregator.IncreaseCount(ValueTuple.Create(OpenDocument, documentId)); } - public static void LogProcessActiveFileDocument(LogAggregator logAggregator, Guid _, bool processed) + public static void LogProcessActiveFileDocument(LogAggregator logAggregator, Guid _, bool processed) { if (processed) { @@ -277,7 +276,7 @@ public static void LogProcessActiveFileDocument(LogAggregator logAggregator, Gui } } - public static void LogProcessDocument(LogAggregator logAggregator, Guid documentId, bool processed) + public static void LogProcessDocument(LogAggregator logAggregator, Guid documentId, bool processed) { if (processed) { @@ -291,10 +290,10 @@ public static void LogProcessDocument(LogAggregator logAggregator, Guid document logAggregator.IncreaseCount(ValueTuple.Create(ProcessDocument, documentId)); } - public static void LogProcessDocumentNotExist(LogAggregator logAggregator) + public static void LogProcessDocumentNotExist(LogAggregator logAggregator) => logAggregator.IncreaseCount(DocumentNotExist); - public static void LogProcessProject(LogAggregator logAggregator, Guid projectId, bool processed) + public static void LogProcessProject(LogAggregator logAggregator, Guid projectId, bool processed) { if (processed) { @@ -308,7 +307,7 @@ public static void LogProcessProject(LogAggregator logAggregator, Guid projectId logAggregator.IncreaseCount(ValueTuple.Create(ProcessProject, projectId)); } - public static void LogProcessProjectNotExist(LogAggregator logAggregator) + public static void LogProcessProjectNotExist(LogAggregator logAggregator) => logAggregator.IncreaseCount(ProjectNotExist); } } diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs index b5def68057044..f0be197426342 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs @@ -62,7 +62,7 @@ public void EnsureRegistration(Workspace workspace, bool initializeLazily) { Contract.ThrowIfNull(workspace.Kind); - var correlationId = LogAggregator.GetNextId(); + var correlationId = LogAggregator.GetNextId(); lock (_gate) { diff --git a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs index f4a317aceaad5..fdd00d4b09d14 100644 --- a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs +++ b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs @@ -42,7 +42,11 @@ private partial class IncrementalAnalyzerProcessor // NOTE: IDiagnosticAnalyzerService can be null in test environment. private readonly Lazy _lazyDiagnosticAnalyzerService; - private LogAggregator _logAggregator = new(); + /// + /// The keys in this are either a string or a (string, Guid) tuple. See + /// for what is writing this out. + /// + private LogAggregator _logAggregator = new(); public IncrementalAnalyzerProcessor( IAsynchronousOperationListener listener, @@ -150,7 +154,7 @@ private IEnumerable GetOpenDocumentIds() => _registration.Workspace.GetOpenDocumentIds(); private void ResetLogAggregator() - => _logAggregator = new LogAggregator(); + => _logAggregator = new LogAggregator(); private void ReportPendingWorkItemCount() { diff --git a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs index cf3c7a1f63683..56cc2553d27c1 100644 --- a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs +++ b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs @@ -24,7 +24,7 @@ internal sealed partial class WorkCoordinator private readonly Registration _registration; private readonly object _gate = new(); - private readonly LogAggregator _logAggregator = new(); + private readonly LogAggregator _logAggregator = new(); private readonly IAsynchronousOperationListener _listener; private readonly IDocumentTrackingService _documentTrackingService; private readonly IWorkspaceConfigurationService? _workspaceConfigurationService; @@ -192,7 +192,7 @@ private bool NotOurShutdownToken(OperationCanceledException oce) private void ProcessEvent(WorkspaceChangeEventArgs args, string eventName) { - SolutionCrawlerLogger.LogWorkspaceEvent(_logAggregator, (int)args.Kind); + SolutionCrawlerLogger.LogWorkspaceEvent(_logAggregator, args.Kind); // TODO: add telemetry that record how much it takes to process an event (max, min, average and etc) switch (args.Kind) diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs index 4a8469a9ee997..fa0cfce888a92 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs @@ -49,7 +49,7 @@ private DiagnosticIncrementalAnalyzer CreateIncrementalAnalyzerCallback(Workspac // subscribe to active context changed event for new workspace workspace.DocumentActiveContextChanged += OnDocumentActiveContextChanged; - return new DiagnosticIncrementalAnalyzer(this, LogAggregator.GetNextId(), workspace, AnalyzerInfoCache); + return new DiagnosticIncrementalAnalyzer(this, LogAggregator.GetNextId(), workspace, AnalyzerInfoCache); } private void OnDocumentActiveContextChanged(object? sender, DocumentActiveContextChangedEventArgs e) diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs index 36fe409203657..742e7fde95117 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs @@ -24,7 +24,7 @@ internal sealed class RequestTelemetryLogger : IDisposable, ILspService /// /// Histogram to aggregate the time in queue metrics. /// - private readonly HistogramLogAggregator _queuedDurationLogAggregator; + private readonly HistogramLogAggregator _queuedDurationLogAggregator; /// /// Histogram to aggregate total request duration metrics. @@ -34,7 +34,7 @@ internal sealed class RequestTelemetryLogger : IDisposable, ILspService /// This provides highly detailed buckets when duration is in MS, but less detailed /// when the duration is in terms of seconds or minutes. /// - private readonly HistogramLogAggregator _requestDurationLogAggregator; + private readonly HistogramLogAggregator _requestDurationLogAggregator; /// /// Store request counters in a concurrent dictionary as non-mutating LSP requests can @@ -42,9 +42,9 @@ internal sealed class RequestTelemetryLogger : IDisposable, ILspService /// private readonly ConcurrentDictionary _requestCounters; - private readonly LogAggregator _findDocumentResults; + private readonly LogAggregator _findDocumentResults; - private readonly LogAggregator _usedForkedSolutionCounter; + private readonly LogAggregator _usedForkedSolutionCounter; private int _disposed; @@ -57,11 +57,11 @@ public RequestTelemetryLogger(string serverTypeName) // Buckets queued duration into 10ms buckets with the last bucket starting at 1000ms. // Queue times are relatively short and fall under 50ms, so tracking past 1000ms is not useful. - _queuedDurationLogAggregator = new HistogramLogAggregator(bucketSize: 10, maxBucketValue: 1000); + _queuedDurationLogAggregator = new HistogramLogAggregator(bucketSize: 10, maxBucketValue: 1000); // Since this is a log based histogram, these are appropriate bucket sizes for the log data. // A bucket at 1 corresponds to ~26ms, while the max bucket value corresponds to ~17minutes - _requestDurationLogAggregator = new HistogramLogAggregator(bucketSize: 1, maxBucketValue: 40); + _requestDurationLogAggregator = new HistogramLogAggregator(bucketSize: 1, maxBucketValue: 40); } public void UpdateFindDocumentTelemetryData(bool success, string? workspaceKind) diff --git a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs index c4ae806c8eec7..9d192e939f2fe 100644 --- a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs +++ b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs @@ -10,7 +10,7 @@ namespace Microsoft.VisualStudio.LanguageServices.InheritanceMargin internal static class InheritanceMarginLogger { // 1 sec per bucket, and if it takes more than 1 min, then this log is considered as time-out in the last bucket. - private static readonly HistogramLogAggregator s_histogramLogAggregator = new(1000, 60000); + private static readonly HistogramLogAggregator s_histogramLogAggregator = new(1000, 60000); private enum ActionInfo { diff --git a/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs b/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs index 9f051c30b102e..5e520fb5a3228 100644 --- a/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs +++ b/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs @@ -13,7 +13,7 @@ internal abstract partial class CommonFixAllState { - public int CorrelationId { get; } = LogAggregator.GetNextId(); + public int CorrelationId { get; } = LogAggregator.GetNextId(); public TFixAllProvider FixAllProvider { get; } public string? CodeActionEquivalenceKey { get; } public TProvider Provider { get; } diff --git a/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs b/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs index 44fe12dcf106d..670fa554761c0 100644 --- a/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs +++ b/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Internal.Log /// /// Defines a log aggregator to create a histogram /// - internal sealed class HistogramLogAggregator : AbstractLogAggregator + internal sealed class HistogramLogAggregator : AbstractLogAggregator.HistogramCounter> { private readonly int _bucketSize; private readonly int _maxBucketValue; @@ -32,19 +32,19 @@ public HistogramLogAggregator(int bucketSize, int maxBucketValue) protected override HistogramCounter CreateCounter() => new(_bucketSize, _maxBucketValue, _bucketCount); - public void IncreaseCount(object key, int value) + public void IncreaseCount(TKey key, int value) { var counter = GetCounter(key); counter.IncreaseCount(value); } - public void IncreaseCount(object key, TimeSpan timeSpan) + public void IncreaseCount(TKey key, TimeSpan timeSpan) { var counter = GetCounter(key); counter.IncreaseCount((int)timeSpan.TotalMilliseconds); } - public HistogramCounter? GetValue(object key) + public HistogramCounter? GetValue(TKey key) { TryGetCounter(key, out var counter); return counter; diff --git a/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs b/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs index 0c5d04a10bd35..afe08bbbb0972 100644 --- a/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs +++ b/src/Workspaces/Core/Portable/Log/StatisticLogAggregator.cs @@ -8,23 +8,23 @@ namespace Microsoft.CodeAnalysis.Internal.Log { - internal sealed class StatisticLogAggregator : AbstractLogAggregator + internal sealed class StatisticLogAggregator : AbstractLogAggregator.StatisticCounter> { protected override StatisticCounter CreateCounter() => new(); - public void AddDataPoint(object key, int value) + public void AddDataPoint(TKey key, int value) { var counter = GetCounter(key); counter.AddDataPoint(value); } - public void AddDataPoint(object key, TimeSpan timeSpan) + public void AddDataPoint(TKey key, TimeSpan timeSpan) { AddDataPoint(key, (int)timeSpan.TotalMilliseconds); } - public StatisticResult GetStaticticResult(object key) + public StatisticResult GetStaticticResult(TKey key) { if (TryGetCounter(key, out var counter)) { diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs index c59b5ecfe193a..6cc780a7ac2b6 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Logging { internal static class SolutionLogger { - private static readonly LogAggregator s_logAggregator = new(); + private static readonly LogAggregator s_logAggregator = new(); public static void UseExistingPartialProjectState() => s_logAggregator.IncreaseCount(nameof(UseExistingPartialProjectState)); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs index 4a17ae05cfdd3..e000a1c7e74ab 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs @@ -17,19 +17,19 @@ namespace Microsoft.CodeAnalysis.Internal.Log /// /// helper class to aggregate some numeric value log in client side /// - internal abstract class AbstractLogAggregator : IEnumerable> + internal abstract class AbstractLogAggregator : IEnumerable> { private static int s_globalId; - private readonly ConcurrentDictionary _map = new(concurrencyLevel: 2, capacity: 2); - private readonly Func _createCounter; + private readonly ConcurrentDictionary _map = new(concurrencyLevel: 2, capacity: 2); + private readonly Func _createCounter; protected AbstractLogAggregator() { _createCounter = _ => CreateCounter(); } - protected abstract T CreateCounter(); + protected abstract TValue CreateCounter(); public static int GetNextId() => Interlocked.Increment(ref s_globalId); @@ -65,17 +65,17 @@ public static StatisticResult GetStatistics(List values) public bool IsEmpty => _map.IsEmpty; - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() => _map.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); [PerformanceSensitive("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1279909", AllowCaptures = false)] - protected T GetCounter(object key) + protected TValue GetCounter(TKey key) => _map.GetOrAdd(key, _createCounter); - protected bool TryGetCounter(object key, out T counter) + protected bool TryGetCounter(TKey key, out TValue counter) { if (_map.TryGetValue(key, out counter)) { diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs index 96aa557eaf4ff..7e1a6669b7765 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs @@ -8,30 +8,30 @@ namespace Microsoft.CodeAnalysis.Internal.Log { - internal class LogAggregator : AbstractLogAggregator + internal class LogAggregator : AbstractLogAggregator.Counter> { protected override Counter CreateCounter() => new(); - public void SetCount(object key, int count) + public void SetCount(TKey key, int count) { var counter = GetCounter(key); counter.SetCount(count); } - public void IncreaseCount(object key) + public void IncreaseCount(TKey key) { var counter = GetCounter(key); counter.IncreaseCount(); } - public void IncreaseCountBy(object key, int value) + public void IncreaseCountBy(TKey key, int value) { var counter = GetCounter(key); counter.IncreaseCountBy(value); } - public int GetCount(object key) + public int GetCount(TKey key) { if (TryGetCounter(key, out var counter)) { From 49b0ad5337bbfc861adc6cbbfb88b401b60c2673 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Tue, 7 Jun 2022 16:37:28 -0700 Subject: [PATCH 3/6] Rename LogAggregator to CountLogAggregator Makes it clear this is not a base type of the other ones. --- .../AsyncCompletion/AsyncCompletionLogger.cs | 16 +++--- .../ChangeSignatureTelemetryLogger.cs | 50 +++++++++---------- .../Log/CompletionProvidersLogger.cs | 16 +++--- .../EditAndContinue/DebuggingSession.cs | 2 +- .../SolutionCrawler/SolutionCrawlerLogger.cs | 34 ++++++------- .../SolutionCrawlerRegistrationService.cs | 2 +- ...oordinator.IncrementalAnalyzerProcessor.cs | 4 +- .../SolutionCrawler/WorkCoordinator.cs | 2 +- ...sticAnalyzerService_IncrementalAnalyzer.cs | 2 +- .../Handler/RequestTelemetryLogger.cs | 4 +- .../CommonFixAllState.cs | 2 +- .../Workspace/Solution/SolutionLogger.cs | 2 +- ...LogAggregator.cs => CountLogAggregator.cs} | 2 +- .../Core/WorkspaceExtensions.projitems | 2 +- 14 files changed, 70 insertions(+), 70 deletions(-) rename src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/{LogAggregator.cs => CountLogAggregator.cs} (94%) diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs index 5e283a3cd4fd6..003f96f6d042e 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncComplet { internal static class AsyncCompletionLogger { - private static readonly LogAggregator s_logAggregator = new(); + private static readonly CountLogAggregator s_countLogAggregator = new(); private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); private static readonly HistogramLogAggregator s_histogramLogAggregator = new(25, 500); @@ -45,26 +45,26 @@ private enum ActionInfo internal static void LogImportCompletionGetContext(bool isBlocking, bool delayed) { - s_logAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); + s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); if (isBlocking) - s_logAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionBlocking); + s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionBlocking); if (delayed) - s_logAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionDelayed); + s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionDelayed); } internal static void LogSessionWithDelayedImportCompletionIncludedInUpdate() => - s_logAggregator.IncreaseCount(ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate); + s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate); internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(TimeSpan timeSpan) => s_histogramLogAggregator.IncreaseCount(ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan); internal static void LogDelayedImportCompletionIncluded() => - s_logAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); + s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); internal static void LogExpanderUsage() => - s_logAggregator.IncreaseCount(ActionInfo.ExpanderUsageCount); + s_countLogAggregator.IncreaseCount(ActionInfo.ExpanderUsageCount); internal static void LogGetDefaultsMatchTicksDataPoint(int count) => s_statisticLogAggregator.AddDataPoint(ActionInfo.GetDefaultsMatchTicks, count); @@ -117,7 +117,7 @@ internal static void ReportTelemetry() m[CreateProperty(info, nameof(StatisticResult.Count))] = statistics.Count; } - foreach (var kv in s_logAggregator) + foreach (var kv in s_countLogAggregator) { var mergeInfo = kv.Key.ToString("f"); m[mergeInfo] = kv.Value.GetCount(); diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs index 161a9fbd0cf4c..c03fe028988dc 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs @@ -15,7 +15,7 @@ internal class ChangeSignatureLogger private const string Minimum = nameof(Minimum); private const string Mean = nameof(Mean); - private static readonly LogAggregator s_logAggregator = new(); + private static readonly CountLogAggregator s_countLogAggregator = new(); private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); private static readonly HistogramLogAggregator s_histogramLogAggregator = new(bucketSize: 1000, maxBucketValue: 30000); @@ -63,31 +63,31 @@ internal enum ActionInfo } internal static void LogChangeSignatureDialogLaunched() => - s_logAggregator.IncreaseCount(ActionInfo.ChangeSignatureDialogLaunched); + s_countLogAggregator.IncreaseCount(ActionInfo.ChangeSignatureDialogLaunched); internal static void LogChangeSignatureDialogCommitted() => - s_logAggregator.IncreaseCount(ActionInfo.ChangeSignatureDialogCommitted); + s_countLogAggregator.IncreaseCount(ActionInfo.ChangeSignatureDialogCommitted); internal static void LogAddParameterDialogLaunched() => - s_logAggregator.IncreaseCount(ActionInfo.AddParameterDialogLaunched); + s_countLogAggregator.IncreaseCount(ActionInfo.AddParameterDialogLaunched); internal static void LogAddParameterDialogCommitted() => - s_logAggregator.IncreaseCount(ActionInfo.AddParameterDialogCommitted); + s_countLogAggregator.IncreaseCount(ActionInfo.AddParameterDialogCommitted); internal static void LogTransformationInformation(int numOriginalParameters, int numParametersAdded, int numParametersRemoved, bool anyParametersReordered) { LogTransformationCombination(numParametersAdded > 0, numParametersRemoved > 0, anyParametersReordered); - s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSession_OriginalParameterCount, numOriginalParameters); + s_countLogAggregator.IncreaseCountBy(ActionInfo.CommittedSession_OriginalParameterCount, numOriginalParameters); if (numParametersAdded > 0) { - s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionWithAdded_NumberAdded, numParametersAdded); + s_countLogAggregator.IncreaseCountBy(ActionInfo.CommittedSessionWithAdded_NumberAdded, numParametersAdded); } if (numParametersRemoved > 0) { - s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionWithRemoved_NumberRemoved, numParametersRemoved); + s_countLogAggregator.IncreaseCountBy(ActionInfo.CommittedSessionWithRemoved_NumberRemoved, numParametersRemoved); } } @@ -96,55 +96,55 @@ private static void LogTransformationCombination(bool parametersAdded, bool para // All three transformations if (parametersAdded && parametersRemoved && parametersReordered) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedRemovedReordered); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedRemovedReordered); return; } // Two transformations if (parametersAdded && parametersRemoved) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedRemovedOnly); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedRemovedOnly); return; } if (parametersAdded && parametersReordered) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedReorderedOnly); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedReorderedOnly); return; } if (parametersRemoved && parametersReordered) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionRemovedReorderedOnly); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionRemovedReorderedOnly); return; } // One transformation if (parametersAdded) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedOnly); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionAddedOnly); return; } if (parametersRemoved) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionRemovedOnly); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionRemovedOnly); return; } if (parametersReordered) { - s_logAggregator.IncreaseCount(ActionInfo.CommittedSessionReorderedOnly); + s_countLogAggregator.IncreaseCount(ActionInfo.CommittedSessionReorderedOnly); return; } } internal static void LogCommitInformation(int numDeclarationsUpdated, int numCallSitesUpdated, TimeSpan elapsedTime) { - s_logAggregator.IncreaseCount(ActionInfo.ChangeSignatureCommitCompleted); + s_countLogAggregator.IncreaseCount(ActionInfo.ChangeSignatureCommitCompleted); - s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfDeclarationsUpdated, numDeclarationsUpdated); - s_logAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfCallSitesUpdated, numCallSitesUpdated); + s_countLogAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfDeclarationsUpdated, numDeclarationsUpdated); + s_countLogAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfCallSitesUpdated, numCallSitesUpdated); s_statisticLogAggregator.AddDataPoint(ActionInfo.CommittedSessionCommitElapsedMS, (int)elapsedTime.TotalMilliseconds); s_histogramLogAggregator.IncreaseCount(ActionInfo.CommittedSessionCommitElapsedMS, elapsedTime); @@ -152,39 +152,39 @@ internal static void LogCommitInformation(int numDeclarationsUpdated, int numCal internal static void LogAddedParameterTypeBinds() { - s_logAggregator.IncreaseCount(ActionInfo.AddedParameterTypeBinds); + s_countLogAggregator.IncreaseCount(ActionInfo.AddedParameterTypeBinds); } internal static void LogAddedParameterRequired() { - s_logAggregator.IncreaseCount(ActionInfo.AddedParameterRequired); + s_countLogAggregator.IncreaseCount(ActionInfo.AddedParameterRequired); } internal static void LogAddedParameter_ValueExplicit() { - s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueExplicit); + s_countLogAggregator.IncreaseCount(ActionInfo.AddedParameterValueExplicit); } internal static void LogAddedParameter_ValueExplicitNamed() { - s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueExplicitNamed); + s_countLogAggregator.IncreaseCount(ActionInfo.AddedParameterValueExplicitNamed); } internal static void LogAddedParameter_ValueTODO() { - s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueTODO); + s_countLogAggregator.IncreaseCount(ActionInfo.AddedParameterValueTODO); } internal static void LogAddedParameter_ValueOmitted() { - s_logAggregator.IncreaseCount(ActionInfo.AddedParameterValueOmitted); + s_countLogAggregator.IncreaseCount(ActionInfo.AddedParameterValueOmitted); } internal static void ReportTelemetry() { Logger.Log(FunctionId.ChangeSignature_Data, KeyValueLogMessage.Create(m => { - foreach (var kv in s_logAggregator) + foreach (var kv in s_countLogAggregator) { var info = kv.Key.ToString("f"); m[info] = kv.Value.GetCount(); diff --git a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs index c001419ddad92..2bdf26380135a 100644 --- a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs +++ b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Completion.Log internal static class CompletionProvidersLogger { private static readonly StatisticLogAggregator s_statisticLogAggregator = new(); - private static readonly LogAggregator s_logAggregator = new(); + private static readonly CountLogAggregator s_countLogAggregator = new(); private static readonly HistogramLogAggregator s_histogramLogAggregator = new(bucketSize: 50, maxBucketValue: 1000); @@ -47,10 +47,10 @@ internal static void LogTypeImportCompletionReferenceCountDataPoint(int count) = s_statisticLogAggregator.AddDataPoint(ActionInfo.TypeImportCompletionReferenceCount, count); internal static void LogTypeImportCompletionCacheMiss() => - s_logAggregator.IncreaseCount(ActionInfo.TypeImportCompletionCacheMissCount); + s_countLogAggregator.IncreaseCount(ActionInfo.TypeImportCompletionCacheMissCount); internal static void LogCommitOfTypeImportCompletionItem() => - s_logAggregator.IncreaseCount(ActionInfo.CommitsOfTypeImportCompletionItem); + s_countLogAggregator.IncreaseCount(ActionInfo.CommitsOfTypeImportCompletionItem); internal static void LogExtensionMethodCompletionTicksDataPoint(TimeSpan total, TimeSpan getSymbols, TimeSpan createItems, bool isRemote) { @@ -70,16 +70,16 @@ internal static void LogExtensionMethodCompletionMethodsProvidedDataPoint(int co s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionMethodsProvided, count); internal static void LogCommitOfExtensionMethodImportCompletionItem() => - s_logAggregator.IncreaseCount(ActionInfo.CommitsOfExtensionMethodImportCompletionItem); + s_countLogAggregator.IncreaseCount(ActionInfo.CommitsOfExtensionMethodImportCompletionItem); internal static void LogExtensionMethodCompletionPartialResultCount() => - s_logAggregator.IncreaseCount(ActionInfo.ExtensionMethodCompletionPartialResultCount); + s_countLogAggregator.IncreaseCount(ActionInfo.ExtensionMethodCompletionPartialResultCount); internal static void LogCommitUsingSemicolonToAddParenthesis() => - s_logAggregator.IncreaseCount(ActionInfo.CommitUsingSemicolonToAddParenthesis); + s_countLogAggregator.IncreaseCount(ActionInfo.CommitUsingSemicolonToAddParenthesis); internal static void LogCommitUsingDotToAddParenthesis() => - s_logAggregator.IncreaseCount(ActionInfo.CommitUsingDotToAddParenthesis); + s_countLogAggregator.IncreaseCount(ActionInfo.CommitUsingDotToAddParenthesis); internal static void LogCustomizedCommitToAddParenthesis(char? commitChar) { @@ -110,7 +110,7 @@ internal static void ReportTelemetry() m[CreateProperty(info, nameof(statistics.Count))] = statistics.Count; } - foreach (var kv in s_logAggregator) + foreach (var kv in s_countLogAggregator) { var info = ((ActionInfo)kv.Key).ToString("f"); m[info] = kv.Value.GetCount(); diff --git a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs index 401dc3b8feab8..e52921095ebab 100644 --- a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs +++ b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs @@ -1042,7 +1042,7 @@ async Task GetTaskAsync(ProjectId projectId) private static void ReportTelemetry(DebuggingSessionTelemetry.Data data) { // report telemetry (fire and forget): - _ = Task.Run(() => DebuggingSessionTelemetry.Log(data, Logger.Log, LogAggregator.GetNextId)); + _ = Task.Run(() => DebuggingSessionTelemetry.Log(data, Logger.Log, CountLogAggregator.GetNextId)); } internal TestAccessor GetTestAccessor() diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs index df6c28bd75de4..16351c4979471 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs @@ -134,10 +134,10 @@ public static void LogWorkCoordinatorShutdownTimeout(int correlationId) })); } - public static void LogWorkspaceEvent(LogAggregator logAggregator, WorkspaceChangeKind kind) + public static void LogWorkspaceEvent(CountLogAggregator logAggregator, WorkspaceChangeKind kind) => logAggregator.IncreaseCount(kind); - public static void LogWorkCoordinatorShutdown(int correlationId, LogAggregator logAggregator) + public static void LogWorkCoordinatorShutdown(int correlationId, CountLogAggregator logAggregator) { Logger.Log(FunctionId.WorkCoordinator_Shutdown, KeyValueLogMessage.Create(m => { @@ -151,17 +151,17 @@ public static void LogWorkCoordinatorShutdown(int correlationId, LogAggregator logAggregator) + public static void LogGlobalOperation(CountLogAggregator logAggregator) => logAggregator.IncreaseCount(GlobalOperation); - public static void LogActiveFileEnqueue(LogAggregator logAggregator) + public static void LogActiveFileEnqueue(CountLogAggregator logAggregator) => logAggregator.IncreaseCount(ActiveFileEnqueue); - public static void LogWorkItemEnqueue(LogAggregator logAggregator, ProjectId _) + public static void LogWorkItemEnqueue(CountLogAggregator logAggregator, ProjectId _) => logAggregator.IncreaseCount(ProjectEnqueue); public static void LogWorkItemEnqueue( - LogAggregator logAggregator, string language, DocumentId? documentId, InvocationReasons reasons, bool lowPriority, SyntaxPath? activeMember, bool added) + CountLogAggregator logAggregator, string language, DocumentId? documentId, InvocationReasons reasons, bool lowPriority, SyntaxPath? activeMember, bool added) { logAggregator.IncreaseCount(language); logAggregator.IncreaseCount(added ? NewWorkItem : UpdateWorkItem); @@ -183,16 +183,16 @@ public static void LogWorkItemEnqueue( } } - public static void LogHigherPriority(LogAggregator logAggregator, Guid documentId) + public static void LogHigherPriority(CountLogAggregator logAggregator, Guid documentId) { logAggregator.IncreaseCount(HigherPriority); logAggregator.IncreaseCount(ValueTuple.Create(HigherPriority, documentId)); } - public static void LogResetStates(LogAggregator logAggregator) + public static void LogResetStates(CountLogAggregator logAggregator) => logAggregator.IncreaseCount(ResetStates); - public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, LogAggregator logAggregator, ImmutableArray analyzers) + public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, Solution solution, CountLogAggregator logAggregator, ImmutableArray analyzers) { Logger.Log(FunctionId.IncrementalAnalyzerProcessor_Shutdown, KeyValueLogMessage.Create(m => { @@ -221,7 +221,7 @@ public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, foreach (var (propertyName, propertyValues) in statMap) { - var result = LogAggregator.GetStatistics(propertyValues); + var result = CountLogAggregator.GetStatistics(propertyValues); m[CreateProperty(propertyName, Max)] = result.Maximum; m[CreateProperty(propertyName, Min)] = result.Minimum; @@ -252,19 +252,19 @@ private static int GetSolutionHash(Solution solution) private static string CreateProperty(string parent, string child) => parent + "." + child; - public static void LogProcessCloseDocument(LogAggregator logAggregator, Guid documentId) + public static void LogProcessCloseDocument(CountLogAggregator logAggregator, Guid documentId) { logAggregator.IncreaseCount(CloseDocument); logAggregator.IncreaseCount(ValueTuple.Create(CloseDocument, documentId)); } - public static void LogProcessOpenDocument(LogAggregator logAggregator, Guid documentId) + public static void LogProcessOpenDocument(CountLogAggregator logAggregator, Guid documentId) { logAggregator.IncreaseCount(OpenDocument); logAggregator.IncreaseCount(ValueTuple.Create(OpenDocument, documentId)); } - public static void LogProcessActiveFileDocument(LogAggregator logAggregator, Guid _, bool processed) + public static void LogProcessActiveFileDocument(CountLogAggregator logAggregator, Guid _, bool processed) { if (processed) { @@ -276,7 +276,7 @@ public static void LogProcessActiveFileDocument(LogAggregator logAggrega } } - public static void LogProcessDocument(LogAggregator logAggregator, Guid documentId, bool processed) + public static void LogProcessDocument(CountLogAggregator logAggregator, Guid documentId, bool processed) { if (processed) { @@ -290,10 +290,10 @@ public static void LogProcessDocument(LogAggregator logAggregator, Guid logAggregator.IncreaseCount(ValueTuple.Create(ProcessDocument, documentId)); } - public static void LogProcessDocumentNotExist(LogAggregator logAggregator) + public static void LogProcessDocumentNotExist(CountLogAggregator logAggregator) => logAggregator.IncreaseCount(DocumentNotExist); - public static void LogProcessProject(LogAggregator logAggregator, Guid projectId, bool processed) + public static void LogProcessProject(CountLogAggregator logAggregator, Guid projectId, bool processed) { if (processed) { @@ -307,7 +307,7 @@ public static void LogProcessProject(LogAggregator logAggregator, Guid p logAggregator.IncreaseCount(ValueTuple.Create(ProcessProject, projectId)); } - public static void LogProcessProjectNotExist(LogAggregator logAggregator) + public static void LogProcessProjectNotExist(CountLogAggregator logAggregator) => logAggregator.IncreaseCount(ProjectNotExist); } } diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs index f0be197426342..aeccb3e2082ec 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs @@ -62,7 +62,7 @@ public void EnsureRegistration(Workspace workspace, bool initializeLazily) { Contract.ThrowIfNull(workspace.Kind); - var correlationId = LogAggregator.GetNextId(); + var correlationId = CountLogAggregator.GetNextId(); lock (_gate) { diff --git a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs index fdd00d4b09d14..2412aed423528 100644 --- a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs +++ b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.IncrementalAnalyzerProcessor.cs @@ -46,7 +46,7 @@ private partial class IncrementalAnalyzerProcessor /// The keys in this are either a string or a (string, Guid) tuple. See /// for what is writing this out. /// - private LogAggregator _logAggregator = new(); + private CountLogAggregator _logAggregator = new(); public IncrementalAnalyzerProcessor( IAsynchronousOperationListener listener, @@ -154,7 +154,7 @@ private IEnumerable GetOpenDocumentIds() => _registration.Workspace.GetOpenDocumentIds(); private void ResetLogAggregator() - => _logAggregator = new LogAggregator(); + => _logAggregator = new CountLogAggregator(); private void ReportPendingWorkItemCount() { diff --git a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs index 56cc2553d27c1..9484183220b3e 100644 --- a/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs +++ b/src/Features/Core/Portable/SolutionCrawler/WorkCoordinator.cs @@ -24,7 +24,7 @@ internal sealed partial class WorkCoordinator private readonly Registration _registration; private readonly object _gate = new(); - private readonly LogAggregator _logAggregator = new(); + private readonly CountLogAggregator _logAggregator = new(); private readonly IAsynchronousOperationListener _listener; private readonly IDocumentTrackingService _documentTrackingService; private readonly IWorkspaceConfigurationService? _workspaceConfigurationService; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs index fa0cfce888a92..f107aa05a990d 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs @@ -49,7 +49,7 @@ private DiagnosticIncrementalAnalyzer CreateIncrementalAnalyzerCallback(Workspac // subscribe to active context changed event for new workspace workspace.DocumentActiveContextChanged += OnDocumentActiveContextChanged; - return new DiagnosticIncrementalAnalyzer(this, LogAggregator.GetNextId(), workspace, AnalyzerInfoCache); + return new DiagnosticIncrementalAnalyzer(this, CountLogAggregator.GetNextId(), workspace, AnalyzerInfoCache); } private void OnDocumentActiveContextChanged(object? sender, DocumentActiveContextChangedEventArgs e) diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs index 742e7fde95117..8a74043c4b9c7 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs @@ -42,9 +42,9 @@ internal sealed class RequestTelemetryLogger : IDisposable, ILspService /// private readonly ConcurrentDictionary _requestCounters; - private readonly LogAggregator _findDocumentResults; + private readonly CountLogAggregator _findDocumentResults; - private readonly LogAggregator _usedForkedSolutionCounter; + private readonly CountLogAggregator _usedForkedSolutionCounter; private int _disposed; diff --git a/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs b/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs index 5e520fb5a3228..fde6a312f0e04 100644 --- a/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs +++ b/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs @@ -13,7 +13,7 @@ internal abstract partial class CommonFixAllState { - public int CorrelationId { get; } = LogAggregator.GetNextId(); + public int CorrelationId { get; } = CountLogAggregator.GetNextId(); public TFixAllProvider FixAllProvider { get; } public string? CodeActionEquivalenceKey { get; } public TProvider Provider { get; } diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs index 6cc780a7ac2b6..161afc1205301 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionLogger.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Logging { internal static class SolutionLogger { - private static readonly LogAggregator s_logAggregator = new(); + private static readonly CountLogAggregator s_logAggregator = new(); public static void UseExistingPartialProjectState() => s_logAggregator.IncreaseCount(nameof(UseExistingPartialProjectState)); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/CountLogAggregator.cs similarity index 94% rename from src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs rename to src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/CountLogAggregator.cs index 7e1a6669b7765..dd948593ad580 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/LogAggregator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/CountLogAggregator.cs @@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.Internal.Log { - internal class LogAggregator : AbstractLogAggregator.Counter> + internal class CountLogAggregator : AbstractLogAggregator.Counter> { protected override Counter CreateCounter() => new(); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems index e126f5c79a839..f7e95fb1757ee 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems @@ -54,7 +54,7 @@ - + From fcfa678a3e21d06d4d87d790ac93ff2c07cbf0c5 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Tue, 7 Jun 2022 16:48:11 -0700 Subject: [PATCH 4/6] Move the GetNextId method to it's own class --- .../EditAndContinue/DebuggingSession.cs | 2 +- .../SolutionCrawlerRegistrationService.cs | 2 +- ...sticAnalyzerService_IncrementalAnalyzer.cs | 2 +- .../CommonFixAllState.cs | 2 +- .../Core/Portable/Log/CorrelationIdFactory.cs | 19 +++++++++++++++++++ .../Core/Log/AbstractLogAggregator.cs | 5 ----- 6 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/Workspaces/Core/Portable/Log/CorrelationIdFactory.cs diff --git a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs index e52921095ebab..7ff73722dc34e 100644 --- a/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs +++ b/src/Features/Core/Portable/EditAndContinue/DebuggingSession.cs @@ -1042,7 +1042,7 @@ async Task GetTaskAsync(ProjectId projectId) private static void ReportTelemetry(DebuggingSessionTelemetry.Data data) { // report telemetry (fire and forget): - _ = Task.Run(() => DebuggingSessionTelemetry.Log(data, Logger.Log, CountLogAggregator.GetNextId)); + _ = Task.Run(() => DebuggingSessionTelemetry.Log(data, Logger.Log, CorrelationIdFactory.GetNextId)); } internal TestAccessor GetTestAccessor() diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs index aeccb3e2082ec..18a1e2e3aba98 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerRegistrationService.cs @@ -62,7 +62,7 @@ public void EnsureRegistration(Workspace workspace, bool initializeLazily) { Contract.ThrowIfNull(workspace.Kind); - var correlationId = CountLogAggregator.GetNextId(); + var correlationId = CorrelationIdFactory.GetNextId(); lock (_gate) { diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs index f107aa05a990d..4bb863a34fdbd 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/DiagnosticAnalyzerService_IncrementalAnalyzer.cs @@ -49,7 +49,7 @@ private DiagnosticIncrementalAnalyzer CreateIncrementalAnalyzerCallback(Workspac // subscribe to active context changed event for new workspace workspace.DocumentActiveContextChanged += OnDocumentActiveContextChanged; - return new DiagnosticIncrementalAnalyzer(this, CountLogAggregator.GetNextId(), workspace, AnalyzerInfoCache); + return new DiagnosticIncrementalAnalyzer(this, CorrelationIdFactory.GetNextId(), workspace, AnalyzerInfoCache); } private void OnDocumentActiveContextChanged(object? sender, DocumentActiveContextChangedEventArgs e) diff --git a/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs b/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs index fde6a312f0e04..28ea1c9e3d971 100644 --- a/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs +++ b/src/Workspaces/Core/Portable/CodeFixesAndRefactorings/CommonFixAllState.cs @@ -13,7 +13,7 @@ internal abstract partial class CommonFixAllState { - public int CorrelationId { get; } = CountLogAggregator.GetNextId(); + public int CorrelationId { get; } = CorrelationIdFactory.GetNextId(); public TFixAllProvider FixAllProvider { get; } public string? CodeActionEquivalenceKey { get; } public TProvider Provider { get; } diff --git a/src/Workspaces/Core/Portable/Log/CorrelationIdFactory.cs b/src/Workspaces/Core/Portable/Log/CorrelationIdFactory.cs new file mode 100644 index 0000000000000..702f148c1574c --- /dev/null +++ b/src/Workspaces/Core/Portable/Log/CorrelationIdFactory.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace Microsoft.CodeAnalysis.Internal.Log +{ + internal static class CorrelationIdFactory + { + private static int s_globalId; + + public static int GetNextId() + => Interlocked.Increment(ref s_globalId); + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs index e000a1c7e74ab..c0898de5e24bf 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs @@ -19,8 +19,6 @@ namespace Microsoft.CodeAnalysis.Internal.Log /// internal abstract class AbstractLogAggregator : IEnumerable> { - private static int s_globalId; - private readonly ConcurrentDictionary _map = new(concurrencyLevel: 2, capacity: 2); private readonly Func _createCounter; @@ -31,9 +29,6 @@ protected AbstractLogAggregator() protected abstract TValue CreateCounter(); - public static int GetNextId() - => Interlocked.Increment(ref s_globalId); - public static StatisticResult GetStatistics(List values) { if (values.Count == 0) From 2ce3ef97be0a1772026a78c24940ccfe891a642c Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Tue, 7 Jun 2022 17:10:07 -0700 Subject: [PATCH 5/6] Move the helper for computing StatisticResults inside the type --- .../SolutionCrawler/SolutionCrawlerLogger.cs | 2 +- .../Core/Portable/Log/StatisticResult.cs | 90 +++++++++++++++++++ .../Core/Log/AbstractLogAggregator.cs | 78 ---------------- 3 files changed, 91 insertions(+), 79 deletions(-) create mode 100644 src/Workspaces/Core/Portable/Log/StatisticResult.cs diff --git a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs index 16351c4979471..c1e248b062b22 100644 --- a/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs +++ b/src/Features/Core/Portable/SolutionCrawler/SolutionCrawlerLogger.cs @@ -221,7 +221,7 @@ public static void LogIncrementalAnalyzerProcessorStatistics(int correlationId, foreach (var (propertyName, propertyValues) in statMap) { - var result = CountLogAggregator.GetStatistics(propertyValues); + var result = StatisticResult.FromList(propertyValues); m[CreateProperty(propertyName, Max)] = result.Maximum; m[CreateProperty(propertyName, Min)] = result.Minimum; diff --git a/src/Workspaces/Core/Portable/Log/StatisticResult.cs b/src/Workspaces/Core/Portable/Log/StatisticResult.cs new file mode 100644 index 0000000000000..0c69d2bb708f9 --- /dev/null +++ b/src/Workspaces/Core/Portable/Log/StatisticResult.cs @@ -0,0 +1,90 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#nullable disable + +using System.Collections.Generic; +using System.Linq; +using Roslyn.Utilities; + +namespace Microsoft.CodeAnalysis.Internal.Log +{ + internal struct StatisticResult + { + public static StatisticResult FromList(List values) + { + if (values.Count == 0) + { + return default; + } + + var max = int.MinValue; + var min = int.MaxValue; + + var total = 0; + for (var i = 0; i < values.Count; i++) + { + var current = values[i]; + max = max < current ? current : max; + min = min > current ? current : min; + + total += current; + } + + var mean = total / values.Count; + var median = values[values.Count / 2]; + + var range = max - min; + var mode = values.GroupBy(i => i).OrderByDescending(g => g.Count()).FirstOrDefault().Key; + + return new StatisticResult(max, min, median, mean, range, mode, values.Count); + } + + /// + /// maximum value + /// + public readonly int Maximum; + + /// + /// minimum value + /// + public readonly int Minimum; + + /// + /// middle value of the total data set + /// + public readonly int? Median; + + /// + /// average value of the total data set + /// + public readonly int Mean; + + /// + /// most frequent value in the total data set + /// + public readonly int? Mode; + + /// + /// difference between max and min value + /// + public readonly int Range; + + /// + /// number of data points in the total data set + /// + public readonly int Count; + + public StatisticResult(int max, int min, int? median, int mean, int range, int? mode, int count) + { + this.Maximum = max; + this.Minimum = min; + this.Median = median; + this.Mean = mean; + this.Range = range; + this.Mode = mode; + this.Count = count; + } + } +} diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs index c0898de5e24bf..0d4173983a3e6 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Log/AbstractLogAggregator.cs @@ -29,35 +29,6 @@ protected AbstractLogAggregator() protected abstract TValue CreateCounter(); - public static StatisticResult GetStatistics(List values) - { - if (values.Count == 0) - { - return default; - } - - var max = int.MinValue; - var min = int.MaxValue; - - var total = 0; - for (var i = 0; i < values.Count; i++) - { - var current = values[i]; - max = max < current ? current : max; - min = min > current ? current : min; - - total += current; - } - - var mean = total / values.Count; - var median = values[values.Count / 2]; - - var range = max - min; - var mode = values.GroupBy(i => i).OrderByDescending(g => g.Count()).FirstOrDefault().Key; - - return new StatisticResult(max, min, median, mean, range, mode, values.Count); - } - public bool IsEmpty => _map.IsEmpty; public IEnumerator> GetEnumerator() @@ -80,53 +51,4 @@ protected bool TryGetCounter(TKey key, out TValue counter) return false; } } - - internal struct StatisticResult - { - /// - /// maximum value - /// - public readonly int Maximum; - - /// - /// minimum value - /// - public readonly int Minimum; - - /// - /// middle value of the total data set - /// - public readonly int? Median; - - /// - /// average value of the total data set - /// - public readonly int Mean; - - /// - /// most frequent value in the total data set - /// - public readonly int? Mode; - - /// - /// difference between max and min value - /// - public readonly int Range; - - /// - /// number of data points in the total data set - /// - public readonly int Count; - - public StatisticResult(int max, int min, int? median, int mean, int range, int? mode, int count) - { - this.Maximum = max; - this.Minimum = min; - this.Median = median; - this.Mean = mean; - this.Range = range; - this.Mode = mode; - this.Count = count; - } - } } From 42c5e0ae6d8f2776a548e4eb19fdfaf69eacd123 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Mon, 13 Jun 2022 17:54:58 -0700 Subject: [PATCH 6/6] Rename the common IncreaseCount method to something more sensible --- .../AsyncCompletion/AsyncCompletionLogger.cs | 10 +++++----- .../ChangeSignature/ChangeSignatureTelemetryLogger.cs | 2 +- .../Completion/Log/CompletionProvidersLogger.cs | 4 ++-- .../Protocol/Handler/RequestTelemetryLogger.cs | 2 +- .../Def/InheritanceMargin/InheritanceMarginLogger.cs | 2 +- .../Core/Portable/Log/HistogramLogAggregator.cs | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs index 003f96f6d042e..8bc051446a7d6 100644 --- a/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs +++ b/src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs @@ -58,7 +58,7 @@ internal static void LogSessionWithDelayedImportCompletionIncludedInUpdate() => s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate); internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(TimeSpan timeSpan) => - s_histogramLogAggregator.IncreaseCount(ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan); + s_histogramLogAggregator.LogTime(ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan); internal static void LogDelayedImportCompletionIncluded() => s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled); @@ -72,7 +72,7 @@ internal static void LogGetDefaultsMatchTicksDataPoint(int count) => internal static void LogSourceInitializationTicksDataPoint(TimeSpan elapsed) { s_statisticLogAggregator.AddDataPoint(ActionInfo.SourceInitializationTicks, elapsed); - s_histogramLogAggregator.IncreaseCount(ActionInfo.SourceInitializationTicks, elapsed); + s_histogramLogAggregator.LogTime(ActionInfo.SourceInitializationTicks, elapsed); } internal static void LogSourceGetContextTicksDataPoint(TimeSpan elapsed, bool isCanceled) @@ -82,13 +82,13 @@ internal static void LogSourceGetContextTicksDataPoint(TimeSpan elapsed, bool is : ActionInfo.SourceGetContextCompletedTicks; s_statisticLogAggregator.AddDataPoint(key, elapsed); - s_histogramLogAggregator.IncreaseCount(key, elapsed); + s_histogramLogAggregator.LogTime(key, elapsed); } internal static void LogItemManagerSortTicksDataPoint(TimeSpan elapsed) { s_statisticLogAggregator.AddDataPoint(ActionInfo.ItemManagerSortTicks, elapsed); - s_histogramLogAggregator.IncreaseCount(ActionInfo.ItemManagerSortTicks, elapsed); + s_histogramLogAggregator.LogTime(ActionInfo.ItemManagerSortTicks, elapsed); } internal static void LogItemManagerUpdateDataPoint(TimeSpan elapsed, bool isCanceled) @@ -98,7 +98,7 @@ internal static void LogItemManagerUpdateDataPoint(TimeSpan elapsed, bool isCanc : ActionInfo.ItemManagerUpdateCompletedTicks; s_statisticLogAggregator.AddDataPoint(key, elapsed); - s_histogramLogAggregator.IncreaseCount(key, elapsed); + s_histogramLogAggregator.LogTime(key, elapsed); } internal static void ReportTelemetry() diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs index c03fe028988dc..634980d055b5b 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureTelemetryLogger.cs @@ -147,7 +147,7 @@ internal static void LogCommitInformation(int numDeclarationsUpdated, int numCal s_countLogAggregator.IncreaseCountBy(ActionInfo.CommittedSessionNumberOfCallSitesUpdated, numCallSitesUpdated); s_statisticLogAggregator.AddDataPoint(ActionInfo.CommittedSessionCommitElapsedMS, (int)elapsedTime.TotalMilliseconds); - s_histogramLogAggregator.IncreaseCount(ActionInfo.CommittedSessionCommitElapsedMS, elapsedTime); + s_histogramLogAggregator.LogTime(ActionInfo.CommittedSessionCommitElapsedMS, elapsedTime); } internal static void LogAddedParameterTypeBinds() diff --git a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs index 2bdf26380135a..eab198df2b957 100644 --- a/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs +++ b/src/Features/Core/Portable/Completion/Log/CompletionProvidersLogger.cs @@ -36,7 +36,7 @@ internal enum ActionInfo internal static void LogTypeImportCompletionTicksDataPoint(TimeSpan elapsed) { - s_histogramLogAggregator.IncreaseCount(ActionInfo.TypeImportCompletionTicks, elapsed); + s_histogramLogAggregator.LogTime(ActionInfo.TypeImportCompletionTicks, elapsed); s_statisticLogAggregator.AddDataPoint(ActionInfo.TypeImportCompletionTicks, elapsed); } @@ -54,7 +54,7 @@ internal static void LogCommitOfTypeImportCompletionItem() => internal static void LogExtensionMethodCompletionTicksDataPoint(TimeSpan total, TimeSpan getSymbols, TimeSpan createItems, bool isRemote) { - s_histogramLogAggregator.IncreaseCount(ActionInfo.ExtensionMethodCompletionTicks, total); + s_histogramLogAggregator.LogTime(ActionInfo.ExtensionMethodCompletionTicks, total); s_statisticLogAggregator.AddDataPoint(ActionInfo.ExtensionMethodCompletionTicks, total); if (isRemote) diff --git a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs index 8a74043c4b9c7..1f6cd5520feb6 100644 --- a/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs +++ b/src/Features/LanguageServer/Protocol/Handler/RequestTelemetryLogger.cs @@ -87,7 +87,7 @@ public void UpdateTelemetryData( { // Find the bucket corresponding to the queued duration and update the count of durations in that bucket. // This is not broken down per method as time in queue is not specific to an LSP method. - _queuedDurationLogAggregator.IncreaseCount(QueuedDurationKey, queuedDuration); + _queuedDurationLogAggregator.LogTime(QueuedDurationKey, queuedDuration); // Store the request time metrics per LSP method. _requestDurationLogAggregator.IncreaseCount(methodName, (int)ComputeLogValue(requestDuration.TotalMilliseconds)); diff --git a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs index 9d192e939f2fe..0b38743b65005 100644 --- a/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs +++ b/src/VisualStudio/Core/Def/InheritanceMargin/InheritanceMarginLogger.cs @@ -18,7 +18,7 @@ private enum ActionInfo } public static void LogGenerateBackgroundInheritanceInfo(TimeSpan elapsedTime) - => s_histogramLogAggregator.IncreaseCount( + => s_histogramLogAggregator.LogTime( ActionInfo.GetInheritanceMarginMembers, elapsedTime); public static void LogInheritanceTargetsMenuOpen() diff --git a/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs b/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs index 670fa554761c0..9f04d3098f021 100644 --- a/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs +++ b/src/Workspaces/Core/Portable/Log/HistogramLogAggregator.cs @@ -38,7 +38,7 @@ public void IncreaseCount(TKey key, int value) counter.IncreaseCount(value); } - public void IncreaseCount(TKey key, TimeSpan timeSpan) + public void LogTime(TKey key, TimeSpan timeSpan) { var counter = GetCounter(key); counter.IncreaseCount((int)timeSpan.TotalMilliseconds);