Skip to content

Commit 1c13b39

Browse files
Merge pull request #61669 from jasonmalinowski/log-aggregator-cleanups
Cleanups for our logging helpers
2 parents ff8175f + 42c5e0a commit 1c13b39

27 files changed

+302
-256
lines changed

src/EditorFeatures/Core/IntelliSense/AsyncCompletion/AsyncCompletionLogger.cs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
56
using Microsoft.CodeAnalysis.Internal.Log;
67

78
namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion
89
{
910
internal static class AsyncCompletionLogger
1011
{
11-
private static readonly LogAggregator s_logAggregator = new();
12-
private static readonly StatisticLogAggregator s_statisticLogAggregator = new();
13-
private static readonly HistogramLogAggregator s_histogramLogAggregator = new(25, 500);
12+
private static readonly CountLogAggregator<ActionInfo> s_countLogAggregator = new();
13+
private static readonly StatisticLogAggregator<ActionInfo> s_statisticLogAggregator = new();
14+
private static readonly HistogramLogAggregator<ActionInfo> s_histogramLogAggregator = new(25, 500);
1415

1516
private enum ActionInfo
1617
{
@@ -44,60 +45,60 @@ private enum ActionInfo
4445

4546
internal static void LogImportCompletionGetContext(bool isBlocking, bool delayed)
4647
{
47-
s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithTypeImportCompletionEnabled);
48+
s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled);
4849

4950
if (isBlocking)
50-
s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithImportCompletionBlocking);
51+
s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionBlocking);
5152

5253
if (delayed)
53-
s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithImportCompletionDelayed);
54+
s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithImportCompletionDelayed);
5455
}
5556

5657
internal static void LogSessionWithDelayedImportCompletionIncludedInUpdate() =>
57-
s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate);
58+
s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithDelayedImportCompletionIncludedInUpdate);
5859

59-
internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(int count) =>
60-
s_histogramLogAggregator.IncreaseCount((int)ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, count);
60+
internal static void LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(TimeSpan timeSpan) =>
61+
s_histogramLogAggregator.LogTime(ActionInfo.AdditionalTicksToCompleteDelayedImportCompletion, timeSpan);
6162

6263
internal static void LogDelayedImportCompletionIncluded() =>
63-
s_logAggregator.IncreaseCount((int)ActionInfo.SessionWithTypeImportCompletionEnabled);
64+
s_countLogAggregator.IncreaseCount(ActionInfo.SessionWithTypeImportCompletionEnabled);
6465

6566
internal static void LogExpanderUsage() =>
66-
s_logAggregator.IncreaseCount((int)ActionInfo.ExpanderUsageCount);
67+
s_countLogAggregator.IncreaseCount(ActionInfo.ExpanderUsageCount);
6768

6869
internal static void LogGetDefaultsMatchTicksDataPoint(int count) =>
69-
s_statisticLogAggregator.AddDataPoint((int)ActionInfo.GetDefaultsMatchTicks, count);
70+
s_statisticLogAggregator.AddDataPoint(ActionInfo.GetDefaultsMatchTicks, count);
7071

71-
internal static void LogSourceInitializationTicksDataPoint(int count)
72+
internal static void LogSourceInitializationTicksDataPoint(TimeSpan elapsed)
7273
{
73-
s_statisticLogAggregator.AddDataPoint((int)ActionInfo.SourceInitializationTicks, count);
74-
s_histogramLogAggregator.IncreaseCount((int)ActionInfo.SourceInitializationTicks, count);
74+
s_statisticLogAggregator.AddDataPoint(ActionInfo.SourceInitializationTicks, elapsed);
75+
s_histogramLogAggregator.LogTime(ActionInfo.SourceInitializationTicks, elapsed);
7576
}
7677

77-
internal static void LogSourceGetContextTicksDataPoint(int count, bool isCanceled)
78+
internal static void LogSourceGetContextTicksDataPoint(TimeSpan elapsed, bool isCanceled)
7879
{
7980
var key = isCanceled
8081
? ActionInfo.SourceGetContextCanceledTicks
8182
: ActionInfo.SourceGetContextCompletedTicks;
8283

83-
s_statisticLogAggregator.AddDataPoint((int)key, count);
84-
s_histogramLogAggregator.IncreaseCount((int)key, count);
84+
s_statisticLogAggregator.AddDataPoint(key, elapsed);
85+
s_histogramLogAggregator.LogTime(key, elapsed);
8586
}
8687

87-
internal static void LogItemManagerSortTicksDataPoint(int count)
88+
internal static void LogItemManagerSortTicksDataPoint(TimeSpan elapsed)
8889
{
89-
s_statisticLogAggregator.AddDataPoint((int)ActionInfo.ItemManagerSortTicks, count);
90-
s_histogramLogAggregator.IncreaseCount((int)ActionInfo.ItemManagerSortTicks, count);
90+
s_statisticLogAggregator.AddDataPoint(ActionInfo.ItemManagerSortTicks, elapsed);
91+
s_histogramLogAggregator.LogTime(ActionInfo.ItemManagerSortTicks, elapsed);
9192
}
9293

93-
internal static void LogItemManagerUpdateDataPoint(int count, bool isCanceled)
94+
internal static void LogItemManagerUpdateDataPoint(TimeSpan elapsed, bool isCanceled)
9495
{
9596
var key = isCanceled
9697
? ActionInfo.ItemManagerUpdateCanceledTicks
9798
: ActionInfo.ItemManagerUpdateCompletedTicks;
9899

99-
s_statisticLogAggregator.AddDataPoint((int)key, count);
100-
s_histogramLogAggregator.IncreaseCount((int)key, count);
100+
s_statisticLogAggregator.AddDataPoint(key, elapsed);
101+
s_histogramLogAggregator.LogTime(key, elapsed);
101102
}
102103

103104
internal static void ReportTelemetry()
@@ -106,7 +107,7 @@ internal static void ReportTelemetry()
106107
{
107108
foreach (var kv in s_statisticLogAggregator)
108109
{
109-
var info = ((ActionInfo)kv.Key).ToString("f");
110+
var info = kv.Key.ToString("f");
110111
var statistics = kv.Value.GetStatisticResult();
111112

112113
m[CreateProperty(info, nameof(StatisticResult.Maximum))] = statistics.Maximum;
@@ -116,15 +117,15 @@ internal static void ReportTelemetry()
116117
m[CreateProperty(info, nameof(StatisticResult.Count))] = statistics.Count;
117118
}
118119

119-
foreach (var kv in s_logAggregator)
120+
foreach (var kv in s_countLogAggregator)
120121
{
121-
var mergeInfo = ((ActionInfo)kv.Key).ToString("f");
122+
var mergeInfo = kv.Key.ToString("f");
122123
m[mergeInfo] = kv.Value.GetCount();
123124
}
124125

125126
foreach (var kv in s_histogramLogAggregator)
126127
{
127-
var info = ((ActionInfo)kv.Key).ToString("f");
128+
var info = kv.Key.ToString("f");
128129
m[$"{info}.BucketSize"] = kv.Value.BucketSize;
129130
m[$"{info}.MaxBucketValue"] = kv.Value.MaxBucketValue;
130131
m[$"{info}.Buckets"] = kv.Value.GetBucketsAsString();

src/EditorFeatures/Core/IntelliSense/AsyncCompletion/CompletionSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public AsyncCompletionData.CompletionStartData InitializeCompletion(
143143
}
144144
finally
145145
{
146-
AsyncCompletionLogger.LogSourceInitializationTicksDataPoint((int)stopwatch.Elapsed.TotalMilliseconds);
146+
AsyncCompletionLogger.LogSourceInitializationTicksDataPoint(stopwatch.Elapsed);
147147
}
148148
}
149149

@@ -311,7 +311,7 @@ public async Task<VSCompletionContext> GetCompletionContextAsync(
311311
// There could be a race around the usage of this stopwatch, I ignored it since we just need a rough idea:
312312
// we always log the time even if the stopwatch's not started regardless of whether expand items are included intially
313313
// (that number can be obtained via another property.)
314-
AsyncCompletionLogger.LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint((int)stopwatch.ElapsedMilliseconds);
314+
AsyncCompletionLogger.LogAdditionalTicksToCompleteDelayedImportCompletionDataPoint(stopwatch.Elapsed);
315315

316316
return result;
317317
}, cancellationToken);
@@ -346,7 +346,7 @@ public async Task<VSCompletionContext> GetCompletionContextAsync(
346346
}
347347
finally
348348
{
349-
AsyncCompletionLogger.LogSourceGetContextTicksDataPoint((int)totalStopWatch.Elapsed.TotalMilliseconds, isCanceled: cancellationToken.IsCancellationRequested);
349+
AsyncCompletionLogger.LogSourceGetContextTicksDataPoint(totalStopWatch.Elapsed, isCanceled: cancellationToken.IsCancellationRequested);
350350
}
351351

352352
static VSCompletionContext CombineCompletionContext(VSCompletionContext context1, VSCompletionContext context2)

src/EditorFeatures/Core/IntelliSense/AsyncCompletion/ItemManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Task<ImmutableArray<VSCompletionItem>> SortCompletionListAsync(
3636

3737
// Sort by default comparer of Roslyn CompletionItem
3838
var sortedItems = data.InitialList.OrderBy(CompletionItemData.GetOrAddDummyRoslynItem).ToImmutableArray();
39-
AsyncCompletionLogger.LogItemManagerSortTicksDataPoint((int)stopwatch.Elapsed.TotalMilliseconds);
39+
AsyncCompletionLogger.LogItemManagerSortTicksDataPoint(stopwatch.Elapsed);
4040
return Task.FromResult(sortedItems);
4141
}
4242

@@ -101,7 +101,7 @@ public Task<ImmutableArray<VSCompletionItem>> SortCompletionListAsync(
101101
}
102102
finally
103103
{
104-
AsyncCompletionLogger.LogItemManagerUpdateDataPoint((int)stopwatch.Elapsed.TotalMilliseconds, isCanceled: cancellationToken.IsCancellationRequested);
104+
AsyncCompletionLogger.LogItemManagerUpdateDataPoint(stopwatch.Elapsed, isCanceled: cancellationToken.IsCancellationRequested);
105105
}
106106
}
107107
}

src/Features/Core/Portable/ChangeSignature/AbstractChangeSignatureService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ private static async Task<ImmutableArray<ReferencedSymbol>> FindChangeSignatureR
427427
}
428428

429429
telemetryTimer.Stop();
430-
ChangeSignatureLogger.LogCommitInformation(telemetryNumberOfDeclarationsToUpdate, telemetryNumberOfReferencesToUpdate, (int)telemetryTimer.ElapsedMilliseconds);
430+
ChangeSignatureLogger.LogCommitInformation(telemetryNumberOfDeclarationsToUpdate, telemetryNumberOfReferencesToUpdate, telemetryTimer.Elapsed);
431431

432432
return (currentSolution, confirmationMessage);
433433
}

0 commit comments

Comments
 (0)