Commit 54a75e5e authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Initial Commit (restarting PC and stretching my legs)

parent 26546cba
......@@ -295,6 +295,16 @@ public class PlacementMap {
return max;
}
public int getMinNumberOfVMsPerClient() {
int min = Integer.MAX_VALUE;
for (Map.Entry<Integer, Client> c : _clients.entrySet()) {
if (min > c.getValue().getNumberOfVMs()) {
min = c.getValue().getNumberOfVMs();
}
}
return min;
}
/**
* Returns the maximum number of slots any Machine has
* @return max number of slots any machine has
......@@ -431,4 +441,18 @@ public class PlacementMap {
return numMoves;
}
public double percentFilled() {
return (double) getNumberOfVMs() / getNumberOfTotalSlots();
}
public int getNumberOfTotalSlots() {
int sum = 0;
for (Machine m : _machines) {
sum += m._maxSpots;
}
return sum;
}
}
......@@ -2,12 +2,225 @@ package vagabond.results;
import java.util.ArrayList;
import vagabond.pieces.*;
import vagabond.singleton.VagabondSettings;
public class StatisticsManager {
public ArrayList<Long> epochTimes;
public VagabondSettings settings;
public String startDTStr;
public String testName = "";
public PlacementMap initialPM;
public ClientToClientInformationLeakage initialCCIL;
public PlacementMap finalPM;
public ClientToClientInformationLeakage finalCCIL;
public EpochHistory eh;
public ArrayList<Long> epochTimes = new ArrayList<>();
public Long avgEpochTime = null;
public ArrayList<Integer> listTIL = new ArrayList<>();
public ArrayList<Integer> listMCCIL = new ArrayList<>();
public ArrayList<Integer> listMovesPerEpoch = new ArrayList<>();
public Long totalTime = null;
public String comments = "";
public StatisticsManager() {
epochTimes = new ArrayList<>();
settings = VagabondSettings.getInstance();
startDTStr = settings.getCurrentDateTimeStr();
}
public String getCSVHeader() {
StringBuilder sb = new StringBuilder(1000);
sb.append("Date Time,");
sb.append("Test Name,");
// Metrics Describing the Setup
sb.append("Machines,");
sb.append("Clients,");
sb.append("Slots,");
sb.append("Max VMs/Client,");
sb.append("Min VMs/Client,");
sb.append("Placement,"); // the name and a descriptive value to individualize
sb.append("Total VMs,");
sb.append("MigBudget,");
sb.append("% Filled,");
sb.append("Total Slots,");
sb.append("Window,");
sb.append("Seed,");
sb.append("# Epochs,");
sb.append("Reduction,");
sb.append("Objective,");
// Metrics describing the Performance or Optimality
sb.append("Avg Epoch Time(ms),");
sb.append("Initial TIL,"); // Total Information Leakage (initial Placement)
sb.append("Final TIL,"); // Total Information Leakage (final placement)
sb.append("Initial MCCIL,");
sb.append("Final MCCIL,");
sb.append("TIL Gain,");
sb.append("MCCIL Gain,");
sb.append("TIL Epochs Changed,");
sb.append("MCCIL Epochs Changed,");
// Lists (raw Data)
sb.append("List of Epoch Times,");
sb.append("Distribution of initial CCIL,");
sb.append("Distribution of final CCIL,");
sb.append("List TIL,");
sb.append("List MCCIL,");
sb.append("List of # Moves per Epoch,");
sb.append("Last Epoch with Move,");
sb.append("Total Test Time(ms),");
sb.append("Comments");
return sb.toString();
}
public String getCSVStatsLine() {
StringBuilder sb = new StringBuilder(3000);
// sb.append("Date Time,");
sb.append(startDTStr).append(",");
// sb.append("Test Name,");
sb.append(testName).append(",");
/**
* Metrics Describing the Setup
*/
// sb.append("Machines,");
sb.append(settings.numberOfMachines).append(",");
// sb.append("Clients,");
sb.append(settings.numberOfClients).append(",");
// sb.append("Slots,");
sb.append(settings.numberOfMachineSlots).append(",");
// sb.append("Max VMs/Client,");
sb.append(initialPM.getMaxNumberOfVMsPerClient()).append(",");
// sb.append("Min VMs/Client,");
sb.append(initialPM.getMinNumberOfVMsPerClient()).append(",");
// sb.append("Placement,"); // the name and a descriptive value to individualize
sb.append(settings.getInformativePlacement()).append(",");
// sb.append("Total VMs,");
sb.append(initialPM.getNumberOfVMs()).append(",");
// sb.append("MigBudget,");
sb.append(settings.migrationBudget).append(",");
// sb.append("% Filled,");
sb.append(initialPM.percentFilled()).append(",");
// sb.append("Total Slots,");
sb.append(initialPM.getNumberOfTotalSlots()).append(",");
// sb.append("Window,");
sb.append(settings.slidingWindow).append(",");
// sb.append("Seed,");
sb.append(settings.randomSeed).append(",");
// sb.append("# Epochs,");
sb.append(settings.numberOfEpochs).append(",");
// sb.append("Reduction,");
sb.append(settings.reductionAlgorithm).append(",");
// sb.append("Objective,");
sb.append(settings.getObjectiveStr()).append(",");
/**
* Metrics describing the Performance or Optimality
*/
// sb.append("Avg Epoch Time,");
sb.append(getAvgEpochTime()).append(",");
// sb.append("Initial TIL,");
sb.append(listTIL.get(0)).append(",");
// sb.append("Final TIL,");
sb.append(listTIL.get(listTIL.size() - 1)).append(",");
// sb.append("Initial MCCIL,");
sb.append(listMCCIL.get(0)).append(",");
// sb.append("Final MCCIL,");
sb.append(listMCCIL.get(listMCCIL.size() - 1)).append(",");
// sb.append("TIL Gain,");
sb.append(listTIL.get(0) - listTIL.get(listTIL.size() - 1)).append(",");
// sb.append("MCCIL Gain,");
sb.append(listMCCIL.get(0) - listMCCIL.get(listMCCIL.size() - 1)).append(",");
sb.append("TIL Epochs Changed,");
sb.append(traceBackList(listTIL, null)).append(",");
sb.append("MCCIL Epochs Changed,");
sb.append(traceBackList(listMCCIL, null)).append(",");
/**
* Lists (raw Data)
*/
// sb.append("List of Epoch Times,");
sb.append(getListStr(epochTimes, ";")).append(",");
// sb.append("Distribution of initial CCIL,");
int[] initialCCILDist = getDistribution(initialCCIL, listMCCIL.get(0));
sb.append(getArrayStr(initialCCILDist, ";")).append(",");
// sb.append("Distribution of final CCIL,");
int[] finalCCILDist = getDistribution(finalCCIL, listMCCIL.get(listMCCIL.size() - 1));
sb.append(getArrayStr(finalCCILDist, ";")).append(",");
// sb.append("List TIL,");
sb.append(getListStr(listTIL, ";")).append(",");
// sb.append("List MCCIL,");
sb.append(getListStr(listMCCIL, ";")).append(",");
// sb.append("List of # Moves per Epoch,");
sb.append(getListStr(listMovesPerEpoch, ";")).append(",");
// sb.append("Last Epoch with Move,");
sb.append(traceBackList(listMovesPerEpoch, 0)).append(",");
// sb.append("Total Test Time(ms),");
sb.append(totalTime).append(",");
// sb.append("Comments");
sb.append(comments).append("\n");
return sb.toString();
}
public int traceBackList(ArrayList<Integer> list, Integer value) {
for (int i = list.size() - 1; i >= 0; i--) {
if (value != null) {
if (!list.get(i).equals(value)) { return i; }
} else {
if (i == list.size() - 1) {
continue;
}
// Check with previous value
if (!list.get(i).equals(list.get(i + 1))) { return i; }
}
}
return 0;
}
private String getArrayStr(int[] arr, String delim) {
StringBuilder sb = new StringBuilder(arr.length * 10);
for (int i = 0; i < arr.length; i++) {
if (i != 0) {
sb.append(delim);
}
sb.append(i).append("=").append(arr[i]);
}
return sb.toString();
}
private int[] getDistribution(ClientToClientInformationLeakage ccil, int maxVal) {
int[] rtn = new int[maxVal + 1]; // initialized to 0
for (Integer c0 : ccil._clientIDs) {
for (Integer c1 : ccil._clientIDs) {
rtn[ccil.get(c0, c1)]++;
}
}
return rtn;
}
public String getListStr(ArrayList<?> list, String delim) {
StringBuilder sb = new StringBuilder(list.size() * 10);
for (int i = 0; i < list.size(); i++) {
if (i != 0) {
sb.append(delim);
}
sb.append(list.get(i).toString());
}
return sb.toString();
}
public void addEpochTime(Long epochTime) {
......@@ -28,5 +241,4 @@ public class StatisticsManager {
}
return avgEpochTime;
}
}
......@@ -3,6 +3,7 @@ package vagabond.singleton;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.*;
import org.apache.commons.lang3.SystemUtils;
......@@ -340,6 +341,27 @@ public class VagabondSettings {
return s.toString();
}
public String getInformativePlacement() {
String name = "";
switch (placementAlgorithm) {
case PLACEMENT_EQUALSPREAD:
name = "EqualSpread_" + equalSpreadNum;
break;
case PLACEMENT_EQUALSPREADHALF:
name = "EqualSpreadHalf_" + equalSpreadNum;
break;
case PLACEMENT_FILE:
name = "File_" + placementMapFile;
break;
case PLACEMENT_RANDOM:
name = "Random_" + randomSeed;
break;
default:
name = placementAlgorithm.toString();
}
return name;
}
/**
* Returns the instance of the logger; creates the logger on the first call.
* @return instance of the logger
......@@ -418,6 +440,19 @@ public class VagabondSettings {
}
}
/**
* Closes all of the open handles and removes all the locks from log files.
* If System.exit() needs to be called or the program exits normally,
* then this function should be called before hand.
*/
public void shutdown() {
if (logger != null) {
for (Handler h : logger.getHandlers()) {
h.close();// must call h.close or a .LCK file will remain.
}
}
}
/**
* Function to return the file path of the timing file. Used to write out the timing results.
* This should be considered a WRITE only file.
......@@ -508,20 +543,16 @@ public class VagabondSettings {
return new File(dataFolder + File.separator + ilpOplNoMigrationFileSumInfoLeak);
}
/**
* Closes all of the open handles and removes all the locks from log files.
* If System.exit() needs to be called or the program exits normally,
* then this function should be called before hand.
*/
public void shutdown() {
if (logger != null) {
for (Handler h : logger.getHandlers()) {
h.close();// must call h.close or a .LCK file will remain.
}
}
}
public File getCNFInstanceFile() {
return new File(dataFolder + File.separator + cnfInstanceFile);
}
public String getCurrentDateTimeStr() {
return df.format(new Date(System.currentTimeMillis()));
}
public String getObjectiveStr() {
if (minimizeMaxClientToClientInfoLeak) { return "Max CCIL"; }
return "Sum CCIL";
}
}
package vagabond.testing;
public class StatisticsManagerTests {
}
......@@ -5,8 +5,6 @@ package vagabond.timing.tests;
import org.junit.Test;
import vagabond.circuit.Circuit;
import vagabond.circuit.ZeroOne;
import vagabond.pieces.EpochHistory;
import vagabond.pieces.PlacementMap;
import vagabond.placement.RandomPlacement;
......
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