From 0a2b96672846deeadffa1456bb5b49aac8eb93c0 Mon Sep 17 00:00:00 2001 From: Amadeusz Wieczorek Date: Thu, 21 Nov 2024 15:57:03 -0800 Subject: [PATCH 1/2] access the ISmartRenameSession.CorrelationId --- .../UI/SmartRename/SmartRenameViewModel_Telemetry.cs | 2 ++ .../Core.Wpf/Lightup/ISmartRenameSessionWrapper.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs index 572060b76a5e0..cf4bd68f16641 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs @@ -52,6 +52,7 @@ private void PostTelemetry(bool isCommit) m[nameof(SuggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts)] = _suggestionsPanelTelemetry.CollapseSuggestionsPanelWhenRenameStarts; m["CollapseSuggestionsPanelWhenRenameEnds"] = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel); m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress; + m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId; })); } else @@ -63,6 +64,7 @@ private void PostTelemetry(bool isCommit) m["UseDropDown"] = true; m[nameof(SuggestionsDropdownTelemetry.DropdownButtonClickTimes)] = _suggestionsDropdownTelemetry.DropdownButtonClickTimes; m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress; + m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId; })); } } diff --git a/src/EditorFeatures/Core.Wpf/Lightup/ISmartRenameSessionWrapper.cs b/src/EditorFeatures/Core.Wpf/Lightup/ISmartRenameSessionWrapper.cs index 9ee6e53ca2168..45efb9baff566 100644 --- a/src/EditorFeatures/Core.Wpf/Lightup/ISmartRenameSessionWrapper.cs +++ b/src/EditorFeatures/Core.Wpf/Lightup/ISmartRenameSessionWrapper.cs @@ -29,6 +29,7 @@ namespace Microsoft.CodeAnalysis.EditorFeatures.Lightup; private static readonly Func s_statusMessageAccessor; private static readonly Func s_statusMessageVisibilityAccessor; private static readonly Func> s_suggestedNamesAccessor; + private static readonly Func s_correlationIdAccessor; private static readonly Func? s_renameContextImmutableListCreateBuilderAccessor; private static readonly Action? s_renameContextImmutableListBuilderAddAccessor; private static readonly Func? s_renameContextImmutableListBuilderToArrayAccessor; @@ -52,6 +53,7 @@ static ISmartRenameSessionWrapper() s_statusMessageAccessor = LightupHelpers.CreatePropertyAccessor(s_wrappedType, nameof(StatusMessage), ""); s_statusMessageVisibilityAccessor = LightupHelpers.CreatePropertyAccessor(s_wrappedType, nameof(StatusMessageVisibility), false); s_suggestedNamesAccessor = LightupHelpers.CreatePropertyAccessor>(s_wrappedType, nameof(SuggestedNames), []); + s_correlationIdAccessor = LightupHelpers.CreatePropertyAccessor(s_wrappedType, nameof(CorrelationId), Guid.Empty); if (s_wrappedRenameContextType is not null) { @@ -93,6 +95,7 @@ private ISmartRenameSessionWrapper(object instance) public string StatusMessage => s_statusMessageAccessor(_instance); public bool StatusMessageVisibility => s_statusMessageVisibilityAccessor(_instance); public IReadOnlyList SuggestedNames => s_suggestedNamesAccessor(_instance); + public Guid CorrelationId => s_correlationIdAccessor(_instance); public event PropertyChangedEventHandler PropertyChanged { From 968444614cb19f81eab77784becf072ba0b745f5 Mon Sep 17 00:00:00 2001 From: Amadeusz Wieczorek Date: Thu, 21 Nov 2024 16:02:52 -0800 Subject: [PATCH 2/2] add telemetry for semantic context --- .../InlineRename/UI/SmartRename/SmartRenameViewModel.cs | 8 ++++++++ .../UI/SmartRename/SmartRenameViewModel_Telemetry.cs | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs index fbb4afed7d98e..73e39b7eab634 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel.cs @@ -21,6 +21,7 @@ using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.TestHooks; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.InlineRename.UI.SmartRename; @@ -37,6 +38,9 @@ internal sealed partial class SmartRenameViewModel : INotifyPropertyChanged, IDi private bool _isDisposed; private TimeSpan AutomaticFetchDelay => _smartRenameSession.AutomaticFetchDelay; private Task _getSuggestionsTask = Task.CompletedTask; + private TimeSpan _semanticContextDelay; + private bool _semanticContextError; + private bool _semanticContextUsed; public event PropertyChangedEventHandler? PropertyChanged; @@ -176,6 +180,8 @@ await Task.Delay(_smartRenameSession.AutomaticFetchDelay, cancellationToken) if (IsUsingSemanticContext) { + var stopwatch = SharedStopwatch.StartNew(); + _semanticContextUsed = true; var document = this.BaseViewModel.Session.TriggerDocument; var smartRenameContext = ImmutableDictionary>.Empty; try @@ -188,9 +194,11 @@ await Task.Delay(_smartRenameSession.AutomaticFetchDelay, cancellationToken) smartRenameContext = ImmutableDictionary.CreateRange>( context .Select(n => new KeyValuePair>(n.Key, n.Value))); + _semanticContextDelay = stopwatch.Elapsed; } catch (Exception e) when (FatalError.ReportAndCatch(e, ErrorSeverity.Diagnostic)) { + _semanticContextError = true; // use empty smartRenameContext } _ = await _smartRenameSession.GetSuggestionsAsync(smartRenameContext, cancellationToken) diff --git a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs index cf4bd68f16641..c023e6c1e1083 100644 --- a/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs +++ b/src/EditorFeatures/Core.Wpf/InlineRename/UI/SmartRename/SmartRenameViewModel_Telemetry.cs @@ -53,6 +53,9 @@ private void PostTelemetry(bool isCommit) m["CollapseSuggestionsPanelWhenRenameEnds"] = _globalOptionService.GetOption(InlineRenameUIOptionsStorage.CollapseSuggestionsPanel); m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress; m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId; + m["smartRenameSemanticContextUsed"] = _semanticContextUsed; + m["smartRenameSemanticContextDelay"] = _semanticContextDelay; + m["smartRenameSemanticContextError"] = _semanticContextError; })); } else @@ -65,6 +68,9 @@ private void PostTelemetry(bool isCommit) m[nameof(SuggestionsDropdownTelemetry.DropdownButtonClickTimes)] = _suggestionsDropdownTelemetry.DropdownButtonClickTimes; m["smartRenameSessionInProgress"] = _smartRenameSession.IsInProgress; m["smartRenameCorrelationId"] = _smartRenameSession.CorrelationId; + m["smartRenameSemanticContextUsed"] = _semanticContextUsed; + m["smartRenameSemanticContextDelay"] = _semanticContextDelay; + m["smartRenameSemanticContextError"] = _semanticContextError; })); } }