]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/util/CSVLogger.java
Merge branch 'master' of ssh://dev.somenet.org:666/tu/lsdc
[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         private CSVWriter writer;
14         private File file;
15         
16         public CSVLogger(File file) throws IOException {
17                 this.file = file;
18                 this.writer = new CSVWriter(new FileWriter(file), ';',
19                                 CSVWriter.NO_QUOTE_CHARACTER);
20         }
21         
22         public void logScenarioData(ScenarioData data)
23                         throws IOException {
24                 if (file.length() == 0) {
25                         writeScenarioDataHeader();
26                 }
27                 writer.writeNext(data.toStringArray());
28         }
29
30         public void logSchedulerData(SchedulerData data)
31                         throws IOException {
32                 if (file.length() == 0) {
33                         writeSchedulerDataHeader();
34                 }
35                 writer.writeNext(data.toStringArray());
36         }
37
38         private void writeScenarioDataHeader() throws IOException {
39                 String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs",
40                                 "TotalVMs", "TotalDuration", "TotalPowerConsumption",
41                                 "TotalInSourced", "TotalOutSourced" };
42                 writer.writeNext(header);
43         }
44
45         private void writeSchedulerDataHeader() throws IOException {
46                 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU",
47                                 "TotalSize", "RunningPMs", "RunningVMs",
48                                 "TotalPowerConsumption", "InSourced", "OutSourced" };
49                 writer.writeNext(header);
50         }
51         
52         public void close() throws IOException {
53                 writer.close();
54         }
55 }