diff --git a/DRAMSys/traceAnalyzer/scripts/plots.py b/DRAMSys/traceAnalyzer/scripts/plots.py index 7576fd8a..185442d1 100755 --- a/DRAMSys/traceAnalyzer/scripts/plots.py +++ b/DRAMSys/traceAnalyzer/scripts/plots.py @@ -193,38 +193,57 @@ def memory_utilisation_window(connection, tracePath, steps): @plot def power_window(connection, tracePath, steps): + windowSize = getWindowSize(connection) + outputFile = "" cursor = connection.cursor() + cursor.execute(" SELECT * FROM Power") - result = cursor.fetchone() - if(result is not None): - time = [0] * (steps+1) - power = [0] * (steps+1) - time[0] = 0 - power[0] = 0 - #pow(10,9): seconds to nanoseconds conversion - time[1] = float(result[0])*pow(10,9) - power[1] = float(result[1]) - for i in range((steps-1)): + + power = [0] * (steps+1) + window = float(windowSize) / pow(10,12) + + for i in range(steps): + sum = 0.0 + counter = 0 + result = cursor.fetchone() + + while (result is not None): + sum += float(result[1]) + counter = counter + 1 + if(result[0] > window*i): + break result = cursor.fetchone() - time[i+2] = float(result[0])*pow(10,9) - power[i+2] = float(result[1]) - outputFileName, basename = createOutputFilename(tracePath, 'power', '', 'pdf') - outputFile = "{0}\n\t".format(outputFileName) + if(counter == 0): + break - import matplotlib.pyplot as plt - from matplotlib.backends.backend_pdf import PdfPages + sum = sum / counter + power[i] = sum + + import numpy as np + time = np.arange(0, windowSize*(steps+1)/1000/1000, windowSize/1000/1000) + + outputFileName, basename = createOutputFilename(tracePath, 'power', '', 'pdf') + outputFile = "{0}\n\t".format(outputFileName) + + import matplotlib.pyplot as plt + from matplotlib.backends.backend_pdf import PdfPages + + PowFigure = plt.figure(figsize=(10,5), dpi=300) + PowFigurePlot = PowFigure.add_subplot(111) + PowFigurePlot.set_xlabel('Time [us]') + PowFigurePlot.set_ylabel('Power [mW]') + PowFigurePlot.set_title('Power Consumption ' + str(basename)) + PowFigurePlot.grid(True) + PowFigurePlot.plot(time, power, linewidth=0.5) + + pdf = PdfPages(outputFileName) + pdf.savefig(PowFigure) + pdf.close() + PowFigurePlot.clear() + plt.close() - plt.plot(time, power) - plt.xlabel('Time [ns]') - plt.ylabel('Power [mW]') - plt.grid(True) - plt.title('Power Consumption ' + str(basename)) - pdf = PdfPages(outputFileName) - pdf.savefig() - pdf.close() - plt.close() return outputFile @plot