]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
Adding StatisticsAspect
authorErlend Kristiansen <erlenkr@ifi.uio.no>
Wed, 19 Feb 2014 07:40:33 +0000 (08:40 +0100)
committerErlend Kristiansen <erlenkr@ifi.uio.no>
Wed, 19 Feb 2014 07:40:33 +0000 (08:40 +0100)
software/no.uio.ifi.refaktor.benchmark/src/no/uio/ifi/refaktor/benchmark/PerPackageSearchBasedExtractAndMoveMethodChangerBenchmark.java
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/analyzers/SearchBasedExtractAndMoveMethodAnalyzer.java
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/analyzers/TypeWideExtractAndMoveMethodAnalyzer.java
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/aspects/StatisticsAspect.aj [new file with mode: 0644]

index 9ad55bcde8be5a8647e050953a25aebc8c84f8e7..8031ce306a64247b564e577ce3219692db6813d6 100644 (file)
@@ -4,6 +4,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
+import no.uio.ifi.refaktor.aspects.StatisticsAspect;
 import no.uio.ifi.refaktor.change.changers.PackageWideExtractAndMoveMethodChanger;
 import no.uio.ifi.refaktor.change.changers.RefaktorChanger;
 import no.uio.ifi.refaktor.utils.RefaktorDebug;
@@ -23,6 +24,7 @@ public class PerPackageSearchBasedExtractAndMoveMethodChangerBenchmark extends A
 
                assertTrue(getProject().exists());
 
+               StatisticsAspect.aspectOf().init();
                makeChangesToWorkspace();
 
                getStatistics().recordTimeUsed();
index c575f34979dc4d3480ff6fd0bfd022059a986d0f..654462c989cf194c2565488c80b4f53be41f9af9 100644 (file)
@@ -4,7 +4,6 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.Set;
 
-import no.uio.ifi.refaktor.analyze.AnalysisStatistics;
 import no.uio.ifi.refaktor.analyze.ExtractAndMoveMethodAnalysisResult;
 import no.uio.ifi.refaktor.analyze.comparators.ExtractAndMoveMethodAnalysisResultComparator;
 import no.uio.ifi.refaktor.analyze.comparators.IgnorantAnalysisResultComparator;
@@ -26,7 +25,6 @@ public class SearchBasedExtractAndMoveMethodAnalyzer implements Analyzer {
 
        private final IMethod method;
        private final ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator;
-       private final AnalysisStatistics statistics;
        private Set<CompilationUnitTextSelection> textSelections;
        private LinkedList<ExtractAndMoveMethodAnalysisResult> possibleResults;
        private ExtractAndMoveMethodAnalysisResult chosenResult;
@@ -36,22 +34,14 @@ public class SearchBasedExtractAndMoveMethodAnalyzer implements Analyzer {
                this(method, new IgnorantAnalysisResultComparator());
        }
 
-       public SearchBasedExtractAndMoveMethodAnalyzer(IMethod method, 
-                       ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator) {
-               this(method, analysisResultComparator, new AnalysisStatistics());
-       }
-
        /**
         * @param method The handler for the method to analyze.
         * @param analysisResultComparator A result comparator to compare two analysis results when deciding
         *              which of them that is the best candidate for the refactoring.
-        * @param statistics 
         */
-       public SearchBasedExtractAndMoveMethodAnalyzer(IMethod method, 
-                       ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator, AnalysisStatistics statistics) {
+       public SearchBasedExtractAndMoveMethodAnalyzer(IMethod method, ExtractAndMoveMethodAnalysisResultComparator analysisResultComparator) {
                this.method = method;
                this.analysisResultComparator = analysisResultComparator;
-               this.statistics = statistics;
                possibleResults = new LinkedList<ExtractAndMoveMethodAnalysisResult>();
                statementsCreator = new StatementsCreator(method);
        }
@@ -62,10 +52,6 @@ public class SearchBasedExtractAndMoveMethodAnalyzer implements Analyzer {
 
        @Override
        public void analyze() throws RefaktorAnalyzerException {
-               statistics.incrementMethodCount();
-
-               printDebugInfo();
-
                // TODO: make the Extract and Move Method Refactoring work with static methods
                abortIfStaticMethod();
 
@@ -78,15 +64,6 @@ public class SearchBasedExtractAndMoveMethodAnalyzer implements Analyzer {
                chooseResult();
        }
 
-       private void printDebugInfo() {
-               try {
-                       RefaktorDebug.println("#" + statistics.getMethodCount() + " (" + statistics.timeSinceStart() + "): " + method.getDeclaringType().getElementName() + "." + method.getElementName() + " (" + "offset: "
-                                       + method.getSourceRange().getOffset() + ", length: " + method.getSourceRange().getLength() + ")");
-               } catch (JavaModelException e) {
-                       RefaktorDebug.println("No info about " + method.getElementName());
-               }
-       }
-
        private void abortIfStaticMethod() {
                try {
                        if (Flags.isStatic(method.getFlags()))
index 6e243866cc501ce111db3c1af04ea9e74de19bcd..3a6567ec517f75206d580dbe867ea332e6d3f88f 100644 (file)
@@ -54,7 +54,7 @@ public class TypeWideExtractAndMoveMethodAnalyzer implements AggregationAnalyzer
        private void analyzeMethod(IMethod method) {
                try {
                        SearchBasedExtractAndMoveMethodAnalyzer analyzer = 
-                                       new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator(), statistics);
+                                       new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator());
                        analyzer.analyze();
                        results.add(analyzer.getResult());
                } catch (NoTargetFoundException e) {
diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/aspects/StatisticsAspect.aj b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/aspects/StatisticsAspect.aj
new file mode 100644 (file)
index 0000000..3d22f94
--- /dev/null
@@ -0,0 +1,50 @@
+package no.uio.ifi.refaktor.aspects;
+
+import no.uio.ifi.refaktor.analyze.analyzers.SearchBasedExtractAndMoveMethodAnalyzer;
+import no.uio.ifi.refaktor.utils.RefaktorDebug;
+
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+
+privileged public aspect StatisticsAspect {
+       private long startTime;
+       private int methodCount;
+
+       pointcut methodAnalyze(SearchBasedExtractAndMoveMethodAnalyzer analyzer) : 
+               call(* SearchBasedExtractAndMoveMethodAnalyzer.analyze()) && target(analyzer);
+       
+       before(SearchBasedExtractAndMoveMethodAnalyzer analyzer) : methodAnalyze(analyzer) {
+               methodCount++;
+               debugPrintMethodAnalysisProgress(analyzer.method);
+       }
+       
+       private void debugPrintMethodAnalysisProgress(IMethod method) {
+               try {
+                       RefaktorDebug.println("#" + methodCount + " (" + timeSinceStart() + "): " 
+                                       + method.getDeclaringType().getElementName() + "." + method.getElementName() + " (" + "offset: "
+                                       + method.getSourceRange().getOffset() + ", length: " + method.getSourceRange().getLength() + ")");
+               } catch (JavaModelException e) {
+                       RefaktorDebug.println("No info about " + method.getElementName());
+               }
+       }
+       
+       public void init() {
+               startTime = System.currentTimeMillis();
+               methodCount = 0;
+       }
+       
+       private String timeSinceStart() {
+               long durationInMillis = System.currentTimeMillis() - startTime;
+               long secondsSinceAnalysisStart = durationInMillis/1000;
+
+               if (secondsSinceAnalysisStart > 0)
+                       return secondsSinceAnalysisStart/60 + "m" + secondsSinceAnalysisStart % 60 + "s";
+               else
+                       return durationInMillis + "ms";
+       }
+       
+       public int getMethodCount() {
+               return methodCount;
+       }
+       
+}