]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/util/CSVLogger.java
added CSV logging (still little bit buggy)
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / util / CSVLogger.java
1 package at.ac.tuwien.lsdc.util;
2
3 import java.io.File;
4 import java.io.FileWriter;
5 import java.io.IOException;
6
7 import at.ac.tuwien.lsdc.types.ScenarioData;
8 import at.ac.tuwien.lsdc.types.SchedulerData;
9 import au.com.bytecode.opencsv.CSVWriter;
10
11 public class CSVLogger {
12
13         public static void logScenarioData(File file, ScenarioData data)
14                         throws IOException {
15                 if (file.length() == 0) {
16                         writeScenarioDataHeader(file);
17                 }
18                 appendCSVLine(file,data.toStringArray());
19         }
20
21         public static void logSchedulerData(File file, SchedulerData data)
22                         throws IOException {
23                 if (file.length() == 0) {
24                         writeSchedulerDataHeader(file);
25                 }
26                 appendCSVLine(file,data.toStringArray());
27         }
28
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);
34         }
35
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);
41         }
42
43         private static void appendCSVLine(File file, String[] strings)
44                         throws IOException {
45                 System.out.println("Write to " + file.toString());
46                 System.out.print("LogCSV: ");
47                 for (String s : strings) {
48                         System.out.println(s + " ");
49                 }
50                 System.out.println();
51                 CSVWriter writer = new CSVWriter(new FileWriter(file), ';',
52                                 CSVWriter.NO_QUOTE_CHARACTER);
53                 writer.writeNext(strings);
54                 writer.close();
55         }
56
57 }