1 package at.ac.tuwien.lsdc.util;
3 import java.io.BufferedWriter;
5 import java.io.FileWriter;
6 import java.io.IOException;
7 import java.io.PrintWriter;
9 import at.ac.tuwien.lsdc.types.ScenarioData;
10 import at.ac.tuwien.lsdc.types.SchedulerData;
11 import au.com.bytecode.opencsv.CSVWriter;
13 public class CSVLogger {
17 public CSVLogger(File file) throws IOException {
21 public void logScenarioData(ScenarioData data) throws IOException {
22 if (file.length() == 0) {
23 writeScenarioDataHeader();
25 writeCSVLine(data.toStringArray());
28 public void logSchedulerData(SchedulerData data) throws IOException {
29 if (file.length() == 0) {
30 writeSchedulerDataHeader();
32 writeCSVLine(data.toStringArray());
35 private void writeScenarioDataHeader() throws IOException {
36 String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs",
37 "TotalVMs", "TotalDuration", "TotalPowerConsumption",
38 "TotalInSourced", "TotalOutSourced" };
42 private void writeSchedulerDataHeader() throws IOException {
43 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU",
44 "TotalSize", "RunningPMs", "RunningVMs",
45 "TotalPowerConsumption", "InSourced", "OutSourced" };
49 private void writeCSVLine(String[] arr) throws IOException {
50 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
52 StringBuilder csvBuilder = new StringBuilder();
54 for (String s : arr) {
55 csvBuilder.append(s).append(";");
58 csvBuilder.deleteCharAt(csvBuilder.length() - 1);
59 out.println(csvBuilder.toString());