diff --git a/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Main.java b/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Main.java
index 3494f84..b43ccaa 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Main.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Main.java
@@ -89,7 +89,6 @@ public class Main {
memoizeIt.setCallGraph(graph);
memoizeIt.setMethods(methods);
memoizeIt.run(kernel.equals("iterative"), true);
- methods.forEach(System.out::println);
System.exit(0);
}
}
diff --git a/src/main/java/br/ufrgs/inf/prosoft/memoizeit/MemoizeIt.java b/src/main/java/br/ufrgs/inf/prosoft/memoizeit/MemoizeIt.java
index e6e3ee3..c311e1a 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/memoizeit/MemoizeIt.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/memoizeit/MemoizeIt.java
@@ -89,16 +89,7 @@ public class MemoizeIt {
// 3.1 time and frequency profiling
private void filterInitialCandidates() {
LOGGER.log(Level.INFO, "Fitering {0} initial candidates by frequency and average execution time", this.methods.size());
- int i = 0;
- while (i < this.methods.size()) {
- Method method = this.methods.get(i);
- double averageExecutionTime = method.getAverageExecutionTime();
- if (method.getOccurrencesSize() < this.minimumMethodCalls || averageExecutionTime < this.minimumExecutionTime) {
- this.methods.remove(method);
- continue;
- }
- i++;
- }
+ this.methods.removeIf(method -> method.getOccurrencesSize() < this.minimumMethodCalls || method.getAverageExecutionTime() < this.minimumExecutionTime);
LOGGER.log(Level.INFO, "Calculating representativity of {0} methods", this.methods.size());
Collection<Node<String>> roots = this.callGraph.getRoots();
roots.stream().forEach(root -> {
@@ -130,23 +121,14 @@ public class MemoizeIt {
});
});
- roots = null;
this.methods.stream().filter(method -> method.getRepresentativeness() == 0)
.forEach(method -> method.setRepresentativeness(1));
LOGGER.log(Level.INFO, "Fitering {0} candidates by representativeness", this.methods.size());
- i = 0;
- while (i < this.methods.size()) {
- Method method = this.methods.get(i);
- if (method.getRepresentativeness() < this.minimumRelativeTime) {
- this.methods.remove(method);
- continue;
- }
- i++;
- }
+ this.methods.removeIf(method -> method.getRepresentativeness() < this.minimumRelativeTime);
}
private void removeUnusedFields() {
- LOGGER.log(Level.INFO, "Removing unused fields of {0} candidates left", this.methods.size());
+ LOGGER.log(Level.INFO, "Removing unused fields from {0} methods", this.methods.size());
this.methods.forEach(method -> method.removeUnusedFields(this.callGraph.getNode(method.getName())));
}
@@ -288,8 +270,10 @@ public class MemoizeIt {
for (int i = 0; i < clusters.size(); i++) {
Collection<Method> cluster = clusters.get(i);
System.out.println("Cluster#" + i);
- cluster.forEach(System.out::println);
- System.out.println();
+ cluster.forEach(method -> {
+ System.out.println("\t" + method.getName());
+ suggestImplementation(method);
+ });
}
}
@@ -304,6 +288,7 @@ public class MemoizeIt {
CachePerformance instanceMultiCachePerformance = cachingStrategyHasPerformance.get("instanceMultiCache");
CachePerformance instanceSingleCachePerformance = cachingStrategyHasPerformance.get("instanceSingleCache");
StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append("\t");
stringBuilder.append("GS: ");
stringBuilder.append("R").append(globalSingleCachePerformance.getRoundedHitRatio());
stringBuilder.append(" * ").append(globalSingleCachePerformance);
@@ -318,25 +303,27 @@ public class MemoizeIt {
stringBuilder.append(" * ").append(instanceMultiCachePerformance);
System.out.println(stringBuilder);
if (globalSingleCachePerformance.getRoundedHitRatio() >= 50) {
- System.out.println("single, global");
+ System.out.println("\tsingle, global");
} else if (instanceSingleCachePerformance.getRoundedHitRatio() >= 50) {
- System.out.println("single, instance");
+ System.out.println("\tsingle, instance");
} else if (globalMultiCachePerformance.getRoundedHitRatio() >= 50) {
- System.out.println("multi, global");
+ System.out.println("\tmulti, global");
} else if (instanceMultiCachePerformance.getRoundedHitRatio() >= 50) {
- System.out.println("multi, instance");
+ System.out.println("\tmulti, instance");
} else {
- System.out.println("none");
+ System.out.println("\tnone");
}
}
// 3.4 suggest cache implementation
- private void suggestImplementations() {
+ public void suggestImplementations() {
+ if (this.methods == null || this.methods.isEmpty()) {
+ throw new RuntimeException("Empty execution traces");
+ }
LOGGER.log(Level.INFO, "Suggesting caching implementation");
this.methods.forEach(method -> {
System.out.println(method.getName());
suggestImplementation(method);
- System.out.println();
});
}
@@ -353,7 +340,7 @@ public class MemoizeIt {
}
filterInitialCandidates();
removeUnusedFields();
- refineCandidates(true);
+ refineCandidates(iteratively);
}
public void suggestCachingImplementations() {
@@ -368,7 +355,6 @@ public class MemoizeIt {
throw new RuntimeException("Call Graph not set");
}
printClusters(shouldRank);
- suggestImplementations();
}
public void run() {
@@ -385,6 +371,5 @@ public class MemoizeIt {
filterInitialCandidates();
refineCandidates(iteratively);
printClusters(shouldRank);
- suggestImplementations();
}
}
diff --git a/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Method.java b/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Method.java
index 0a2dd53..da697d7 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Method.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/memoizeit/Method.java
@@ -79,7 +79,7 @@ public class Method {
}
protected void groupByParameter(int depth) {
- LOGGER.log(Level.INFO, "Grouping by parameters {0} occurrences of {1}", new Object[]{this.name, this.occurrences.size()});
+ LOGGER.log(Level.FINE, "\tGrouping by parameters {0} occurrences of {1}", new Object[]{this.name, this.occurrences.size()});
this.groupByParameter = new HashMap<>();
this.occurrences.stream().parallel().forEach(new Consumer<Occurrence>() {
int i = 0;
@@ -140,7 +140,7 @@ public class Method {
}
protected void removeUnusedFields(Node<String> methodNode) {
- LOGGER.log(Level.INFO, "Removing unused fields of {0} occurrences of {1}", new Object[]{this.occurrences.size(), this.name});
+ LOGGER.log(Level.FINE, "\tRemoving unused fields of {0} occurrences of {1}", new Object[]{this.occurrences.size(), this.name});
if (methodNode == null) {
LOGGER.log(Level.WARNING, "methodNode null: {0}", this.name);
return;
@@ -161,7 +161,6 @@ public class Method {
occurrence.removeUnusedFields(methodNode);
}
});
- System.out.println();
}
protected Map<String, CachePerformance> simulateCachingStrategies() {