]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/util/CSVLogger.java
final presentation. NEED BETTER INPUT FILE!
[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", "TotalVMs",
36                                 "TotalDuration", "TotalPowerConsumption", "TotalInSourced", "TotalOutSourced",
37                                 "TotalResizeEvents", "TotalDelayedApps", "TotalStarted", "TotalStopped"};
38                 writeCSVLine(header);
39         }
40
41         private void writeSchedulerDataHeader() throws IOException {
42                 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU", "TotalSize",
43                                 "RunningPMs", "RunningVMs", "TotalPowerConsumption", "InSourced", "OutSourced",
44                                 "TotalResizes", "DelayedApps", "Started", "Stopped"};
45                 writeCSVLine(header);
46         }
47
48         private void writeCSVLine(String[] arr) throws IOException {
49                 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
50                 StringBuilder csvBuilder = new StringBuilder();
51
52                 for (String s : arr) {
53                         csvBuilder.append(s).append(";");
54                 }
55
56                 csvBuilder.deleteCharAt(csvBuilder.length() - 1);
57                 out.println(csvBuilder.toString());
58                 out.close();
59         }
60
61 }