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", "TotalVMs",
36 "TotalDuration", "TotalPowerConsumption", "TotalInSourced", "TotalOutSourced",
37 "TotalResizeEvents" };
41 private void writeSchedulerDataHeader() throws IOException {
42 String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU", "TotalSize",
43 "RunningPMs", "RunningVMs", "TotalPowerConsumption", "InSourced", "OutSourced" };
47 private void writeCSVLine(String[] arr) throws IOException {
48 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
49 StringBuilder csvBuilder = new StringBuilder();
51 for (String s : arr) {
52 csvBuilder.append(s).append(";");
55 csvBuilder.deleteCharAt(csvBuilder.length() - 1);
56 out.println(csvBuilder.toString());