#!/usr/bin/python3 import numpy as np import matplotlib.pyplot as plt #Use for running rsync import subprocess #Use for command line args import sys, argparse import array import pickle from matplotlib.pyplot import savefig ''' Plot the data and output to a file ''' def plot(xList,filename): i = 0 colours = ["red", "blue"] labels = ["Enabled", "Disabled"] bins = array.array('f') #Get max and min max = np.amax(xList[0]) if np.amax(xList[1]) > max: max = np.amax(xList[1]) min = np.amin(xList[0]) if np.amin(xList[1]) < min: min = np.amin(xList[1]) intervalBins = np.linspace(min, max, num=100) for data in xList: n, bins, patches = plt.hist(data, intervalBins, facecolor=colours[i], alpha=0.75, label=labels[i]); print(str(n) + " " + str(bins) + " " + str(patches) + "\n") i = i + 1 print("Mean: " + str(np.mean(data)) + " seconds\n") print("Std: " + str(np.std(data,dtype=np.float64)) + " seconds\n") print("Max: " + str(np.amax(data)) + " Min: " + str(np.amin(data)) + "\n") plt.legend(loc='upper right') plt.ylabel("Frequency") plt.xlabel("Time/s") plt.title("Graph of Xen deprivileged user performance") plt.ticklabel_format(axis='x', style='sci', scilimits=(-2,2)) fg = plt.gcf() fg.savefig(filename) return def main(): #Setup parser parser = argparse.ArgumentParser(description="Test HVM depriv performance.") parser.add_argument("-p", "--plot", nargs=2, metavar=("[DATA FILE NAME]", "[GRAPH FILE NAME]"), help="Plot the data and output a graph at file name") args = parser.parse_args() #Process args if args.plot: print("Plotting...\n") #Use Pickle to load in the array timeData = pickle.load(open(args.plot[0], "rb")) #Parse it and plot plot(timeData, args.plot[1]) print("DONE") if __name__ == '__main__': main()