aplcachetf

replaced hitspertimeincache for savedtimepertimeincache.

9/11/2020 5:42:47 AM

Details

diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/APLCache.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/APLCache.java
index 759e29a..db01d6e 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/APLCache.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/APLCache.java
@@ -13,7 +13,6 @@ import com.google.gson.GsonBuilder;
 import com.google.gson.JsonObject;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -44,21 +43,21 @@ public class APLCache {
         Thresholds.population = getPopulation();
         this.methods.stream().forEach(Method::calculateThresholds);
 
-        LOGGER.log(Level.INFO, "\tAverage   ExecutionTime:      {0}", Thresholds.getAverageExecutionTime());
-        LOGGER.log(Level.INFO, "\tStdDv     ExecutionTime:      {0}", Thresholds.getStdDevExecutionTimeRatio());
-        LOGGER.log(Level.INFO, "\tThreshold ExecutionTime:      {0}", Thresholds.expensivenessThreshold(kStdDev));
-        LOGGER.log(Level.INFO, "\tAverage   HitRatio:           {0}", Thresholds.getAverageHitRatio());
-        LOGGER.log(Level.INFO, "\tStdDv     HitRatio:           {0}", Thresholds.getStdDevHitRatio());
-        LOGGER.log(Level.INFO, "\tThreshold HitRatio:           {0}", Thresholds.hitThreshold(kStdDev));
-        LOGGER.log(Level.INFO, "\tAverage   MissRatio:          {0}", Thresholds.getAverageMissRatio());
-        LOGGER.log(Level.INFO, "\tStdDv     MissRatio:          {0}", Thresholds.getStdDevMissRatio());
-        LOGGER.log(Level.INFO, "\tThreshold MissRatio:          {0}", Thresholds.missThreshold(kStdDev));
-        LOGGER.log(Level.INFO, "\tAverage   Shareability:       {0}", Thresholds.getAverageShareability());
-        LOGGER.log(Level.INFO, "\tStdDv     Shareability:       {0}", Thresholds.getStdDevShareability());
-        LOGGER.log(Level.INFO, "\tThreshold Shareability:       {0}", Thresholds.shareabilityThreshold(kStdDev));
-        LOGGER.log(Level.INFO, "\tAverage   HitsPerTimeInCache: {0}", Thresholds.getAverageHitsPerTimeInCache());
-        LOGGER.log(Level.INFO, "\tStdDv     HitsPerTimeInCache: {0}", Thresholds.getStdDevHitsPerTimeInCache());
-        LOGGER.log(Level.INFO, "\tThreshold HitsPerTimeInCache: {0}", Thresholds.hitsPerTimeInCacheThreshold(kStdDev));
+        LOGGER.log(Level.INFO, "\tAverage   ExecutionTime:           {0}", Thresholds.getAverageExecutionTime());
+        LOGGER.log(Level.INFO, "\tStdDv     ExecutionTime:           {0}", Thresholds.getStdDevExecutionTimeRatio());
+        LOGGER.log(Level.INFO, "\tThreshold ExecutionTime:           {0}", Thresholds.expensivenessThreshold(kStdDev));
+        LOGGER.log(Level.INFO, "\tAverage   HitRatio:                {0}", Thresholds.getAverageHitRatio());
+        LOGGER.log(Level.INFO, "\tStdDv     HitRatio:                {0}", Thresholds.getStdDevHitRatio());
+        LOGGER.log(Level.INFO, "\tThreshold HitRatio:                {0}", Thresholds.hitThreshold(kStdDev));
+        LOGGER.log(Level.INFO, "\tAverage   MissRatio:               {0}", Thresholds.getAverageMissRatio());
+        LOGGER.log(Level.INFO, "\tStdDv     MissRatio:               {0}", Thresholds.getStdDevMissRatio());
+        LOGGER.log(Level.INFO, "\tThreshold MissRatio:               {0}", Thresholds.missThreshold(kStdDev));
+        LOGGER.log(Level.INFO, "\tAverage   Shareability:            {0}", Thresholds.getAverageShareability());
+        LOGGER.log(Level.INFO, "\tStdDv     Shareability:            {0}", Thresholds.getStdDevShareability());
+        LOGGER.log(Level.INFO, "\tThreshold Shareability:            {0}", Thresholds.shareabilityThreshold(kStdDev));
+        LOGGER.log(Level.INFO, "\tAverage   SavedTimePerTimeInCache: {0}", Thresholds.getAverageSavedTimePerTimeInCache());
+        LOGGER.log(Level.INFO, "\tStdDv     SavedTimePerTimeInCache: {0}", Thresholds.getStdDevSavedTimePerTimeInCache());
+        LOGGER.log(Level.INFO, "\tThreshold SavedTimePerTimeInCache: {0}", Thresholds.savedTimePerTimeInCacheThreshold(kStdDev));
     }
 
     private void filterCacheableInputs(int kStdDev) {
@@ -92,10 +91,23 @@ public class APLCache {
         filterCacheableInputs(kStdDev);
 
         LOGGER.log(Level.INFO, "{0} cacheable methods detected", this.methods.size());
-        Collections.sort(this.methods, (m1, m2) -> Long.compare(m2.getSavedTime(), m1.getSavedTime()));
+        this.methods.sort((method1, method2) -> method2.getEstimatedSavedTimePerTimeInCache().compareTo(method1.getEstimatedSavedTimePerTimeInCache()));
 
         this.methods.forEach(method -> {
-            System.out.println(method.getName() + " Occurrences " + method.getOccurrencesSize() + " Inputs " + method.groupsOfOccurrences().count() + " TTL " + method.getTtl() + " HpTiC " + method.getHitsPerTimeInCache() + " Saves " + method.getSavedTime());
+            if (method.getBestMetrics() != null) {
+                System.out.println(method.getName()
+                        + " Occurrences " + method.getOccurrencesSize()
+                        + " Inputs " + method.groupsOfOccurrences().count()
+                        + " TTL " + method.getBestMetrics().getTtl()
+                        + " STpTiC " + method.getBestMetrics().getSavedTimePerTimeInCache()
+                        + " Saves " + method.getBestMetrics().getSavedTime()
+                        + " Hits " + method.getBestMetrics().getHits()
+                        + " Stales " + method.getBestMetrics().getStales());
+            } else {
+                System.out.println(method.getName()
+                        + " Occurrences " + method.getOccurrencesSize()
+                        + " Inputs " + method.groupsOfOccurrences().count());
+            }
         });
         try (FileWriter fileWriter = new FileWriter(outputPath)) {
             JsonObject jsonCacheableParameters = new JsonObject();
diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/GroupOfOccurrences.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/GroupOfOccurrences.java
index f065eea..575546c 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/GroupOfOccurrences.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/GroupOfOccurrences.java
@@ -5,13 +5,11 @@
  */
 package br.ufrgs.inf.prosoft.aplcachetf.extension.metadata;
 
-import br.ufrgs.inf.prosoft.aplcachetf.extension.metrics.Thresholds;
 import br.ufrgs.inf.prosoft.aplcachetf.extension.metrics.Metrics;
+import br.ufrgs.inf.prosoft.aplcachetf.extension.metrics.Thresholds;
 import br.ufrgs.inf.prosoft.tfcache.Simulator;
 import br.ufrgs.inf.prosoft.tfcache.metadata.Occurrence;
 import java.math.BigDecimal;
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -49,52 +47,44 @@ public class GroupOfOccurrences {
 
     public Metrics getBestMetrics() {
         if (this.bestMetrics == null) {
-            throw new RuntimeException("hitsPerTimeInCache must be calculated");
+            throw new RuntimeException("SavedTimePerTimeInCache must be calculated");
         }
         return this.bestMetrics;
     }
 
-    public Long getTtl() {
-        return getBestMetrics().getTtl();
+    public long getTtl() {
+        return getBestMetrics().getTfmetrics().getTtl();
     }
 
-    public Long getSavedTime() {
-        return getBestMetrics().getSavedTime();
+    public long getHits() {
+        return getBestMetrics().getTfmetrics().getHits();
     }
 
-    public BigDecimal getHitsPerTimeInCache() {
-        return getBestMetrics().getHitsPerTimeInCache();
+    public long getStales() {
+        return getBestMetrics().getTfmetrics().getStales();
     }
 
-    private void calculateHitsPerTimeInCache() {
-        if (this.bestMetrics != null) {
-            LOGGER.log(Level.WARNING, "HitsPerTimeInCache already calculated");
-        }
-        this.bestMetrics = new Metrics();
-
-        Collection<Long> ttlsOfInterest = new HashSet<>();
-        for (int hits = 1; hits < this.occurrences.size(); hits++) {
-            for (int shift = 0; shift < this.occurrences.size() - hits; shift++) {
-                long ttl = 0;
-                for (int k = shift + 1; k < shift + 1 + hits; k++) {
-                    ttl += this.occurrences.get(k).getStartTime() - this.occurrences.get(k - 1).getEndTime();
-                }
-                if (ttl > 0) {
-                    ttlsOfInterest.add(ttl);
-                }
-            }
-        }
+    public long getSavedTime() {
+        return getBestMetrics().getTfmetrics().getSavedTime();
+    }
 
-        ttlsOfInterest.stream().parallel().forEach(actualTTL -> {
-            Simulator.simulate(occurrences(), actualTTL, this.bestMetrics);
-        });
+    public BigDecimal getSavedTimePerTimeInCache() {
+        return getBestMetrics().getTfmetrics().getSavedTimePerTimeInCache();
     }
 
     protected void calculateMetrics() {
+        if (this.bestMetrics != null) {
+            LOGGER.log(Level.WARNING, "Metrics already calculated");
+        }
         if (this.occurrences.size() < 2) {
-            throw new RuntimeException("Cannot calculate metrics for not reusable input");
+            throw new RuntimeException("Not reusable input");
         }
-        calculateHitsPerTimeInCache();
+
+        this.bestMetrics = new Metrics();
+
+        this.occurrences.sort((occurrence1, occurrence2) -> Long.compare(occurrence1.getStartTime(), occurrence2.getStartTime()));
+        Simulator.simulate(this.occurrences, this.bestMetrics.getTfmetrics());
+
         for (int i = 0; i < this.occurrences.size(); i++) {
             Occurrence occurrence = this.occurrences.get(i);
             Object returnValue = occurrence.getReturnValue();
@@ -114,7 +104,7 @@ public class GroupOfOccurrences {
         Thresholds.hitRatios.add(this.bestMetrics.getHitRatio());
         Thresholds.missRatios.add(this.bestMetrics.getMissRatio());
         Thresholds.shareabilities.add(this.bestMetrics.getShareability());
-        Thresholds.hitsPerTimeInCache.add(this.bestMetrics.getHitsPerTimeInCache());
+        Thresholds.savedTimePerTimeInCache.add(this.bestMetrics.getTfmetrics().getSavedTimePerTimeInCache());
     }
 
 }
diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java
index 480c262..af242b8 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java
@@ -7,12 +7,11 @@ package br.ufrgs.inf.prosoft.aplcachetf.extension.metadata;
 
 import br.ufrgs.inf.prosoft.aplcachetf.extension.metrics.CacheabilityPatternDecider;
 import br.ufrgs.inf.prosoft.tfcache.Metrics;
-import br.ufrgs.inf.prosoft.tfcache.Simulator;
+import br.ufrgs.inf.prosoft.tfcache.StorageManager;
+import br.ufrgs.inf.prosoft.tfcache.configuration.Configuration;
 import br.ufrgs.inf.prosoft.tfcache.metadata.Occurrence;
 import java.math.BigDecimal;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -50,28 +49,18 @@ public class Method {
     }
 
     public Metrics getBestMetrics() {
-        if (this.bestMetrics == null) {
-            throw new RuntimeException("hitsPerTimeInCache must be calculated");
-        }
         return this.bestMetrics;
     }
 
-    public Long getTtl() {
-        return getBestMetrics().getTtl();
-    }
-
-    public Long getSavedTime() {
-        return getBestMetrics().getSavedTime();
-    }
-
-    public BigDecimal getHitsPerTimeInCache() {
-        return getBestMetrics().getHitsPerTimeInCache();
+    public BigDecimal getEstimatedSavedTimePerTimeInCache() {
+        if (getBestMetrics() != null) {
+            return getBestMetrics().getSavedTimePerTimeInCache();
+        }
+        GroupOfOccurrences max = groupsOfOccurrences().max((group1, group2) -> group1.getSavedTimePerTimeInCache().compareTo(group2.getSavedTimePerTimeInCache())).get();
+        return max.getSavedTimePerTimeInCache();
     }
 
     public Stream<Occurrence> occurrences() {
-        if (this.occurrences == null) {
-            throw new RuntimeException("Occurrences already consumed");
-        }
         return this.occurrences.stream();
     }
 
@@ -83,19 +72,10 @@ public class Method {
     }
 
     public int getOccurrencesSize() {
-        if (this.occurrences == null) {
-            if (this.groupsOfOccurrences == null) {
-                throw new RuntimeException("groupsOfOccurrences is null");
-            }
-            return this.groupsOfOccurrences.stream().map(GroupOfOccurrences::getOccurrencesSize).reduce(Integer::sum).orElse(0);
-        }
         return this.occurrences.size();
     }
 
     private void groupByInput() {
-        if (this.occurrences == null) {
-            throw new RuntimeException("Occurrences already consumed");
-        }
         Map<String, List<Occurrence>> inputHasOccurrences = new ConcurrentHashMap<>();
         occurrences().forEach(occurrence -> {
             String parameters = occurrence.getParametersSerialised();
@@ -110,37 +90,6 @@ public class Method {
         this.groupsOfOccurrences = inputHasOccurrences.entrySet().stream()
                 .map(entry -> new GroupOfOccurrences(entry.getKey(), entry.getValue()))
                 .collect(Collectors.toList());
-        this.occurrences = null;
-    }
-
-    public void recommendTTL() {
-        if (this.bestMetrics != null) {
-            LOGGER.log(Level.WARNING, "HitsPerTimeInCache already calculated");
-        }
-        if (this.occurrences == null) {
-            throw new RuntimeException("groupByInputs called. Cannot proceed");
-        }
-        this.bestMetrics = new Metrics();
-        if (this.occurrences.size() < 2) {
-            return;
-        }
-
-        Collection<Long> ttlsOfInterest = new HashSet<>();
-        for (int hits = 1; hits < this.occurrences.size(); hits++) {
-            for (int shift = 0; shift < this.occurrences.size() - hits; shift++) {
-                long ttl = 0;
-                for (int k = shift + 1; k < shift + 1 + hits; k++) {
-                    ttl += this.occurrences.get(k).getStartTime() - this.occurrences.get(k - 1).getEndTime();
-                }
-                if (ttl > 0) {
-                    ttlsOfInterest.add(ttl);
-                }
-            }
-        }
-
-        ttlsOfInterest.stream().parallel().forEach(actualTTL -> {
-            Simulator.simulate(occurrences(), actualTTL, this.bestMetrics);
-        });
     }
 
     public void removeSingleOccurrences() {
@@ -160,12 +109,10 @@ public class Method {
             groupByInput();
         }
         groupsOfOccurrences().forEach(GroupOfOccurrences::calculateMetrics);
-        if (this.bestMetrics == null) {
-            long savedTime = groupsOfOccurrences().map(GroupOfOccurrences::getSavedTime).reduce(Long::sum).get();
-            GroupOfOccurrences max = groupsOfOccurrences().max((group1, group2) -> Long.compare(group1.getSavedTime(), group2.getSavedTime())).get();
-            long ttl = max.getTtl();
-            BigDecimal hitsPerTimeInCache = max.getHitsPerTimeInCache();
-            this.bestMetrics = new Metrics(ttl, savedTime, hitsPerTimeInCache);
+        String uuid = Configuration.getUUID().replace("level:input", "level:method");
+        Metrics metrics = StorageManager.get(uuid, this.occurrences);
+        if (this.bestMetrics == null && metrics != null) {
+            this.bestMetrics = metrics;
         }
     }
 
diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/CacheabilityMetrics.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/CacheabilityMetrics.java
index f508c10..cdd857c 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/CacheabilityMetrics.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/CacheabilityMetrics.java
@@ -7,7 +7,7 @@ public class CacheabilityMetrics {
     public static int K_STANDARD_DEVIATION = 0;
 
     public static boolean isStaticData(GroupOfOccurrences groupOfOccurrences) {
-        if (groupOfOccurrences.getBestMetrics().getHitsPerTimeInCache().compareTo(Thresholds.hitsPerTimeInCacheThreshold(K_STANDARD_DEVIATION)) < 0) {
+        if (groupOfOccurrences.getBestMetrics().getTfmetrics().getSavedTimePerTimeInCache().compareTo(Thresholds.savedTimePerTimeInCacheThreshold(K_STANDARD_DEVIATION)) < 0) {
             return false;
         }
         return groupOfOccurrences.getBestMetrics().getHitRatio() == 100.0;
@@ -22,7 +22,7 @@ public class CacheabilityMetrics {
     }
 
     public static boolean hasHighUsagePerCaching(GroupOfOccurrences groupOfOccurrences) {
-        return groupOfOccurrences.getBestMetrics().getHitsPerTimeInCache().compareTo(Thresholds.hitsPerTimeInCacheThreshold(K_STANDARD_DEVIATION)) >= 0;
+        return groupOfOccurrences.getBestMetrics().getTfmetrics().getSavedTimePerTimeInCache().compareTo(Thresholds.savedTimePerTimeInCacheThreshold(K_STANDARD_DEVIATION)) >= 0;
     }
 
     public static boolean hasLowUsagePerCaching(GroupOfOccurrences groupOfOccurrences) {
diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Metrics.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Metrics.java
index 78cc8d2..1e17c21 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Metrics.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Metrics.java
@@ -15,9 +15,10 @@ import java.util.Set;
  *
  * @author root
  */
-public class Metrics extends br.ufrgs.inf.prosoft.tfcache.Metrics {
+public class Metrics {
 //exactly same method calls
 
+    private final br.ufrgs.inf.prosoft.tfcache.Metrics tfmetrics;
     private long sameOccurrences;
 
     //number of same method calls with different return
@@ -33,6 +34,11 @@ public class Metrics extends br.ufrgs.inf.prosoft.tfcache.Metrics {
         sameOccurrencesExecutionTime = 0L;
         amountOfIdentifiedSameOccurences = 0L;
         uniqueUsers = new HashSet<>();
+        this.tfmetrics = new br.ufrgs.inf.prosoft.tfcache.Metrics();
+    }
+
+    public br.ufrgs.inf.prosoft.tfcache.Metrics getTfmetrics() {
+        return tfmetrics;
     }
 
     public void addSameOccurrence(Occurrence occurrence) {
diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Thresholds.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Thresholds.java
index ceba2bc..03eeca8 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Thresholds.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metrics/Thresholds.java
@@ -18,12 +18,12 @@ import java.util.List;
  */
 public class Thresholds {
 
-    public static BigDecimal averageHitsPerTimeInCache;
+    public static BigDecimal averageSavedTimePerTimeInCache;
 
     public static Double stdDevHitRatio;
     public static Double stdDevMissRatio;
     public static Double stdDevExecutionTimeRatio;
-    public static BigDecimal stdDevHitsPerTimeInCache;
+    public static BigDecimal stdDevSavedTimePerTimeInCache;
     public static Double stdDevShareability;
 
     public static long population;
@@ -32,15 +32,15 @@ public class Thresholds {
     public static final List<Double> missRatios = new ArrayList<>();
     public static final List<Long> executionTimes = new ArrayList<>();
     public static final List<Double> shareabilities = new ArrayList<>();
-    public static final List<BigDecimal> hitsPerTimeInCache = new ArrayList<>();
+    public static final List<BigDecimal> savedTimePerTimeInCache = new ArrayList<>();
 
     public static void reset() {
-        Thresholds.averageHitsPerTimeInCache = null;
+        Thresholds.averageSavedTimePerTimeInCache = null;
 
         Thresholds.stdDevHitRatio = null;
         Thresholds.stdDevMissRatio = null;
         Thresholds.stdDevExecutionTimeRatio = null;
-        Thresholds.stdDevHitsPerTimeInCache = null;
+        Thresholds.stdDevSavedTimePerTimeInCache = null;
         Thresholds.stdDevShareability = null;
 
         Thresholds.population = 0;
@@ -49,7 +49,7 @@ public class Thresholds {
         Thresholds.missRatios.clear();
         Thresholds.executionTimes.clear();
         Thresholds.shareabilities.clear();
-        Thresholds.hitsPerTimeInCache.clear();
+        Thresholds.savedTimePerTimeInCache.clear();
     }
 
     /**
@@ -135,21 +135,21 @@ public class Thresholds {
         return stdDevExecutionTimeRatio;
     }
 
-    public static BigDecimal getStdDevHitsPerTimeInCache() {
+    public static BigDecimal getStdDevSavedTimePerTimeInCache() {
         if (population == 0) {
             return new BigDecimal(BigInteger.ZERO);
         }
-        if (stdDevHitsPerTimeInCache != null) {
-            return stdDevHitsPerTimeInCache;
+        if (stdDevSavedTimePerTimeInCache != null) {
+            return stdDevSavedTimePerTimeInCache;
         }
 
-        BigDecimal mean = getAverageHitsPerTimeInCache();
-        BigDecimal temp = hitsPerTimeInCache.stream()
+        BigDecimal mean = getAverageSavedTimePerTimeInCache();
+        BigDecimal temp = savedTimePerTimeInCache.stream()
                 .map(frequency -> frequency.subtract(mean).multiply(frequency.subtract(mean)))
                 .reduce(BigDecimal::add)
                 .orElse(new BigDecimal(BigInteger.ZERO));
-        stdDevHitsPerTimeInCache = temp.divide(new BigDecimal(population), MathContext.DECIMAL128).sqrt(MathContext.DECIMAL128);
-        return stdDevHitsPerTimeInCache;
+        stdDevSavedTimePerTimeInCache = temp.divide(new BigDecimal(population), MathContext.DECIMAL128).sqrt(MathContext.DECIMAL128);
+        return stdDevSavedTimePerTimeInCache;
     }
 
     public static double getStdDevShareability() {
@@ -169,17 +169,17 @@ public class Thresholds {
         return stdDevShareability;
     }
 
-    public static BigDecimal getAverageHitsPerTimeInCache() {
-        if (hitsPerTimeInCache.isEmpty()) {
+    public static BigDecimal getAverageSavedTimePerTimeInCache() {
+        if (savedTimePerTimeInCache.isEmpty()) {
             return new BigDecimal(BigInteger.ZERO);
         }
-        if (averageHitsPerTimeInCache != null) {
-            return averageHitsPerTimeInCache;
+        if (averageSavedTimePerTimeInCache != null) {
+            return averageSavedTimePerTimeInCache;
         }
 
-        averageHitsPerTimeInCache = hitsPerTimeInCache.stream().reduce(BigDecimal::add).orElse(new BigDecimal(BigInteger.ZERO))
-                .divide(new BigDecimal(hitsPerTimeInCache.size()), MathContext.DECIMAL128);
-        return averageHitsPerTimeInCache;
+        averageSavedTimePerTimeInCache = savedTimePerTimeInCache.stream().reduce(BigDecimal::add).orElse(new BigDecimal(BigInteger.ZERO))
+                .divide(new BigDecimal(savedTimePerTimeInCache.size()), MathContext.DECIMAL128);
+        return averageSavedTimePerTimeInCache;
     }
 
 //getting X% with most hits
@@ -202,8 +202,8 @@ public class Thresholds {
     }
 
 //getting X% most frenquent
-    public static BigDecimal hitsPerTimeInCacheThreshold(int kStdDev) {
-        return getAverageHitsPerTimeInCache().add(getStdDevHitsPerTimeInCache().multiply(new BigDecimal(kStdDev)));
+    public static BigDecimal savedTimePerTimeInCacheThreshold(int kStdDev) {
+        return getAverageSavedTimePerTimeInCache().add(getStdDevSavedTimePerTimeInCache().multiply(new BigDecimal(kStdDev)));
     }
 
 }
diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/Main.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/Main.java
index 3193e94..6ec6242 100755
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/Main.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/Main.java
@@ -8,14 +8,15 @@ package br.ufrgs.inf.prosoft.aplcachetf;
 import br.ufrgs.inf.prosoft.aplcachetf.adapter.TraceReader;
 import br.ufrgs.inf.prosoft.aplcachetf.extension.APLCache;
 import br.ufrgs.inf.prosoft.aplcachetf.extension.metadata.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;
 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;
 
 /**
  *
@@ -29,22 +30,11 @@ public class Main {
         System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT+%1$tL] [%4$-7s] [APLCacheTF] %5$s %n");
 
         if (args.length < 2) {
-            System.err.println("--trace=<TracePath> --output=<OutputPath> [--mode=<complete|hashed|partial>] [--k=<kStandardDeviation>] [--window=<windowSize>] [--shift=<shiftTime>]");
+            System.err.println("--trace=<TracePath> --output=<OutputPath> [--tfstore=<storePath>] [--tfkernel=<exhaustive|optimised>] [--tfstaleness=<ignore|shrink>] [--mode=<complete|hashed|partial>] [--k=<kStandardDeviation>] [--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) {
@@ -91,7 +81,13 @@ public class Main {
         List<Method> methods = TraceReader.groupByMethods(traces);
         LOGGER.log(Level.INFO, "grouped traces into {0} methods", methods.size());
 
+        Configuration.setLevel("input");
+        Configuration.setKernel(arguments.get("tfkernel"));
+        Configuration.setStaleness(arguments.get("tfstaleness"));
+        Configuration.setStore(arguments.get("tfstore"));
+        StorageManager.load();
         APLCache aplcache = new APLCache(methods);
         aplcache.recommend(k, outputPath);
+        StorageManager.update();
     }
 }