From bdc9e58d605fba39b97886e86d5f1fe0b192b606 Mon Sep 17 00:00:00 2001 From: Felipe Salerno Prado Date: Thu, 28 Apr 2016 17:17:26 +0200 Subject: [PATCH] Charts Correction --- DRAMSys/analyzer/scripts/plots.py | 58 +++++++++++++------------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/DRAMSys/analyzer/scripts/plots.py b/DRAMSys/analyzer/scripts/plots.py index 745ad8c2..4706b98d 100644 --- a/DRAMSys/analyzer/scripts/plots.py +++ b/DRAMSys/analyzer/scripts/plots.py @@ -7,7 +7,6 @@ import os plots = [] - def plot(function): plots.append(function) return function @@ -22,58 +21,52 @@ def memory_utilisation_window(connection, tracePath): # Besides, extracting the data from the memory specs, it is feasible to calculate the maximum data rate of the memory and then determine the bandwidth in Gbit/s. # The bandwidth data are then plotted in two graphics. - steps = 1000 cursor = connection.cursor() - cursor.execute(""" SELECT max(DataStrobeEnd) FROM Transactions """) - total = cursor.fetchone() - windowSize = ceil(float(total[0])/float(steps)) - if (windowSize == 0): - windowSize = 1 - # print(steps) + cursor.execute(""" SELECT max(time) FROM Power """) + maxTime = cursor.fetchone() + cursor.execute(""" SELECT min(time) FROM Power where time > 0 """) + windowSize = cursor.fetchone()[0] + steps = ceil(float(maxTime[0])/float(windowSize)) # All possible cases of data transfers inside a time window queryFull = """ SELECT sum(DataStrobeEnd - DataStrobeBegin) FROM transactions Where DataStrobeBegin > ? and DataStrobeEnd < ?""" # The data transfer begins and ends inside the time window queryEnd = """ SELECT sum(DataStrobeEnd - ?) FROM transactions Where DataStrobeBegin < ? and DataStrobeEnd > ? and DataStrobeEnd <=?""" # Only the end of the data transfer is inside the time window queryBegin = """ SELECT sum(? - DataStrobeBegin) FROM transactions Where DataStrobeBegin >= ? and DataStrobeBegin < ? and DataStrobeEnd > ?""" # Only the beginning of the data transfer is inside the time window queryPart = """ SELECT DataStrobeBegin FROM transactions Where DataStrobeBegin <= ? and DataStrobeEnd >= ?""" # The data transfer occupies all the time window maxDataRate = maximum_data_rate(connection) - # print(width) - # print(clk) - # print(rate) - bandwidthPercentage = [0] * steps - bandwidth = [0] * steps + bandwidthPercentage = [0] * (steps+1) + bandwidth = [0] * (steps+1) + bandwidthPercentage[0] = 0 + bandwidth[0] = 0 for i in range(steps): - # print(i) - bandwidthPercentage[i] = 0 + bandwidthPercentage[i+1] = 0 cursor.execute(queryPart, (i*windowSize, (i+1)*windowSize)) result = cursor.fetchone() if(result is None): cursor.execute(queryFull, (i*windowSize, (i+1)*windowSize)) result = cursor.fetchone() if(result[0] is not None): - bandwidthPercentage[i] += int(result[0]) + bandwidthPercentage[i+1] += int(result[0]) # print(bandwidthPercentage[i]) cursor.execute(queryEnd, (i*windowSize, i*windowSize, i*windowSize, (i+1)*windowSize)) result = cursor.fetchone() if(result[0] is not None): - bandwidthPercentage[i] += int(result[0]) + bandwidthPercentage[i+1] += int(result[0]) # print(bandwidthPercentage[i]) cursor.execute(queryBegin, ((i+1)*windowSize, i*windowSize, (i+1)*windowSize, (i+1)*windowSize)) result = cursor.fetchone() if(result[0] is not None): - bandwidthPercentage[i] += int(result[0]) + bandwidthPercentage[i+1] += int(result[0]) # print(bandwidthPercentage[i]) else: - bandwidthPercentage[i] = windowSize + bandwidthPercentage[i+1] = windowSize # print(bandwidthPercentage[i]) - bandwidthPercentage[i] = float(bandwidthPercentage[i]/windowSize) - bandwidth[i] = float(bandwidthPercentage[i])*float(maxDataRate)/1024 - bandwidthPercentage[i] *= 100 + bandwidthPercentage[i+1] = float(bandwidthPercentage[i+1]/windowSize) + bandwidth[i+1] = float(bandwidthPercentage[i+1])*float(maxDataRate)/1024 + bandwidthPercentage[i+1] *= 100 name = ntpath.basename(tracePath) basename, extension = os.path.splitext(name) - - OUTPUT_FILE = 'memory_utilization_' + basename + '.pdf' print("Output file is {0}".format(OUTPUT_FILE)) @@ -81,8 +74,7 @@ def memory_utilisation_window(connection, tracePath): import numpy as np from matplotlib.backends.backend_pdf import PdfPages - time = np.arange(0, steps*windowSize, windowSize) - + time = np.arange(0, (steps+1)*windowSize, windowSize) plt.figure() subplotIndex = 211 @@ -112,13 +104,13 @@ def power_window(connection, tracePath): cursor = connection.cursor() cursor.execute(""" SELECT max(time) FROM Power """) maxTime = cursor.fetchone() - cursor.execute(""" SELECT min(time) FROM Power WHERE time > 0""") - windowSize = cursor.fetchone() - steps = ceil(float(maxTime[0])/float(windowSize[0])) + cursor.execute(""" SELECT min(time) FROM Power where time > 0 """) + windowSize = cursor.fetchone()[0] + steps = ceil(float(maxTime[0])/float(windowSize)) cursor.execute(""" SELECT * FROM Power """) - time = [0] * steps - power = [0] * steps - for i in range(steps): + time = [0] * (steps+1) + power = [0] * (steps+1) + for i in range((steps+1)): result = cursor.fetchone() time[i] = int(result[0])/1000 power[i] = float(result[1]) @@ -156,7 +148,7 @@ def power_window(connection, tracePath): # return "Saved as hist.png" -def generatePlots(pathToTrace): +def generatePlots(pathToTrace): connection = sqlite3.connect(pathToTrace) print("================================")