Main.java

90 lines | 3.442 kB Blame History Raw Download
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
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.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author romulo
 */
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>] [--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.log(Level.INFO, "Using default mode: {0}", mode);
        }
        String kernel = arguments.get("kernel");
        if (kernel == null) {
            kernel = "exhaustive";
            LOGGER.log(Level.INFO, "Using default kernel: {0}", kernel);
        }

        Long window = null;
        try {
            window = Long.valueOf(arguments.get("window"));
        } catch (NumberFormatException ex) {
        }
        Long shift = null;
        try {
            shift = Long.valueOf(arguments.get("shift"));
        } catch (NumberFormatException ex) {
        }

        LOGGER.log(Level.INFO, "Reading callgraph");
        Graph<String> graph = CallGraphReader.parseFile(callGraphPath);
        LOGGER.log(Level.INFO, "Reading traces");
        List<Trace> traces = TraceReader.parseFile(tracePath, Mode.valueOf(mode.toUpperCase()), window, shift);
        LOGGER.log(Level.INFO, "Grouping {0} traces by methods", traces.size());
        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();
    }
}