]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/util/CSVLogger.java
Some own test outputs on resize and delays
[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" };
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                 writeCSVLine(header);
45         }
46
47         private void writeCSVLine(String[] arr) throws IOException {
48                 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
49                 StringBuilder csvBuilder = new StringBuilder();
50
51                 for (String s : arr) {
52                         csvBuilder.append(s).append(";");
53                 }
54
55                 csvBuilder.deleteCharAt(csvBuilder.length() - 1);
56                 out.println(csvBuilder.toString());
57                 out.close();
58         }
59
60 }