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