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;
12 public class CSVLogger {
16 public CSVLogger(File file) throws IOException {
20 public void logScenarioData(ScenarioData data) throws IOException {
21 if (file.length() == 0) {
22 writeScenarioDataHeader();
24 writeCSVLine(data.toStringArray());
27 public void logSchedulerData(SchedulerData data) throws IOException {
28 if (file.length() == 0) {
29 writeSchedulerDataHeader();
31 writeCSVLine(data.toStringArray());
34 private void writeScenarioDataHeader() throws IOException {
35 String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs",
36 "TotalVMs", "TotalDuration", "TotalPowerConsumption",
37 "TotalInSourced", "TotalOutSourced" };
41 private void writeSchedulerDataHeader() throws IOException {
42 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU",
43 "TotalSize", "RunningPMs", "RunningVMs",
44 "TotalPowerConsumption", "InSourced", "OutSourced" };
48 private void writeCSVLine(String[] arr) throws IOException {
49 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
51 StringBuilder csvBuilder = new StringBuilder();
53 for (String s : arr) {
54 csvBuilder.append(s).append(";");
57 csvBuilder.deleteCharAt(csvBuilder.length() - 1);
58 out.println(csvBuilder.toString());