diff --git a/src/main/java/lancs/dividend/oclBenchMapper/energy/EnergyLog.java b/src/main/java/lancs/dividend/oclBenchMapper/energy/EnergyLog.java index 433f5a0..f2f337e 100644 --- a/src/main/java/lancs/dividend/oclBenchMapper/energy/EnergyLog.java +++ b/src/main/java/lancs/dividend/oclBenchMapper/energy/EnergyLog.java @@ -15,19 +15,30 @@ public class EnergyLog implements Serializable { private static final char SEPARATOR = ';'; private static final String EXPECTED_HEADER = "Status;Event;Command;Issue;Start;Stop;Workload;Energy;Name"; + private static final int HEADER_ISSUE_IDX = 3; + private static final int HEADER_STOP_IDX = 5; + private static final int HEADER_ENERGY_IDX = 7; private static final int HEADER_SKIP = 2; private final List> logRecords; + private double energyJ; + private double runtimeMS; + public EnergyLog(Path logFile) { if (logFile == null) throw new IllegalArgumentException("Given log file path must not be null."); logRecords = parseLogFile(logFile); + + calculateStatistics(logRecords); } - + public List> getLogRecords() { return logRecords; } + + public double getEnergyJ() { return energyJ; } + public double getRuntimeMS() { return runtimeMS; } private List> parseLogFile(Path logFile) { if (!logFile.toFile().exists() || @@ -61,4 +72,16 @@ private void checkHeader(Path logFile) { throw new RuntimeException("Unexpected header format in log file: " + join); } + + private void calculateStatistics(List> records) { + + runtimeMS = 0; + energyJ = 0; + + for (List rec : records) { + energyJ += Double.parseDouble(rec.get(HEADER_ENERGY_IDX)); + runtimeMS += (Double.parseDouble(rec.get(HEADER_STOP_IDX)) - + Double.parseDouble(rec.get(HEADER_ISSUE_IDX))) / 1000000; + } + } } diff --git a/src/main/java/lancs/dividend/oclBenchMapper/resultDisplay/SimpleConsoleDisplay.java b/src/main/java/lancs/dividend/oclBenchMapper/resultDisplay/SimpleConsoleDisplay.java index c12d917..1301b74 100644 --- a/src/main/java/lancs/dividend/oclBenchMapper/resultDisplay/SimpleConsoleDisplay.java +++ b/src/main/java/lancs/dividend/oclBenchMapper/resultDisplay/SimpleConsoleDisplay.java @@ -1,7 +1,6 @@ package lancs.dividend.oclBenchMapper.resultDisplay; import java.util.Hashtable; -import java.util.List; import lancs.dividend.oclBenchMapper.connection.ServerConnection; import lancs.dividend.oclBenchMapper.mapping.ExecutionItem; @@ -53,11 +52,9 @@ public void display(Hashtable executionMap, Use if(br.hasEnergyLog()) { System.out.println("### Energy Log:"); - List> elogRecords = br.getEnergyLog().getLogRecords(); - System.out.println(elogRecords.size() + " log entries found."); - for (List rec : elogRecords) { - System.out.println(rec); - } + System.out.println(br.getEnergyLog().getLogRecords().size() + " log entries found."); + System.out.println("### Energy: " + br.getEnergyLog().getEnergyJ() + " J"); + System.out.println("### Runtime: " + br.getEnergyLog().getRuntimeMS() + " ms"); } break;