private void PropagateCostlyReachableMark(HotMethodAnalyzerContext context)
        {
            var callGraph = context.InvertedCallGraph;
            var nodes     = new HashSet <IDeclaredElement>();

            foreach (var(from, toVertices) in callGraph)
            {
                if (context.IsDeclaredElementCostlyReachable(from))
                {
                    nodes.Add(from);
                }
                foreach (var to in toVertices)
                {
                    if (context.IsDeclaredElementCostlyReachable(to))
                    {
                        nodes.Add(to);
                    }
                }
            }

            var visited = new HashSet <IDeclaredElement>();

            foreach (var node in nodes)
            {
                PropagateCostlyMark(node, callGraph, context, visited);
            }
        }
Esempio n. 2
0
        private void PropagateCostlyReachableMark(HotMethodAnalyzerContext context)
        {
            var callGraph = context.InvertedCallGraph;
            var nodes     = new HashSet <IDeclaredElement>();

            foreach (var costlyMethod in context.CostlyMethods)
            {
                nodes.Add(costlyMethod);
            }

            var visited = new HashSet <IDeclaredElement>();

            foreach (var node in nodes)
            {
                PropagateCostlyMark(node, callGraph, context, visited);
            }
        }
        private static HotMethodAnalyzerContext GetHotMethodAnalyzerContext(IHighlightingConsumer consumer, HashSet <IMethodDeclaration> hotRootMethods,
                                                                            IPsiSourceFile sourceFile)
        {
            // sharing context for each hot root.
            var context = new HotMethodAnalyzerContext();

            foreach (var methodDeclaration in hotRootMethods)
            {
                var declaredElement = methodDeclaration.DeclaredElement.NotNull("declaredElement != null");
                context.CurrentDeclaredElement = declaredElement;

                var visitor = new HotMethodAnalyzer(sourceFile, consumer, ourMaxAnalysisDepth);
                methodDeclaration.ProcessDescendants(visitor, context);
            }

            return(context);
        }
        private void PropagateCostlyMark(IDeclaredElement node, IReadOnlyDictionary <IDeclaredElement, HashSet <IDeclaredElement> > callGraph,
                                         HotMethodAnalyzerContext context, ISet <IDeclaredElement> visited)
        {
            if (visited.Contains(node))
            {
                return;
            }
            visited.Add(node);
            context.MarkElementAsCostlyReachable(node);

            if (callGraph.TryGetValue(node, out var children))
            {
                foreach (var child in children)
                {
                    PropagateCostlyMark(child, callGraph, context, visited);
                }
            }
        }
Esempio n. 5
0
        private HotMethodAnalyzerContext GetHotMethodAnalyzerContext(IHighlightingConsumer consumer, HashSet <IDeclaration> hotRootMethods,
                                                                     IPsiSourceFile sourceFile)
        {
            // sharing context for each hot root.
            var context = new HotMethodAnalyzerContext();

            foreach (var declaration in hotRootMethods)
            {
                var declaredElement = declaration.DeclaredElement;
                if (declaredElement == null)
                {
                    continue;
                }

                context.CurrentDeclaredElement = declaredElement;
                context.CurrentDeclaration     = declaration;

                var visitor = new HotMethodAnalyzer(sourceFile, consumer, myCheckForInterrupt, ourMaxAnalysisDepth);
                declaration.ProcessThisAndDescendants(visitor, context);
            }

            return(context);
        }
Esempio n. 6
0
        private static void HighlightCostlyReachableInvocation(IHighlightingConsumer consumer, HotMethodAnalyzerContext context)
        {
            foreach (var kvp in context.InvocationsInMethods)
            {
                var method = kvp.Key;
                if (!context.IsDeclaredElementCostly(method))
                {
                    continue;
                }

                var invocationElements = kvp.Value;
                foreach (var invocationElement in invocationElements)
                {
                    var invokedMethod = invocationElement.Key;
                    if (!context.IsDeclaredElementCostly(invokedMethod))
                    {
                        continue;
                    }

                    var references = invocationElement.Value;
                    foreach (var reference in references)
                    {
                        var referenceExpression = reference.InvokedExpression as IReferenceExpression;
                        if (referenceExpression == null)
                        {
                            continue;
                        }
                        consumer.AddHighlighting(new PerformanceInvocationHighlighting(reference,
                                                                                       referenceExpression.Reference.NotNull("(reference.InvokedExpression as IReferenceExpression).Reference != null")));
                    }
                }
            }
        }
        private static void HighlightCostlyReachableInvocation(IHighlightingConsumer consumer, HotMethodAnalyzerContext context)
        {
            foreach (var kvp in context.InvocationsInMethods)
            {
                var method = kvp.Key;
                if (!context.IsDeclaredElementCostlyReachable(method))
                {
                    continue;
                }

                var invocationElements = kvp.Value;
                foreach (var invocationElement in invocationElements)
                {
                    var invokedMethod = invocationElement.Key;
                    if (!context.IsDeclaredElementCostlyReachable(invokedMethod))
                    {
                        continue;
                    }

                    var references = invocationElement.Value;
                    foreach (var reference in references)
                    {
                        consumer.AddHighlighting(new PerformanceCriticalCodeInvocationReachableHighlighting(reference));
                    }
                }
            }
        }