package mvd.jester; import java.util.Map; import java.util.Set; import java.util.Map.Entry; import mvd.jester.model.Task; import mvd.jester.tests.AbstractTest; import mvd.jester.utils.Logger; /** * ResultCollector */ public class ResultLogger { private final Logger logger; public ResultLogger(final String fileName) { this.logger = new Logger("./results/" + fileName + ".txt"); } public void logHeader(final Map, Long> results, String xAxisName) { final Appendable out = new StringBuilder(); try { out.append(xAxisName); for (final Entry, Long> rc : results.entrySet()) { out.append("\t" + rc.getKey().getName()); } out.append("\n"); } catch (final Exception e) { throw new RuntimeException("Failed to log header!"); } logger.log(out); } public void logLine(final double utilization, final Map, Long> results) { final Appendable out = new StringBuilder(); try { out.append("" + utilization); for (final Entry, Long> rc : results.entrySet()) { final long numberOfFeasibleTasks = rc.getValue(); out.append("\t" + numberOfFeasibleTasks); } } catch (final Exception e) { throw new RuntimeException("Failed to log line!"); } logger.log(out); } public void newLine() { final Appendable out = new StringBuilder(); try { out.append("\n"); } catch (final Exception e) { throw new RuntimeException("Failed to log line!"); } logger.log(out); } // public void logAll(Set>> testResults, // Set> simResults) { // logTests(testResults); // logSimulations(simResults); // } // public void logTests(Set>> results) { // if (!results.isEmpty()) { // logFeasibility(results, "test"); // } // } // public void logSimulations(Set> results) { // if (!results.isEmpty()) { // logFeasibility(results, "sim"); // logTaskRatio(results, "sim"); // } // } public void logFeasibilityLevel(final Set> results, final String type) { // LocalTime date = LocalTime.now(); // Logger log = new Logger("./results/feasibility_level_" + type + "_" + numberOfProcessors // + "_" + date.getHour() + ":" + date.getMinute() + ".txt"); // Table, Double> resultTable = TreeBasedTable.create(); // Set> resultCollectors = new TreeSet<>(); // for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) { // for (ResultCollector rc : results) { // resultCollectors.add(rc); // final long local_util = util; // Supplier> schedulingResults = () -> rc.getResults().stream() // .filter(r -> Math.round(r.getUtilization() * 10 / (numberOfProcessors / 4)) // * (numberOfProcessors / 4) == local_util); // if (schedulingResults.get().filter(r -> !r.checkTasksetFeasible()).count() > 0) { // double feasibleTasksets = (double) schedulingResults.get() // .filter(r -> r.checkLevelFail(Level.HIGH)).count() // / schedulingResults.get().filter(r -> !r.checkTasksetFeasible()) // .count(); // resultTable.put(util, rc, feasibleTasksets); // } else { // resultTable.put(util, rc, 0.); // } // } // } // logData(log, resultTable, resultCollectors, "Utilization"); } // public void logFeasibility(Set> results, // String type) { // LocalTime date = LocalTime.now(); // Logger log = new Logger("./results/feasibility_" + type + "_" + numberOfProcessors + "_" // + date.getHour() + ":" + date.getMinute() + ".txt"); // Table, Long> resultTable = TreeBasedTable.create(); // Set> resultCollectors = new TreeSet<>(); // for (double util = 0.25; util <= numberOfProcessors; util += 0.25) { // for (ResultCollector rc : results) { // resultCollectors.add(rc); // final double local_util = util; // long feasibleTasksets = rc.getResults().stream() // .filter(r -> DoubleMath.fuzzyEquals(r.getUtilization(), local_util, 0.125)) // .filter(r -> r.checkTasksetFeasible()).count(); // resultTable.put(util, rc, feasibleTasksets); // } // } // logData(log, resultTable, resultCollectors, "Utilization"); // } public void logFeasibilityRatio(final Set> results, final String type) { // LocalTime date = LocalTime.now(); // Logger log = new Logger("./results/feasibility_ratio_" + type + "_" + numberOfProcessors // + "_" + date.getHour() + ":" + date.getMinute() + ".txt"); // Table, Double> resultTable = TreeBasedTable.create(); // Set> resultCollectors = new TreeSet<>(); // for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) { // for (ResultCollector rc : results) { // resultCollectors.add(rc); // final long local_util = util; // Supplier> schedulingResults = () -> rc.getResults().stream() // .filter(r -> Math.round(r.getUtilization() * 10 / (numberOfProcessors / 4)) // * (numberOfProcessors / 4) == local_util); // if (schedulingResults.get().count() > 0) { // double feasibleTasksets = // (double) schedulingResults.get().filter(r -> r.checkTasksetFeasible()) // .count() / schedulingResults.get().count(); // resultTable.put(util, rc, feasibleTasksets); // } else { // resultTable.put(util, rc, 1.); // } // } // } // logData(log, resultTable, resultCollectors, "Utilization"); } public void logTaskRatio(final Set> results, final String type) { // LocalTime date = LocalTime.now(); // Logger log = new Logger("./results/task_ratio_" + type + "_" + numberOfProcessors + "_" // + date.getHour() + ":" + date.getMinute() + ".txt"); // Table, Long> resultTable = TreeBasedTable.create(); // Set> resultCollectors = new TreeSet<>(); // for (long ratio = 0; ratio <= 10; ratio += 1) { // for (ResultCollector rc : results) { // resultCollectors.add(rc); // final long local_ratio = ratio; // long feasibleTasksets = rc.getResults().stream() // .filter(r -> Math.ceil(r.getParallelTaskRatio() * 10) == local_ratio) // .filter(r -> r.checkTasksetFeasible()).count(); // resultTable.put(ratio, rc, feasibleTasksets); // } // } // logData(log, resultTable, resultCollectors, "TaskRatio"); } public void finalize() { logger.finalize(); } // private void logData(Logger log, // Table, ? extends Number> resultTable, // Set> resultCollectors, String xDataName) { // final Appendable out = new StringBuilder(); // try { // String[] resultCollectorNames = resultCollectors.stream() // .map(ResultCollector::getName).toArray(String[]::new); // String[] header = ObjectArrays.concat(xDataName, resultCollectorNames); // final CSVPrinter printer = CSVFormat.DEFAULT.withHeader(header).print(out); // printer.printRecords(resultTable.rowMap().entrySet().stream() // .map(entry -> ImmutableList.builder().add((double) entry.getKey()) // .addAll(entry.getValue().values()).build()) // .collect(Collectors.toList())); // } catch (final IOException e) { // e.printStackTrace(); // } // log.log(out); // log.finalize(); // } }