FlowchartWorkFlow.java
Home
/
src /
main /
java /
br /
ufrgs /
inf /
prosoft /
aplcache /
flowchart /
FlowchartWorkFlow.java
package br.ufrgs.inf.prosoft.aplcache.flowchart;
import br.ufrgs.inf.prosoft.aplcache.flowchart.metrics.CacheabilityMetrics;
import br.ufrgs.inf.prosoft.aplcache.flowchart.metrics.Thresholds;
import br.ufrgs.inf.prosoft.aplcache.metadata.Method;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public final class FlowchartWorkFlow {
private static final Logger LOGGER = Logger.getLogger(FlowchartWorkFlow.class.getName());
private List<Method> methods;
public FlowchartWorkFlow setMethods(List<Method> methods) {
this.methods = methods;
return this;
}
private void countStats() {
LOGGER.log(Level.INFO, "Counting stats of {0} methods", this.methods.size());
Collections.sort(this.methods, (m1, m2) -> Integer.compare(m1.getOccurrencesSize(), m2.getOccurrencesSize()));
this.methods.stream().parallel().forEach(Method::calculateMetrics);
}
private void calculateThresholds(int kStdDev) {
LOGGER.log(Level.INFO, "Calculating thresholds");
Thresholds.reset();
Thresholds.population = getPopulation();
this.methods.stream().forEach(Method::calculateThresholds);
LOGGER.log(Level.INFO, "Average ExecutionTime: {0}", Thresholds.getAverageExecutionTime());
LOGGER.log(Level.INFO, "Average HitRatio: {0}", Thresholds.getAverageHitRatio());
LOGGER.log(Level.INFO, "Average MissRatio: {0}", Thresholds.getAverageMissRatio());
LOGGER.log(Level.INFO, "Average shareability: {0}", Thresholds.getAverageShareability());
LOGGER.log(Level.INFO, "StdDv ExecutionTime: {0}", Thresholds.getStdDevExecutionTimeRatio());
LOGGER.log(Level.INFO, "StdDv HitRatio: {0}", Thresholds.getStdDevHitRatio());
LOGGER.log(Level.INFO, "StdDv MissRatio: {0}", Thresholds.getStdDevMissRatio());
LOGGER.log(Level.INFO, "StdDv shareability: {0}", Thresholds.getStdDevShareability());
LOGGER.log(Level.INFO, "StdDv frequency: {0}", Thresholds.getStdDevFrequency());
LOGGER.log(Level.INFO, "Using {0} stdDev to calculate thresholds...", kStdDev);
LOGGER.log(Level.INFO, "Threshold ExecutionTime: {0}", Thresholds.expensivenessThreshold(kStdDev));
LOGGER.log(Level.INFO, "Threshold HitRatio: {0}", Thresholds.hitThreshold(kStdDev));
LOGGER.log(Level.INFO, "Threshold MissRatio: {0}", Thresholds.missThreshold(kStdDev));
LOGGER.log(Level.INFO, "Threshold Shareability: {0}", Thresholds.shareabilityThreshold(kStdDev));
LOGGER.log(Level.INFO, "Threshold frequency: {0}", Thresholds.frequencyThreshold(kStdDev));
}
public void filterCacheableInputs() {
filterCacheableInputs(0);
}
public void filterCacheableInputs(int kStdDev) {
countStats();
calculateThresholds(kStdDev);
LOGGER.log(Level.INFO, "Deciding if methods are cacheable...");
CacheabilityMetrics.K_STANDARD_DEVIATION = kStdDev;
Iterator<Method> iterator = this.methods.iterator();
while (iterator.hasNext()) {
Method method = iterator.next();
method.filterCacheableInputs();
if (method.getGroupsOfOccurrences().isEmpty()) {
iterator.remove();
}
}
LOGGER.log(Level.INFO, "{0} cacheable methods detected", this.methods.size());
}
private long getPopulation() {
return this.methods.stream().parallel()
.map(Method::getOccurrencesSize)
.reduce(Integer::sum)
.get();
}
}