Main.java
Home
/
src /
main /
java /
br /
ufrgs /
inf /
prosoft /
memoizeittf /
Main.java
package br.ufrgs.inf.prosoft.memoizeittf;
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;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
public static void main(String[] args) {
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>" +
" [--tfstore=<storePath>]" +
" [--tfkernel=<exhaustive|optimised>]" +
" [--mode=<complete|hashed|partial>]" +
" [--kernel=<iterative|exhaustive>]" +
" [--objetive=(savedTime)0..1,0..1(idleTime)]" +
" [--window=<windowSize>]" +
" [--shift=<shiftTime>]");
System.exit(1);
}
Map<String, String> arguments = Arguments.parse(args);
String tracePath = arguments.get("trace");
if (tracePath == null) {
System.err.println("<TracePath> is required");
System.exit(1);
}
String callGraphPath = arguments.get("callgraph");
if (callGraphPath == null) {
System.err.println("<CallGraphPath> is required");
System.exit(1);
}
String mode = arguments.get("mode");
if (mode == null) {
mode = "complete";
LOGGER.info(MessageFormat.format("Using default mode: {0}", mode));
}
String kernel = arguments.get("kernel");
if (kernel == null) {
kernel = "exhaustive";
LOGGER.info(MessageFormat.format("Using default kernel: {0}", kernel));
}
Long window = null;
try {
window = Long.valueOf(arguments.get("window"));
} catch (NumberFormatException ignored) {
}
Long shift = null;
try {
shift = Long.valueOf(arguments.get("shift"));
} catch (NumberFormatException ignored) {
}
LOGGER.info("Reading callgraph");
Graph<String> graph = CallGraphReader.parseFile(callGraphPath);
LOGGER.info("Reading traces");
List<Trace> traces = TraceReader.parseFile(tracePath, Mode.valueOf(mode.toUpperCase()), window, shift);
LOGGER.info(MessageFormat.format("Grouping {0} traces by methods", traces.size()));
List<Method> methods = TraceReader.groupByMethods(traces);
LOGGER.info(MessageFormat.format("grouped traces into {0} methods", methods.size()));
Configuration.setLevel("method");
Configuration.setKernel(arguments.get("tfkernel"));
Configuration.setStaleness("ignore");
Configuration.setStore(arguments.get("tfstore"));
Configuration.setInput(Arrays.stream(tracePath.split("/")).reduce((a, b) -> b).orElse(""));
Configuration.setPreferences(arguments.get("objective"));
StorageManager.load();
MemoizeItTF memoizeItTF = new MemoizeItTF(methods, graph);
memoizeItTF.recommend(kernel.equals("iterative"));
StorageManager.update();
}
}