ResultLogger.java 8.26 KB
Newer Older
1 2
package mvd.jester;

3
import java.util.Map;
4
import java.util.Set;
5
import java.util.Map.Entry;
6
import mvd.jester.model.Task;
7 8 9 10 11 12 13 14
import mvd.jester.tests.AbstractTest;
import mvd.jester.utils.Logger;

/**
 * ResultCollector
 */
public class ResultLogger {

15
    private final Logger logger;
16

Michael Schmid committed
17 18
    public ResultLogger(final String fileName) {
        this.logger = new Logger("./results/" + fileName + ".txt");
19 20
    }

Michael Schmid committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    public <T extends Task> void logHeader(final Map<AbstractTest<T>, Long> results,
            String xAxisName) {
        final Appendable out = new StringBuilder();
        try {
            out.append(xAxisName);
            for (final Entry<AbstractTest<T>, 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);
    }


37 38 39 40 41 42 43 44 45 46 47
    public <T extends Task> void logLine(final double utilization,
            final Map<AbstractTest<T>, Long> results) {
        final Appendable out = new StringBuilder();
        try {
            out.append("" + utilization);
            for (final Entry<AbstractTest<T>, Long> rc : results.entrySet()) {
                final long numberOfFeasibleTasks = rc.getValue();
                out.append("\t" + numberOfFeasibleTasks);
            }
        } catch (final Exception e) {
            throw new RuntimeException("Failed to log line!");
48
        }
49
        logger.log(out);
50 51
    }

52 53 54 55 56 57
    public void newLine() {
        final Appendable out = new StringBuilder();
        try {
            out.append("\n");
        } catch (final Exception e) {
            throw new RuntimeException("Failed to log line!");
58
        }
59
        logger.log(out);
60 61
    }

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    // public <T extends Task> void logAll(Set<ResultCollector<AbstractTest<T>>> testResults,
    // Set<ResultCollector<AbstractSimulator>> simResults) {
    // logTests(testResults);
    // logSimulations(simResults);
    // }

    // public <T extends Task> void logTests(Set<ResultCollector<AbstractTest<T>>> results) {
    // if (!results.isEmpty()) {
    // logFeasibility(results, "test");
    // }
    // }

    // public void logSimulations(Set<ResultCollector<AbstractSimulator>> results) {
    // if (!results.isEmpty()) {
    // logFeasibility(results, "sim");
    // logTaskRatio(results, "sim");
    // }
    // }
80

81 82 83

    public <T extends TypeInterface> void logFeasibilityLevel(final Set<ResultCollector<T>> results,
            final String type) {
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
        // LocalTime date = LocalTime.now();
        // Logger log = new Logger("./results/feasibility_level_" + type + "_" + numberOfProcessors
        // + "_" + date.getHour() + ":" + date.getMinute() + ".txt");

        // Table<Long, ResultCollector<T>, Double> resultTable = TreeBasedTable.create();
        // Set<ResultCollector<T>> resultCollectors = new TreeSet<>();

        // for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) {
        // for (ResultCollector<T> rc : results) {
        // resultCollectors.add(rc);
        // final long local_util = util;

        // Supplier<Stream<SchedulingInfo>> 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");
112 113 114 115
    }



116 117 118 119 120
    // public <T extends TypeInterface> void logFeasibility(Set<ResultCollector<T>> results,
    // String type) {
    // LocalTime date = LocalTime.now();
    // Logger log = new Logger("./results/feasibility_" + type + "_" + numberOfProcessors + "_"
    // + date.getHour() + ":" + date.getMinute() + ".txt");
121

122 123
    // Table<Double, ResultCollector<T>, Long> resultTable = TreeBasedTable.create();
    // Set<ResultCollector<T>> resultCollectors = new TreeSet<>();
124

125 126 127 128 129 130 131 132 133 134
    // for (double util = 0.25; util <= numberOfProcessors; util += 0.25) {
    // for (ResultCollector<T> 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);
    // }
    // }
135

136 137
    // logData(log, resultTable, resultCollectors, "Utilization");
    // }
138

139 140
    public <T extends TypeInterface> void logFeasibilityRatio(final Set<ResultCollector<T>> results,
            final String type) {
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        // LocalTime date = LocalTime.now();
        // Logger log = new Logger("./results/feasibility_ratio_" + type + "_" + numberOfProcessors
        // + "_" + date.getHour() + ":" + date.getMinute() + ".txt");

        // Table<Long, ResultCollector<T>, Double> resultTable = TreeBasedTable.create();
        // Set<ResultCollector<T>> resultCollectors = new TreeSet<>();

        // for (long util = 0; util <= numberOfProcessors * 10; util += numberOfProcessors / 4) {
        // for (ResultCollector<T> rc : results) {
        // resultCollectors.add(rc);
        // final long local_util = util;
        // Supplier<Stream<SchedulingInfo>> 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");
167 168
    }

169 170
    public <T extends TypeInterface> void logTaskRatio(final Set<ResultCollector<T>> results,
            final String type) {
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
        // LocalTime date = LocalTime.now();
        // Logger log = new Logger("./results/task_ratio_" + type + "_" + numberOfProcessors + "_"
        // + date.getHour() + ":" + date.getMinute() + ".txt");

        // Table<Long, ResultCollector<T>, Long> resultTable = TreeBasedTable.create();
        // Set<ResultCollector<T>> resultCollectors = new TreeSet<>();

        // for (long ratio = 0; ratio <= 10; ratio += 1) {
        // for (ResultCollector<T> 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");
190 191
    }

192 193
    public void finalize() {
        logger.finalize();
194
    }
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216

    // private <T extends TypeInterface> void logData(Logger log,
    // Table<Double, ResultCollector<T>, ? extends Number> resultTable,
    // Set<ResultCollector<T>> resultCollectors, String xDataName) {
    // final Appendable out = new StringBuilder();
    // try {
    // String[] resultCollectorNames = resultCollectors.stream()
    // .map(ResultCollector<T>::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();
    // }
217
}