]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/util/CSVLogger.java
change build.xml clean ..
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / util / CSVLogger.java
1 package at.ac.tuwien.lsdc.util;
2
3 import java.io.BufferedWriter;
4 import java.io.File;
5 import java.io.FileWriter;
6 import java.io.IOException;
7 import java.io.PrintWriter;
8
9 import at.ac.tuwien.lsdc.types.ScenarioData;
10 import at.ac.tuwien.lsdc.types.SchedulerData;
11
12 public class CSVLogger {
13
14         private File file;
15
16         public CSVLogger(File file) throws IOException {
17                 this.file = file;
18         }
19
20         public void logScenarioData(ScenarioData data) throws IOException {
21                 if (file.length() == 0) {
22                         writeScenarioDataHeader();
23                 }
24                 writeCSVLine(data.toStringArray());
25         }
26
27         public void logSchedulerData(SchedulerData data) throws IOException {
28                 if (file.length() == 0) {
29                         writeSchedulerDataHeader();
30                 }
31                 writeCSVLine(data.toStringArray());
32         }
33
34         private void writeScenarioDataHeader() throws IOException {
35                 String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs",
36                                 "TotalVMs", "TotalDuration", "TotalPowerConsumption",
37                                 "TotalInSourced", "TotalOutSourced" };
38                 writeCSVLine(header);
39         }
40
41         private void writeSchedulerDataHeader() throws IOException {
42                 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU",
43                                 "TotalSize", "RunningPMs", "RunningVMs",
44                                 "TotalPowerConsumption", "InSourced", "OutSourced" };
45                 writeCSVLine(header);
46         }
47
48         private void writeCSVLine(String[] arr) throws IOException {
49                 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
50                                 file, true)));
51                 StringBuilder csvBuilder = new StringBuilder();
52
53                 for (String s : arr) {
54                         csvBuilder.append(s).append(";");
55                 }
56
57                 csvBuilder.deleteCharAt(csvBuilder.length() - 1);
58                 out.println(csvBuilder.toString());
59                 out.close();
60         }
61
62 }