Commit a0f0f2f4 authored by Benardi's avatar Benardi
Browse files

Add code host energy logging

parent 4fd3fdf9
......@@ -64,7 +64,7 @@ import org.cloudsimplus.slametrics.SlaMetricDimension;
public class SlaExploitationSimulation {
private static String PATH;
private static String PATH = "/home/benardi/";
private static String FILEID;
private static int SLA_TIGHT_HOSTS;
private static int SLA_LOOSE_HOSTS;
......@@ -170,6 +170,7 @@ public class SlaExploitationSimulation {
CsvGenerator.outputCloudletResults(PATH+"cloudlets-"+FILEID, finishedCloudlets);
CsvGenerator.outputSlaResults(PATH+"sla-"+FILEID, finishedCloudlets, (int) simulation.clock());
CsvGenerator.outputHostsEnergy(PATH+"hosts-"+FILEID, datacenter.getHostList(),datacenter.getSchedulingInterval());
}
private SlaContract createSlaContract(long minimum_iops, double availability) {
......@@ -244,6 +245,7 @@ public class SlaExploitationSimulation {
Vm vm = new VmSimple(i, VM_MIPS, VM_PES).setRam(VM_RAM).setBw(VM_BW).setSize(VM_STORAGE)
.setIops(VM_IOPS).setCloudletScheduler(new CloudletSchedulerSpaceShared());
vm.setContract(contract);
vm.getUtilizationHistory().enable();
list.add(vm);
}
......
......@@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.List;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.hosts.Host;
public class CsvGenerator {
......@@ -103,6 +104,41 @@ public class CsvGenerator {
return writer;
}
public static void outputHostsEnergy(String outputFile, List<Host> existingHosts, double schedulingInterval) {
FileWriter writer = createHeaderForHostsEnergy(outputFile);
writer = writeHostsEnergy(writer, existingHosts, schedulingInterval);
flushFile(writer);
}
private static FileWriter writeHostsEnergy(FileWriter writer, List<Host> existingHosts, double schedulingInterval) {
//datacenter.id, host.id, host.time, host.energy
try{
for(Host h : existingHosts){
int moment = 0;
double[] history = h.getUtilizationHistory();
writer.append(String.valueOf(history.length));
writer.append('\n');
for(int i = 0; i < history.length; i++) {
writer.append(String.valueOf(h.getDatacenter().getId()));
writer.append(',');
writer.append(String.valueOf(h.getId()));
writer.append(',');
writer.append(String.valueOf(schedulingInterval * moment));
writer.append(',');
writer.append(String.valueOf(history[i]));
writer.append('\n');
moment++;
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Exception while writing cloudlets results...");
}
return writer;
}
private static void flushFile(FileWriter writer) {
......@@ -146,6 +182,31 @@ public class CsvGenerator {
}
private static FileWriter createHeaderForHostsEnergy(String outputFile) {
FileWriter writer = null;
try {
writer = new FileWriter(outputFile + ".csv");
} catch (IOException e) {
e.printStackTrace();
}
try {
writer.append("datacenter-id");
writer.append(',');
writer.append("host-id");
writer.append(',');
writer.append("host.time");
writer.append(',');
writer.append("host.energy");
writer.append('\n');
} catch (IOException e) {
e.printStackTrace();
}
return writer;
}
private static FileWriter writeCloudletSlaViolations(FileWriter writer, List<Cloudlet> finishedCloudlets, int lastSimulationTime) {
try{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment