1 package at.ac.tuwien.lsdc.util;
4 import java.io.FileWriter;
5 import java.io.IOException;
7 import at.ac.tuwien.lsdc.types.ScenarioData;
8 import at.ac.tuwien.lsdc.types.SchedulerData;
9 import au.com.bytecode.opencsv.CSVWriter;
11 public class CSVLogger {
13 public static void logScenarioData(File file, ScenarioData data)
15 if (file.length() == 0) {
16 writeScenarioDataHeader(file);
18 appendCSVLine(file,data.toStringArray());
21 public static void logSchedulerData(File file, SchedulerData data)
23 if (file.length() == 0) {
24 writeSchedulerDataHeader(file);
26 appendCSVLine(file,data.toStringArray());
29 private static void writeScenarioDataHeader(File file) throws IOException {
30 String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs",
31 "TotalVMs", "TotalDuration", "TotalPowerConsumption",
32 "TotalInSourced", "TotalOutSourced" };
33 appendCSVLine(file, header);
36 private static void writeSchedulerDataHeader(File file) throws IOException {
37 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU",
38 "TotalSize", "RunningPMs", "RunningVMs",
39 "TotalPowerConsumption", "InSourced", "OutSourced" };
40 appendCSVLine(file, header);
43 private static void appendCSVLine(File file, String[] strings)
45 System.out.println("Write to " + file.toString());
46 System.out.print("LogCSV: ");
47 for (String s : strings) {
48 System.out.println(s + " ");
51 CSVWriter writer = new CSVWriter(new FileWriter(file), ';',
52 CSVWriter.NO_QUOTE_CHARACTER);
53 writer.writeNext(strings);