Example #1
0
        private async Task <LoopPerformanceInfo> VisitLoopAsync(SyntaxNode loopSyntax, MethodPerformanceInfo methodPerformanceInfo)
        {
            var invocationExpressionSyntaxsInLoop = loopSyntax.DescendantNodes(node => true).OfType <InvocationExpressionSyntax>();
            var loopInvocationsList = new List <MethodPerformanceInfo>();

            foreach (var invocationExpressionSyntax in invocationExpressionSyntaxsInLoop)
            {
                var invokedMethodSymbol = _semanticModel.GetSymbolInfo(invocationExpressionSyntax).Symbol as IMethodSymbol;
                // Only Drawing invocationSymbols that refer to the current assembly. Not drawing Information about other assemblies...
                if (invokedMethodSymbol == null || !Equals(_semanticModel.Compilation.Assembly, invokedMethodSymbol.ContainingAssembly))
                {
                    continue;
                }
                var invocationPerformanceInfo = await _telemetryDataMapper.GetMethodPerformanceInfoAsync(invokedMethodSymbol).ConfigureAwait(false);

                loopInvocationsList.Add(invocationPerformanceInfo);
            }


            var loopPerformanceInfo = new LoopPerformanceInfo(_predictionEngine, methodPerformanceInfo, loopInvocationsList);

            var derivedLoopIterations = TryGetLoopIterationsFromCodeFlow(loopSyntax);

            if (derivedLoopIterations != 0)
            {
                loopPerformanceInfo.PredictedLoopIterations = derivedLoopIterations;
            }

            PerformanceTags.Add(loopSyntax, new LoopPerformanceTag(loopPerformanceInfo));
            return(loopPerformanceInfo);
        }
Example #2
0
        public async Task VisitMethodDeclarationAsync(MethodDeclarationSyntax methodDeclarationSyntax)
        {
            var methodSymbol = _semanticModel.GetDeclaredSymbol(methodDeclarationSyntax);

            if (methodSymbol == null)
            {
                return;
            }

            var methodPerformanceInfo = await _telemetryDataMapper.GetMethodPerformanceInfoAsync(methodSymbol).ConfigureAwait(false);

            if (methodPerformanceInfo == null)
            {
                return;
            }

            // TODO RR: var syntaxReference = methodSymbol.DeclaringSyntaxReferences
            // syntaxReference.GetSyntax(context.CancellationToken);

            // Invocations in Method
            IList <MethodPerformanceInfo> invocationsList = new List <MethodPerformanceInfo>();
            var invocationExpressionSyntaxs = methodDeclarationSyntax.DescendantNodes(node => true).OfType <InvocationExpressionSyntax>();

            foreach (var invocationExpressionSyntax in invocationExpressionSyntaxs)
            {
                var invocationsTuple = await VisitInvocationAsync(invocationExpressionSyntax).ConfigureAwait(false);

                if (invocationsTuple != null)
                {
                    invocationsList.Add(invocationsTuple);
                }
            }
            methodPerformanceInfo.UpdateCallees(invocationsList);

            // Loops
            // TODO RR: Clean and only Iterate once...
            var loopSyntaxs          = methodDeclarationSyntax.DescendantNodes(node => true).Where(n => n.IsLoopSyntax());
            var loopPerformanceInfos = new List <LoopPerformanceInfo>();

            foreach (var loopSyntax in loopSyntaxs)
            {
                loopPerformanceInfos.Add(await VisitLoopAsync(loopSyntax, methodPerformanceInfo).ConfigureAwait(false));
            }
            methodPerformanceInfo.UpdateLoops(loopPerformanceInfos);

            // TODO RR: Problem with textchanges: Insertions aren't recognized as change, since the space did not exist before...
            methodPerformanceInfo.HasChanged = methodDeclarationSyntax.HasTextChanges(TreeChanges);
            if (methodPerformanceInfo.HasChanged)
            {
                methodPerformanceInfo.PredictExecutionTime();
            }
            PerformanceTags.Add(methodDeclarationSyntax, new MethodPerformanceTag(methodPerformanceInfo));


            // TODO RR: all References:
            //var referencesToMethod = await SymbolFinder.FindCallersAsync(methodSymbol, _document.Project.Solution).ConfigureAwait(false);
        }
Example #3
0
        // ReSharper disable once SuggestBaseTypeForParameter
        private async Task <MethodPerformanceInfo> VisitInvocationAsync(InvocationExpressionSyntax invocationExpressionSyntax)
        {
            var invokedMethodSymbol = _semanticModel.GetSymbolInfo(invocationExpressionSyntax).Symbol as IMethodSymbol;

            // Only Drawing invocationSymbols that refer to the current assembly. Not drawing Information about other assemblies...
            if (invokedMethodSymbol == null || !Equals(_semanticModel.Compilation.Assembly, invokedMethodSymbol.ContainingAssembly))
            {
                return(null);
            }

            var invocationPerformanceInfo = await _telemetryDataMapper.GetMethodPerformanceInfoAsync(invokedMethodSymbol).ConfigureAwait(false);

            if (invocationPerformanceInfo != null)
            {
                PerformanceTags.Add(invocationExpressionSyntax, new MethodInvocationPerformanceTag(invocationPerformanceInfo));
            }
            return(invocationPerformanceInfo);
        }