Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 Microsoft.CodeAnalysis.Internal.Log;

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static readonly HistogramLogAggregator s_histogramLogAggregator = new(1000, 60000);
private static readonly HistogramLogAggregator s_histogramLogAggregator = new(TimeSpan.FromSecons(1), TimeSpan.FromMinutes(1));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


private enum ActionInfo
{
GetInheritanceMarginMembers,
}

public static void LogGenerateBackgroundInheritanceInfo(TimeSpan elapsedTime)
=> s_histogramLogAggregator.IncreaseCount(
ActionInfo.GetInheritanceMarginMembers, Convert.ToDecimal(elapsedTime.TotalMilliseconds));

public static void LogInheritanceTargetsMenuOpen()
=> Logger.Log(FunctionId.InheritanceMargin_TargetsMenuOpen, KeyValueLogMessage.Create(LogType.UserAction));

public static void LogNavigateToTarget()
=> Logger.Log(FunctionId.InheritanceMargin_NavigateToTarget, KeyValueLogMessage.Create(LogType.UserAction));

public static void ReportTelemetry()
{
Logger.Log(FunctionId.InheritanceMargin_GetInheritanceMemberItems,
KeyValueLogMessage.Create(
m =>
{
var histogramLogAggragator = s_histogramLogAggregator.GetValue(ActionInfo.GetInheritanceMarginMembers);
if (histogramLogAggragator != null)
{
m[$"{ActionInfo.GetInheritanceMarginMembers}.BucketSize"] = histogramLogAggragator.BucketSize;
m[$"{ActionInfo.GetInheritanceMarginMembers}.BucketCount"] = histogramLogAggragator.BucketCount;
m[$"{ActionInfo.GetInheritanceMarginMembers}.Bucket"] = histogramLogAggragator.GetBucketsAsString();
}
}));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Implementation.Classification;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Tagging;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.InheritanceMargin;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.LanguageServices.InheritanceMargin;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
Expand Down Expand Up @@ -105,20 +104,21 @@ protected override async Task ProduceTagsAsync(
return;
}

var inheritanceMemberItems = ImmutableArray<InheritanceMarginItem>.Empty;
using (Logger.LogBlock(FunctionId.InheritanceMargin_GetInheritanceMemberItems, cancellationToken, LogLevel.Information))
{
inheritanceMemberItems = await inheritanceMarginInfoService.GetInheritanceMemberItemsAsync(
document,
spanToTag.SnapshotSpan.Span.ToTextSpan(),
cancellationToken).ConfigureAwait(false);
}
var spanToSearch = spanToTag.SnapshotSpan.Span.ToTextSpan();
var stopwatch = SharedStopwatch.StartNew();
var inheritanceMemberItems = await inheritanceMarginInfoService.GetInheritanceMemberItemsAsync(
document,
spanToSearch,
cancellationToken).ConfigureAwait(false);
var elapsed = stopwatch.Elapsed;

if (inheritanceMemberItems.IsEmpty)
{
return;
}

InheritanceMarginLogger.LogGenerateBackgroundInheritanceInfo(elapsed);

// One line might have multiple members to show, so group them.
// For example:
// interface IBar { void Foo1(); void Foo2(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
using System.Windows;
using System.Windows.Controls;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.LanguageServices.InheritanceMargin;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.InheritanceMargin.MarginGlyph
Expand Down Expand Up @@ -49,7 +47,7 @@ private void TargetMenuItem_OnClick(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is MenuItem { DataContext: TargetMenuItemViewModel viewModel })
{
Logger.Log(FunctionId.InheritanceMargin_NavigateToTarget, KeyValueLogMessage.Create(LogType.UserAction));
InheritanceMarginLogger.LogNavigateToTarget();

var token = _listener.BeginAsyncOperation(nameof(TargetMenuItem_OnClick));
TargetMenuItem_OnClickAsync(viewModel).CompletesAsyncOperation(token);
Expand Down Expand Up @@ -79,7 +77,7 @@ private async Task TargetMenuItem_OnClickAsync(TargetMenuItemViewModel viewModel

private void TargetsSubmenu_OnOpen(object sender, RoutedEventArgs e)
{
Logger.Log(FunctionId.InheritanceMargin_TargetsMenuOpen, KeyValueLogMessage.Create(LogType.UserAction));
InheritanceMarginLogger.LogInheritanceTargetsMenuOpen();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.Imaging;
using Microsoft.VisualStudio.LanguageServices.InheritanceMargin;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Classification;
Expand Down Expand Up @@ -179,7 +179,7 @@ private void ContextMenu_OnOpen(object sender, RoutedEventArgs e)
// -> Target4
// If the first level of the context menu contains a TargetMenuItemViewModel, it means here it is case 1,
// user is viewing the targets menu.
Logger.Log(FunctionId.InheritanceMargin_TargetsMenuOpen, KeyValueLogMessage.Create(LogType.UserAction));
InheritanceMarginLogger.LogInheritanceTargetsMenuOpen();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/VisualStudio/Core/Def/RoslynPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using Microsoft.VisualStudio.LanguageServices.Implementation.SyncNamespaces;
using Microsoft.VisualStudio.LanguageServices.Implementation.TableDataSource;
using Microsoft.VisualStudio.LanguageServices.Implementation.UnusedReferences;
using Microsoft.VisualStudio.LanguageServices.InheritanceMargin;
using Microsoft.VisualStudio.LanguageServices.StackTraceExplorer;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand Down Expand Up @@ -316,6 +317,7 @@ private static void ReportSessionWideTelemetry()
AsyncCompletionLogger.ReportTelemetry();
CompletionProvidersLogger.ReportTelemetry();
ChangeSignatureLogger.ReportTelemetry();
InheritanceMarginLogger.ReportTelemetry();
}

private void DisposeVisualStudioServices()
Expand Down