public List <AutomatedAnalysisRule> ExecuteRules()
        {
            Issues = new AutomatedAnalysisIssueCollection();

            List <AutomatedAnalysisRule>           allRules        = new List <AutomatedAnalysisRule>();
            List <AutomatedAnalysisPerProcessRule> perProcessRules = new List <AutomatedAnalysisPerProcessRule>();

            // Run global rules, deferring per-process rules.
            AutomatedAnalysisExecutionContext executionContext = new AutomatedAnalysisExecutionContext(_trace, _textLog, Issues);

            foreach (AutomatedAnalysisRule rule in AutomatedAnalysisRuleResolver.GetRules())
            {
                // Create a list of all executed rules so that they can be written into the report.
                allRules.Add(rule);

                if (rule is AutomatedAnalysisPerProcessRule)
                {
                    // Defer per-process rules.
                    perProcessRules.Add((AutomatedAnalysisPerProcessRule)rule);
                }
                else
                {
                    // Execute the rule.
                    try
                    {
                        rule.RunRule(executionContext, null);
                    }
                    catch (Exception ex)
                    {
                        _textLog.WriteLine($"Error while executing rule '{rule.GetType().FullName}': {ex}");
                    }
                }
            }

            // Run per-process rules.
            foreach (AutomatedAnalysisTraceProcess process in executionContext.Trace.Processes)
            {
                if (process.ContainsManagedCode)
                {
                    // Create the process context.
                    ProcessContext processContext = new ProcessContext(executionContext, process);

                    foreach (AutomatedAnalysisPerProcessRule rule in perProcessRules)
                    {
                        try
                        {
                            rule.RunRule(executionContext, processContext);
                        }
                        catch (Exception ex)
                        {
                            _textLog.WriteLine($"Error while executing rule '{rule.GetType().FullName}': {ex}");
                        }
                    }
                }
            }

            return(allRules);
        }
Пример #2
0
        /// <summary>
        /// Process a single trace.
        /// </summary>
        /// <param name="trace">The trace.</param>
        /// <returns>The result of processing the trace.</returns>
        public TraceProcessorResult ProcessTrace(ITrace trace)
        {
            List<ProcessAnalyzer> processAnalyzers = new List<ProcessAnalyzer>();

            // Run global analyzers, deferring per-process analyzers.
            AnalyzerExecutionContext executionContext = new AnalyzerExecutionContext(_configuration, trace);
            foreach (Analyzer analyzer in _analyzers)
            {
                if (analyzer is ProcessAnalyzer)
                {
                    // Defer per-process analyzers.
                    processAnalyzers.Add((ProcessAnalyzer)analyzer);
                }
                else
                {
                    // Execute the analyzer.
                    try
                    {
                        using (new AnalyzerExecutionScope(analyzer))
                        {
                            analyzer.RunAnalyzer(executionContext, null);
                        }
                    }
                    catch (Exception ex)
                    {
                        AutomatedAnalysisEventSource.Log.Error($"Error while executing analyzer '{analyzer.GetType().FullName}': {ex}");
                    }
                }
            }

            // Run per-process analyzers.
            foreach (Process process in executionContext.Trace.Processes)
            {
                if (process.ContainsManagedCode)
                {
                    // Create the process context.
                    ProcessContext processContext = new ProcessContext(executionContext, process);

                    foreach (ProcessAnalyzer analyzer in processAnalyzers)
                    {
                        try
                        {
                            using (new AnalyzerExecutionScope(analyzer))
                            {
                                analyzer.RunAnalyzer(executionContext, processContext);
                            }
                        }
                        catch (Exception ex)
                        {
                            AutomatedAnalysisEventSource.Log.Error($"Error while executing analyzer '{analyzer.GetType().FullName}': {ex}");
                        }
                    }
                }
            }

            return new TraceProcessorResult(_analyzers, executionContext);
        }
        public void GenerateReport(TextWriter writer)
        {
            using (AutomatedAnalysisReportGenerator reportGenerator = new AutomatedAnalysisReportGenerator(writer))
            {
                List <AutomatedAnalysisRule>           allRules        = new List <AutomatedAnalysisRule>();
                List <AutomatedAnalysisPerProcessRule> perProcessRules = new List <AutomatedAnalysisPerProcessRule>();

                // Run global rules, deferring per-process rules.
                AutomatedAnalysisExecutionContext executionContext = new AutomatedAnalysisExecutionContext(_traceLog, _textLog, _symbolReader, _issueCollection);
                foreach (AutomatedAnalysisRule rule in AutomatedAnalysisRuleResolver.GetRules())
                {
                    // Create a list of all executed rules so that they can be written into the report.
                    allRules.Add(rule);

                    if (rule is AutomatedAnalysisPerProcessRule)
                    {
                        // Defer per-process rules.
                        perProcessRules.Add((AutomatedAnalysisPerProcessRule)rule);
                    }
                    else
                    {
                        // Execute the rule.
                        rule.RunRule(executionContext, null);
                    }
                }

                // Run per-process rules.
                foreach (TraceProcess process in executionContext.TraceLog.Processes)
                {
                    if (process.ManagedProcess())
                    {
                        // Create the process context.
                        ProcessContext processContext = new ProcessContext(executionContext, process);

                        foreach (AutomatedAnalysisPerProcessRule rule in perProcessRules)
                        {
                            rule.RunRule(executionContext, processContext);
                        }
                    }
                }

                // Write out issues.
                foreach (KeyValuePair <TraceProcess, List <AutomatedAnalysisIssue> > pair in _issueCollection)
                {
                    if (pair.Value.Count > 0)
                    {
                        reportGenerator.WriteIssuesForProcess(pair.Key, pair.Value);
                    }
                }

                // Write the list of executed rules.
                reportGenerator.WriteExecutedRulesList(allRules);
            }
        }
        public AutomatedAnalysisResult ProcessTrace(ITrace trace, TextWriter textLog)
        {
            List <PerProcessAnalyzer> perProcessAnalyzers = new List <PerProcessAnalyzer>();

            // Run global analyzers, deferring per-process analyzers.
            AnalyzerExecutionContext executionContext = new AnalyzerExecutionContext(_configuration, trace, textLog);

            foreach (Analyzer analyzer in _analyzers)
            {
                if (analyzer is PerProcessAnalyzer)
                {
                    // Defer per-process analyzers.
                    perProcessAnalyzers.Add((PerProcessAnalyzer)analyzer);
                }
                else
                {
                    // Execute the analyzer.
                    try
                    {
                        analyzer.RunAnalyzer(executionContext, null);
                    }
                    catch (Exception ex)
                    {
                        textLog.WriteLine($"Error while executing analyzer '{analyzer.GetType().FullName}': {ex}");
                    }
                }
            }

            // Run per-process analyzers.
            foreach (AnalyzerTraceProcess process in executionContext.Trace.Processes)
            {
                if (process.ContainsManagedCode)
                {
                    // Create the process context.
                    ProcessContext processContext = new ProcessContext(executionContext, process);

                    foreach (PerProcessAnalyzer analyzer in perProcessAnalyzers)
                    {
                        try
                        {
                            analyzer.RunAnalyzer(executionContext, processContext);
                        }
                        catch (Exception ex)
                        {
                            textLog.WriteLine($"Error while executing analyzer '{analyzer.GetType().FullName}': {ex}");
                        }
                    }
                }
            }

            return(new AutomatedAnalysisResult(_analyzers, executionContext));
        }
Пример #5
0
 internal override AnalyzerExecutionResult RunAnalyzer(AnalyzerExecutionContext executionContext, ProcessContext processContext)
 {
     return(Execute(executionContext, processContext));
 }
Пример #6
0
 /// <summary>
 /// Called by the platform to analyze a single process.
 /// </summary>
 /// <param name="executionContext">The context associated with this execution of the Analyzer.</param>
 /// <param name="processContext">The process-specific context associated with this execution of the Analyzer.</param>
 /// <returns>The result of the execution.</returns>
 protected abstract AnalyzerExecutionResult Execute(AnalyzerExecutionContext executionContext, ProcessContext processContext);
Пример #7
0
 protected abstract void Execute(AutomatedAnalysisExecutionContext executionContext, ProcessContext processContext);
Пример #8
0
 internal override void RunRule(AutomatedAnalysisExecutionContext executionContext, ProcessContext processContext)
 {
     Execute(executionContext, processContext);
 }
Пример #9
0
 internal virtual void RunRule(AutomatedAnalysisExecutionContext executionContext, ProcessContext processContext)
 {
     Execute(executionContext);
 }