Skip to content

Commit

Permalink
adds calculation of total energy and runtime to energy log
Browse files Browse the repository at this point in the history
  • Loading branch information
vsee committed Mar 2, 2017
1 parent 5fa4037 commit 6a9b0c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<String>> 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<List<String>> getLogRecords() { return logRecords; }

public double getEnergyJ() { return energyJ; }
public double getRuntimeMS() { return runtimeMS; }

private List<List<String>> parseLogFile(Path logFile) {
if (!logFile.toFile().exists() ||
Expand Down Expand Up @@ -61,4 +72,16 @@ private void checkHeader(Path logFile) {
throw new RuntimeException("Unexpected header format in log file: " + join);
}


private void calculateStatistics(List<List<String>> records) {

runtimeMS = 0;
energyJ = 0;

for (List<String> 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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,11 +52,9 @@ public void display(Hashtable<ServerConnection, ExecutionItem> executionMap, Use

if(br.hasEnergyLog()) {
System.out.println("### Energy Log:");
List<List<String>> elogRecords = br.getEnergyLog().getLogRecords();
System.out.println(elogRecords.size() + " log entries found.");
for (List<String> 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;
Expand Down

0 comments on commit 6a9b0c7

Please sign in to comment.