Beispiel #1
0
        /// <summary>
        /// Stops monitoring and reports finish state of the analysis.
        /// </summary>
        private void analysisFinished()
        {
            watch.Stop();
            timer.IsEnabled    = false;
            memoryText.Content = OutputUtils.GetMemoryText(GC.GetTotalMemory(true));

            warningsTab.Visibility = System.Windows.Visibility.Visible;
            FlowDocumentOutput warningsOutput = new FlowDocumentOutput(warningsFlowDocument);

            warningsOutput.ClearDocument();
            currentAnalyser.GenerateWarnings(warningsOutput);

            finalSnapshotTab.Visibility = System.Windows.Visibility.Visible;
            FlowDocumentOutput finalSnapshotOutput = new FlowDocumentOutput(finalSnapshotFlowDocument);

            finalSnapshotOutput.ClearDocument();
            currentAnalyser.GenerateFinalSnapshotText(finalSnapshotOutput);

            if (currentAnalyser.EndState == AnalysisEndState.Success && isBenchmarkEnabled)
            {
                exportBenchmarkMenu.IsEnabled = true;
            }

            abortButton.IsEnabled = false;
        }
Beispiel #2
0
        private void actualizeMemory()
        {
            // Report memory every 5 sec
            if (memoryCounter == 0)
            {
                memoryCounter = MEMORY_COUTER_LIMIT;
                long memoryConsumption = GC.GetTotalMemory(false);
                memoryText.Content = OutputUtils.GetMemoryText(memoryConsumption);
                if (memoryConsumption > memoryLimit)
                {
                    //reportEvent("Memory limit reached - trying to garbage collect");
                    //memoryConsumption = GC.GetTotalMemory(true);
                    if (memoryConsumption > memoryLimit && currentAnalyser != null && !currentAnalyser.IsFinished)
                    {
                        if (currentAnalysisThred != null)
                        {
                            // try to garbage collect
                            memoryConsumption = GC.GetTotalMemory(true);
                            reportEvent("Memory limit reached - terminating the analysis");
                            currentAnalysisThred.Abort(AnalysisEndState.AbortMemory);
                        }
                    }
                }
            }

            memoryCounter--;
        }
Beispiel #3
0
        /// <summary>
        /// Starts the analysis with specified settings. Analysis is started in separated thread.
        /// The Dispatcher timer is started to monitor progress of the analysis.
        /// </summary>
        private void startAnalysis()
        {
            isFirstPhaseStartNotReported  = true;
            isFirstPhaseEndNotReported    = true;
            isSecondPhaseStartNotReported = true;
            isSecondPhaseEndNotReported   = true;

            memoryLimitText.Content = OutputUtils.GetMemoryText(memoryLimit);

            outputTab.IsSelected        = true;
            warningsTab.Visibility      = System.Windows.Visibility.Collapsed;
            finalSnapshotTab.Visibility = System.Windows.Visibility.Collapsed;

            memoryText.Content = OutputUtils.GetMemoryText(GC.GetTotalMemory(true));

            abortButton.IsEnabled = true;

            currentAnalyser = new Analyser(fileName, secondPhaseType, memoryModelType);

            watch           = Stopwatch.StartNew();
            timer.IsEnabled = true;

            ThreadPool.QueueUserWorkItem(startAnalyserMainMethod);

            exportBenchmarkMenu.IsEnabled = false;

            reportAnalysisStart();
        }
Beispiel #4
0
        /// <summary>
        /// Generates the output of the analysis.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateOutput(OutputBase output)
        {
            output.EmptyLine();
            output.Headline("Analysis summary");

            if (Watch != null)
            {
                var ts = Watch.Elapsed;

                output.EmptyLine();
                output.Headline2("Time consumption");
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                output.CommentLine("Weverca analyzer time consumption: " + elapsedTime);

                if (IsFirstPhaseStarted)
                {
                    var ts1 = WatchFirstPhase.Elapsed;
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts1.Hours, ts1.Minutes, ts1.Seconds, ts1.Milliseconds);
                    output.CommentLine("First phase time consumption: " + elapsedTime);
                }
                if (IsSecondPhaseStarted)
                {
                    var ts2 = WatchSecondPhase.Elapsed;
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds);
                    output.CommentLine("Second phase time consumption: " + elapsedTime);
                }
            }

            if (FirstPhaseInitialMemory != 0)
            {
                output.EmptyLine();
                output.Headline2("Memory consumption");
                output.CommentLine(string.Format("Initial memory before the first phase: {0}",
                                                 OutputUtils.GetMemoryText(FirstPhaseInitialMemory)
                                                 ));

                if (IsFirstPhaseStarted)
                {
                    output.CommentLine(string.Format("Memory at the end of the first phase: {0} (diff: {1})",
                                                     OutputUtils.GetMemoryText(FirstPhaseEndMemory),
                                                     OutputUtils.GetMemoryText(FirstPhaseEndMemory - FirstPhaseInitialMemory)
                                                     ));
                }
                if (IsSecondPhaseStarted)
                {
                    output.CommentLine(string.Format("Memory at the end of the second phase: {0} (diff: {1})",
                                                     OutputUtils.GetMemoryText(SecondPhaseEndMemory),
                                                     OutputUtils.GetMemoryText(SecondPhaseEndMemory - FirstPhaseEndMemory)
                                                     ));
                }
            }

            output.EmptyLine();
            output.Headline2("Code statistics");

            if (controlFlowGraph != null)
            {
                List <BasicBlock> basicBlocks = controlFlowGraph.CollectAllBasicBlocks();
                output.CommentLine("The number of basic blocks of code is: " + basicBlocks.Count);
            }

            if (programPointGraph != null)
            {
                var programLines          = new Dictionary <string, HashSet <int> >();
                int numberOfProgramPoints = NumProgramPoints(new HashSet <ProgramPointGraph>(), programLines, programPointGraph);
                int numberOfProgramLines  = NumProgramLines(programLines);

                output.CommentLine("The number of processed lines of code is: " + numberOfProgramLines);
                output.CommentLine("The number of program points in the application is: " + numberOfProgramPoints);

                if (programPointGraph.End.OutSet != null)
                {
                    output.CommentLine("The number of memory locations in final snapshot is: " + programPointGraph.End.OutSnapshot.NumMemoryLocations());
                }
                else
                {
                    output.CommentLine("End program point was not reached");
                }
            }
            else
            {
                output.CommentLine("Program point graph was not built");
            }

            output.EmptyLine();
            output.Headline2("Warnings");
            output.CommentLine("Total number of warnings: " + GetNumberOfWarnings());
            if (IsFirstPhaseStarted)
            {
                output.CommentLine("Number of warnings in the first phase: " + (analysisWarnings.Count + securityWarnings.Count));
            }
            if (IsSecondPhaseStarted)
            {
                output.CommentLine("Number of warnings in the second phase: " + secondPhaseWarnings.Count);
            }
        }