diff --git a/DRAMSys/analyzer/scripts/plots.py b/DRAMSys/analyzer/scripts/plots.py index d09bc31f..e14b32c3 100755 --- a/DRAMSys/analyzer/scripts/plots.py +++ b/DRAMSys/analyzer/scripts/plots.py @@ -22,48 +22,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(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)) + cursor.execute(""" SELECT max(DataStrobeEnd) FROM Transactions """) + total = cursor.fetchone() + windowSize = ceil(float(total[0])/float(steps)) + if (windowSize == 0): + windowSize = 1 + # print(steps) # 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) - bandwidthPercentage = [0] * (steps+1) - bandwidth = [0] * (steps+1) - bandwidthPercentage[0] = 0 - bandwidth[0] = 0 + # print(width) + # print(clk) + # print(rate) + bandwidthPercentage = [0] * steps + bandwidth = [0] * steps for i in range(steps): - bandwidthPercentage[i+1] = 0 + # print(i) + bandwidthPercentage[i] = 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+1] += int(result[0]) + bandwidthPercentage[i] += 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+1] += int(result[0]) + bandwidthPercentage[i] += 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+1] += int(result[0]) + bandwidthPercentage[i] += int(result[0]) # print(bandwidthPercentage[i]) else: - bandwidthPercentage[i+1] = windowSize + bandwidthPercentage[i] = windowSize # print(bandwidthPercentage[i]) - bandwidthPercentage[i+1] = float(bandwidthPercentage[i+1]/windowSize) - bandwidth[i+1] = float(bandwidthPercentage[i+1])*float(maxDataRate)/1024 - bandwidthPercentage[i+1] *= 100 + bandwidthPercentage[i] = float(bandwidthPercentage[i]/windowSize) + bandwidth[i] = float(bandwidthPercentage[i])*float(maxDataRate)/1024 + bandwidthPercentage[i] *= 100 name = ntpath.basename(tracePath) basename, extension = os.path.splitext(name) @@ -75,7 +79,8 @@ def memory_utilisation_window(connection, tracePath): import numpy as np from matplotlib.backends.backend_pdf import PdfPages - time = np.arange(0, (steps+1)*windowSize, windowSize) + time = np.arange(0, steps*windowSize, windowSize) + plt.figure() subplotIndex = 211 @@ -83,7 +88,7 @@ def memory_utilisation_window(connection, tracePath): plt.plot(time/1000, bandwidthPercentage) plt.xlabel('Time (ns)') plt.ylabel('Bandwidth (%)') - plt.ylim(0, 120) + plt.ylim(0, 100) plt.grid(True) subplotIndex += 1 @@ -105,13 +110,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()[0] - steps = ceil(float(maxTime[0])/float(windowSize)) + cursor.execute(""" SELECT min(time) FROM Power WHERE time > 0""") + windowSize = cursor.fetchone() + steps = ceil(float(maxTime[0])/float(windowSize[0])) cursor.execute(""" SELECT * FROM Power """) - time = [0] * (steps+1) - power = [0] * (steps+1) - for i in range((steps+1)): + time = [0] * steps + power = [0] * steps + for i in range(steps): result = cursor.fetchone() time[i] = float(result[0]) * 1000000000 # convertion of seconds to nanoseconds power[i] = float(result[1]) # values are stored in mW @@ -128,6 +133,7 @@ def power_window(connection, tracePath): plt.plot(time, power) plt.xlabel('Time (ns)') plt.ylabel('Power (mW)') + plt.gca().set_ylim(bottom=0) plt.grid(True) pdf = PdfPages(OUTPUT_FILE) pdf.savefig()