未验证 提交 44938774 编写于 作者: H Heejae Chang 提交者: GitHub

add more telemetry to track feature performances (#32550)

上级 882f646d
......@@ -9,7 +9,7 @@
using Microsoft.CodeAnalysis.Editor.FindUsages;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
......@@ -79,9 +79,11 @@ public bool ExecuteCommand(GoToImplementationCommandArgs args, CommandExecutionC
// We have all the cheap stuff, so let's do expensive stuff now
string messageToShow = null;
var userCancellationToken = context.OperationContext.UserCancellationToken;
using (context.OperationContext.AddScope(allowCancellation: true, EditorFeaturesResources.Locating_implementations))
using (Logger.LogBlock(FunctionId.CommandHandler_GoToImplementation, KeyValueLogMessage.Create(LogType.UserAction), userCancellationToken))
{
var userCancellationToken = context.OperationContext.UserCancellationToken;
StreamingGoToImplementation(
document, caretPosition,
streamingService, streamingPresenter,
......
......@@ -348,7 +348,6 @@ private bool IsAnyTypeKind(GraphNode node, params TypeKind[] typeKinds)
public T GetExtension<T>(GraphObject graphObject, T previous) where T : class
{
if (graphObject is GraphNode graphNode)
{
// If this is not a Roslyn node, bail out.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.GraphModel;
using Microsoft.VisualStudio.GraphModel.Schemas;
using Microsoft.VisualStudio.Progression;
using Roslyn.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Progression
{
......@@ -21,24 +14,27 @@ internal sealed class ImplementedByGraphQuery : IGraphQuery
{
public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken)
{
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var node in context.InputNodes)
using (Logger.LogBlock(FunctionId.GraphQuery_ImplementedBy, KeyValueLogMessage.Create(LogType.UserAction), cancellationToken))
{
var symbol = graphBuilder.GetSymbol(node);
if (symbol is INamedTypeSymbol || symbol is IMethodSymbol || symbol is IPropertySymbol || symbol is IEventSymbol)
{
var implementations = await SymbolFinder.FindImplementationsAsync(symbol, solution, cancellationToken: cancellationToken).ConfigureAwait(false);
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var implementation in implementations)
foreach (var node in context.InputNodes)
{
var symbol = graphBuilder.GetSymbol(node);
if (symbol is INamedTypeSymbol || symbol is IMethodSymbol || symbol is IPropertySymbol || symbol is IEventSymbol)
{
var symbolNode = await graphBuilder.AddNodeForSymbolAsync(implementation, relatedNode: node).ConfigureAwait(false);
graphBuilder.AddLink(symbolNode, CodeLinkCategories.Implements, node);
var implementations = await SymbolFinder.FindImplementationsAsync(symbol, solution, cancellationToken: cancellationToken).ConfigureAwait(false);
foreach (var implementation in implementations)
{
var symbolNode = await graphBuilder.AddNodeForSymbolAsync(implementation, relatedNode: node).ConfigureAwait(false);
graphBuilder.AddLink(symbolNode, CodeLinkCategories.Implements, node);
}
}
}
}
return graphBuilder;
return graphBuilder;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.GraphModel;
using Microsoft.VisualStudio.GraphModel.Schemas;
using Microsoft.VisualStudio.Progression;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Progression
{
......@@ -19,25 +15,28 @@ internal sealed class ImplementsGraphQuery : IGraphQuery
{
public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken)
{
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var node in context.InputNodes)
using (Logger.LogBlock(FunctionId.GraphQuery_Implements, KeyValueLogMessage.Create(LogType.UserAction), cancellationToken))
{
var symbol = graphBuilder.GetSymbol(node);
if (symbol is INamedTypeSymbol namedType)
{
var implementedSymbols = namedType.AllInterfaces;
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
await AddImplementedSymbolsAsync(graphBuilder, node, implementedSymbols).ConfigureAwait(false);
}
else if (symbol is IMethodSymbol || symbol is IPropertySymbol || symbol is IEventSymbol)
foreach (var node in context.InputNodes)
{
var implements = await SymbolFinder.FindImplementedInterfaceMembersAsync(symbol, solution, cancellationToken: cancellationToken).ConfigureAwait(false);
await AddImplementedSymbolsAsync(graphBuilder, node, implements).ConfigureAwait(false);
var symbol = graphBuilder.GetSymbol(node);
if (symbol is INamedTypeSymbol namedType)
{
var implementedSymbols = namedType.AllInterfaces;
await AddImplementedSymbolsAsync(graphBuilder, node, implementedSymbols).ConfigureAwait(false);
}
else if (symbol is IMethodSymbol || symbol is IPropertySymbol || symbol is IEventSymbol)
{
var implements = await SymbolFinder.FindImplementedInterfaceMembersAsync(symbol, solution, cancellationToken: cancellationToken).ConfigureAwait(false);
await AddImplementedSymbolsAsync(graphBuilder, node, implements).ConfigureAwait(false);
}
}
}
return graphBuilder;
return graphBuilder;
}
}
private static async Task AddImplementedSymbolsAsync(GraphBuilder graphBuilder, GraphNode node, IEnumerable<ISymbol> implementedSymbols)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.GraphModel;
using Microsoft.VisualStudio.GraphModel.CodeSchema;
using Microsoft.VisualStudio.GraphModel.Schemas;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Progression
......@@ -19,24 +15,27 @@ internal sealed class IsCalledByGraphQuery : IGraphQuery
{
public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken)
{
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var node in context.InputNodes)
using (Logger.LogBlock(FunctionId.GraphQuery_IsCalledBy, KeyValueLogMessage.Create(LogType.UserAction), cancellationToken))
{
var symbol = graphBuilder.GetSymbol(node);
if (symbol != null)
{
var callers = await SymbolFinder.FindCallersAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var caller in callers.Where(c => c.IsDirect))
foreach (var node in context.InputNodes)
{
var symbol = graphBuilder.GetSymbol(node);
if (symbol != null)
{
var callerNode = await graphBuilder.AddNodeForSymbolAsync(caller.CallingSymbol, relatedNode: node).ConfigureAwait(false);
graphBuilder.AddLink(callerNode, CodeLinkCategories.Calls, node);
var callers = await SymbolFinder.FindCallersAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
foreach (var caller in callers.Where(c => c.IsDirect))
{
var callerNode = await graphBuilder.AddNodeForSymbolAsync(caller.CallingSymbol, relatedNode: node).ConfigureAwait(false);
graphBuilder.AddLink(callerNode, CodeLinkCategories.Calls, node);
}
}
}
}
return graphBuilder;
return graphBuilder;
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.GraphModel;
using Microsoft.VisualStudio.GraphModel.CodeSchema;
using Microsoft.VisualStudio.GraphModel.Schemas;
......@@ -19,30 +16,33 @@ internal sealed class IsUsedByGraphQuery : IGraphQuery
{
public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken)
{
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var node in context.InputNodes)
using (Logger.LogBlock(FunctionId.GraphQuery_IsUsedBy, KeyValueLogMessage.Create(LogType.UserAction), cancellationToken))
{
var symbol = graphBuilder.GetSymbol(node);
var references = await SymbolFinder.FindReferencesAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var reference in references)
foreach (var node in context.InputNodes)
{
var referencedSymbol = reference.Definition;
var projectId = graphBuilder.GetContextProject(node).Id;
var allLocations = referencedSymbol.Locations.Concat(reference.Locations.Select(r => r.Location))
.Where(l => l != null && l.IsInSource);
var symbol = graphBuilder.GetSymbol(node);
var references = await SymbolFinder.FindReferencesAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
foreach (var location in allLocations)
foreach (var reference in references)
{
var locationNode = GetLocationNode(referencedSymbol, location, context, projectId, cancellationToken);
graphBuilder.AddLink(node, CodeLinkCategories.SourceReferences, locationNode);
var referencedSymbol = reference.Definition;
var projectId = graphBuilder.GetContextProject(node).Id;
var allLocations = referencedSymbol.Locations.Concat(reference.Locations.Select(r => r.Location))
.Where(l => l != null && l.IsInSource);
foreach (var location in allLocations)
{
var locationNode = GetLocationNode(referencedSymbol, location, context, projectId, cancellationToken);
graphBuilder.AddLink(node, CodeLinkCategories.SourceReferences, locationNode);
}
}
}
}
return graphBuilder;
return graphBuilder;
}
}
internal GraphNode GetLocationNode(ISymbol symbol, Location location, IGraphContext context, ProjectId projectId, CancellationToken cancellationToken)
......
......@@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.GraphModel;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.Progression
......@@ -12,23 +13,26 @@ internal sealed class OverridesGraphQuery : IGraphQuery
{
public async Task<GraphBuilder> GetGraphAsync(Solution solution, IGraphContext context, CancellationToken cancellationToken)
{
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var node in context.InputNodes)
using (Logger.LogBlock(FunctionId.GraphQuery_Overrides, KeyValueLogMessage.Create(LogType.UserAction), cancellationToken))
{
var symbol = graphBuilder.GetSymbol(node);
if (symbol is IMethodSymbol || symbol is IPropertySymbol || symbol is IEventSymbol)
var graphBuilder = await GraphBuilder.CreateForInputNodesAsync(solution, context.InputNodes, cancellationToken).ConfigureAwait(false);
foreach (var node in context.InputNodes)
{
var overrides = await SymbolFinder.FindOverridesAsync(symbol, solution, cancellationToken: cancellationToken).ConfigureAwait(false);
foreach (var o in overrides)
var symbol = graphBuilder.GetSymbol(node);
if (symbol is IMethodSymbol || symbol is IPropertySymbol || symbol is IEventSymbol)
{
var symbolNode = await graphBuilder.AddNodeForSymbolAsync(o, relatedNode: node).ConfigureAwait(false);
graphBuilder.AddLink(symbolNode, RoslynGraphCategories.Overrides, node);
var overrides = await SymbolFinder.FindOverridesAsync(symbol, solution, cancellationToken: cancellationToken).ConfigureAwait(false);
foreach (var o in overrides)
{
var symbolNode = await graphBuilder.AddNodeForSymbolAsync(o, relatedNode: node).ConfigureAwait(false);
graphBuilder.AddLink(symbolNode, RoslynGraphCategories.Overrides, node);
}
}
}
}
return graphBuilder;
return graphBuilder;
}
}
}
}
......@@ -445,5 +445,11 @@ internal enum FunctionId
SyntaxTreeIndex_Precalculate_Create,
SymbolTreeInfo_Create,
SymbolTreeInfo_TryLoadOrCreate,
CommandHandler_GoToImplementation,
GraphQuery_ImplementedBy,
GraphQuery_Implements,
GraphQuery_IsCalledBy,
GraphQuery_IsUsedBy,
GraphQuery_Overrides,
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册