memoizeittf

fixed methods synchronization. raised threshold to 0.5. added

9/11/2020 2:04:21 AM

Details

diff --git a/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/adapter/Thresholds.java b/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/adapter/Thresholds.java
index f904ce7..c6fbf67 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/adapter/Thresholds.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/adapter/Thresholds.java
@@ -18,7 +18,7 @@ import java.util.List;
 public class Thresholds {
 
     private static final List<BigDecimal> SAVED_TIME_PER_TIME_IN_CACHE = new ArrayList<>();
-    private static final BigDecimal SAVED_TIME_PER_TIME_IN_CACHE_THRESHOLD = new BigDecimal(0.1);
+    private static final BigDecimal SAVED_TIME_PER_TIME_IN_CACHE_THRESHOLD = new BigDecimal(0.5);
 
     private static BigDecimal averageSavedTimePerTimeInCache;
     private static BigDecimal stdDevSavedTimePerTimeInCache;
diff --git a/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/Main.java b/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/Main.java
index 106851b..9e7e9b9 100755
--- a/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/Main.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/Main.java
@@ -9,6 +9,8 @@ import br.ufrgs.inf.prosoft.memoizeit.adapter.CallGraphReader;
 import br.ufrgs.inf.prosoft.memoizeit.graph.Graph;
 import br.ufrgs.inf.prosoft.memoizeittf.adapter.TraceReader;
 import br.ufrgs.inf.prosoft.memoizeittf.facade.Method;
+import br.ufrgs.inf.prosoft.tfcache.StorageManager;
+import br.ufrgs.inf.prosoft.tfcache.configuration.Arguments;
 import br.ufrgs.inf.prosoft.tfcache.configuration.Configuration;
 import br.ufrgs.inf.prosoft.trace.Trace;
 import br.ufrgs.inf.prosoft.trace.reader.Mode;
@@ -16,8 +18,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 /**
  *
@@ -31,22 +31,11 @@ public class Main {
         System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT+%1$tL] [%4$-7s] [MemoizeItTF] %5$s %n");
 
         if (args.length < 2) {
-            System.err.println("--trace=<TracePath> --callgraph=<CallGraphPath> [--tfkernel=<exhaustive|optimised>] [--mode=<complete|hashed|partial>] [--kernel=<iterative|exhaustive>] [--window=<windowSize>] [--shift=<shiftTime>]");
+            System.err.println("--trace=<TracePath> --callgraph=<CallGraphPath> [--tfstore=<storePath>] [--tfkernel=<exhaustive|optimised>] [--mode=<complete|hashed|partial>] [--kernel=<iterative|exhaustive>] [--window=<windowSize>] [--shift=<shiftTime>]");
             System.exit(1);
         }
 
-        Map<String, String> arguments = Stream.of(args).map(arg -> {
-            arg = arg.replaceFirst("--", "");
-            int indexOf = arg.indexOf("=");
-            if (indexOf == -1) {
-                return new String[]{arg, ""};
-            }
-            return new String[]{arg.substring(0, indexOf), arg.substring(indexOf + 1)};
-        }).collect(Collectors.toMap(array -> {
-            return array[0];
-        }, array -> {
-            return array[1];
-        }));
+        Map<String, String> arguments = Arguments.parse(args);
 
         String tracePath = arguments.get("trace");
         if (tracePath == null) {
@@ -88,9 +77,13 @@ public class Main {
         List<Method> methods = TraceReader.groupByMethods(traces);
         LOGGER.log(Level.INFO, "grouped traces into {0} methods", methods.size());
 
+        Configuration.setLevel("method");
         Configuration.setKernel(arguments.get("tfkernel"));
         Configuration.setStaleness("ignore");
+        Configuration.setStore(arguments.get("tfstore"));
+        StorageManager.load();
         MemoizeItTF memoizeItTF = new MemoizeItTF(methods, graph);
         memoizeItTF.recommend(kernel.equals("iterative"));
+        StorageManager.update();
     }
 }
diff --git a/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/MemoizeItTF.java b/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/MemoizeItTF.java
index 24e32bf..ab4c44f 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/MemoizeItTF.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/memoizeittf/MemoizeItTF.java
@@ -21,7 +21,7 @@ public class MemoizeItTF extends MemoizeIt {
 
     public MemoizeItTF(List<Method> methods, Graph<String> callgraph) {
         this.methods = new Methods(methods);
-        setMethods(Methods.getMemoizeitMethods(methods));
+        setMethods(this.methods.getMemoizeitMethods());
         setCallGraph(callgraph);
         setMinimumHitRatio(0D);
     }
@@ -41,21 +41,21 @@ public class MemoizeItTF extends MemoizeIt {
         LOGGER.log(Level.INFO, "Recommending TTL to {0} methods", tfcacheMethods.size());
         tfcacheMethods.stream().parallel().forEach(br.ufrgs.inf.prosoft.tfcache.metadata.Method::recommendTTL);
         LOGGER.log(Level.INFO, "Removing not recommended from {0}", tfcacheMethods.size());
-        tfcacheMethods.removeIf(method -> method.getSavedTime() == 0);
+        tfcacheMethods.removeIf(method -> method.getBestMetrics().getSavedTime() == 0);
 
         LOGGER.log(Level.INFO, "Removing methods according to the STpTiC Threshold from {0}", tfcacheMethods.size());
-        tfcacheMethods.removeIf(method -> method.getSavedTimePerTimeInCache().compareTo(Thresholds.savedTimePerTimeInCacheThreshold()) < 0);
+        tfcacheMethods.removeIf(method -> method.getBestMetrics().getSavedTimePerTimeInCache().compareTo(Thresholds.savedTimePerTimeInCacheThreshold()) < 0);
 
         LOGGER.log(Level.INFO, "Ranking {0} methods according STpTiC", tfcacheMethods.size());
-        tfcacheMethods.sort((method1, method2) -> method2.getSavedTimePerTimeInCache().compareTo(method1.getSavedTimePerTimeInCache()));
+        tfcacheMethods.sort((method1, method2) -> method2.getBestMetrics().getSavedTimePerTimeInCache().compareTo(method1.getBestMetrics().getSavedTimePerTimeInCache()));
         LOGGER.log(Level.INFO, "Printing recommendations for {0} methods", tfcacheMethods.size());
         tfcacheMethods.forEach(method -> {
             System.out.println(method.getName()
                     + " Occurrences " + method.getOccurrencesSize()
                     + " Inputs " + method.groupsOfOccurrences().count()
-                    + " TTL " + method.getTtl()
-                    + " STpTiC " + method.getSavedTimePerTimeInCache()
-                    + " Saves " + method.getSavedTime()
+                    + " TTL " + method.getBestMetrics().getTtl()
+                    + " STpTiC " + method.getBestMetrics().getSavedTimePerTimeInCache()
+                    + " Saves " + method.getBestMetrics().getSavedTime()
                     + " Hits " + method.getBestMetrics().getHits()
                     + " Stales " + method.getBestMetrics().getStales());
         });