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 ;
56using Microsoft . CodeAnalysis . Internal . Log ;
67
78namespace 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 ( ) ;
0 commit comments