We may reimplement such changes in the near feature considering also the new status of DRAMSys (more specifically Dram.h) and DRAMPower. Changes introduced in the following commits were reverted:98249947f4c0f83bb1dcOther changes: Upper and lower limits for some plots adjusted.
173 lines
6.5 KiB
Python
Executable File
173 lines
6.5 KiB
Python
Executable File
import sys
|
|
import sqlite3
|
|
from memUtil import *
|
|
from math import *
|
|
import ntpath
|
|
import os
|
|
|
|
plots = []
|
|
|
|
|
|
def plot(function):
|
|
plots.append(function)
|
|
return function
|
|
|
|
|
|
@plot
|
|
def memory_utilisation_window(connection, tracePath):
|
|
# This function determines the average memory bandwidth over time in percentage and in Gbit/s.
|
|
# The average bandwidth over time is done dividing the time into windows of the same length and getting the average bandwidth in each window.
|
|
# Through data from the database, DataStrobeEnd and DataStrobeBegin, it is possible to assess when a data transfer begins or ends.
|
|
# Hence, it is achievable to ckeck when a data transfer happens and if it occupies or is inside a time window. Then, it is attainable to determine the average bandwidth in percentage.
|
|
# 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)
|
|
# 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
|
|
for i in range(steps):
|
|
# 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] += 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])
|
|
# 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])
|
|
# print(bandwidthPercentage[i])
|
|
else:
|
|
bandwidthPercentage[i] = windowSize
|
|
# print(bandwidthPercentage[i])
|
|
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)
|
|
|
|
OUTPUT_FILE = 'memory_utilization_' + basename + '.pdf'
|
|
print("Output file is {0}".format(OUTPUT_FILE))
|
|
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
from matplotlib.backends.backend_pdf import PdfPages
|
|
|
|
time = np.arange(0, steps*windowSize, windowSize)
|
|
|
|
plt.figure()
|
|
|
|
subplotIndex = 211
|
|
plt.subplot(subplotIndex)
|
|
plt.plot(time/1000, bandwidthPercentage)
|
|
plt.xlabel('Time (ns)')
|
|
plt.ylabel('Bandwidth (%)')
|
|
plt.ylim(0, 100)
|
|
plt.grid(True)
|
|
|
|
subplotIndex += 1
|
|
plt.subplot(subplotIndex)
|
|
plt.plot(time/1000, bandwidth)
|
|
plt.xlabel('Time (ns)')
|
|
plt.ylabel('Bandwidth (Gibit/s)')
|
|
plt.grid(True)
|
|
|
|
pdf = PdfPages(OUTPUT_FILE)
|
|
pdf.savefig()
|
|
pdf.close()
|
|
plt.close()
|
|
return
|
|
|
|
|
|
@plot
|
|
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 * FROM Power """)
|
|
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
|
|
|
|
name = ntpath.basename(tracePath)
|
|
basename, extension = os.path.splitext(name)
|
|
|
|
OUTPUT_FILE = 'power_' + basename + '.pdf'
|
|
print("Output file is {0}".format(OUTPUT_FILE))
|
|
|
|
import matplotlib.pyplot as plt
|
|
from matplotlib.backends.backend_pdf import PdfPages
|
|
|
|
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()
|
|
pdf.close()
|
|
plt.close()
|
|
return
|
|
|
|
# @plot
|
|
# def latency_histogram(connection):
|
|
# # This function plots an histogram with access latencys
|
|
# cursor = connection.cursor()
|
|
# cursor.execute("SELECT ((p2.PhaseEnd - p1.PhaseEnd)/1000) FROM Transactions t, Phases p1, Phases p2 WHERE t.id = p1.Transact and t.id = p2.Transact and p1.PhaseName = \"REQ\" and p2.PhaseName = \"RESP\" ")
|
|
# result = cursor.fetchall()
|
|
# #result.sort()
|
|
# #print(max(result)[0])
|
|
# import matplotlib.pyplot as plt
|
|
# plt.hist(result, bins=max(result)[0], histtype='barstacked')
|
|
# plt.savefig('hist.png')
|
|
# return "Saved as hist.png"
|
|
|
|
|
|
def generatePlots(pathToTrace):
|
|
connection = sqlite3.connect(pathToTrace)
|
|
|
|
print("================================")
|
|
print("Generating plots for {0}".format(pathToTrace))
|
|
|
|
for p in plots:
|
|
p(connection, pathToTrace)
|
|
|
|
connection.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
path = sys.argv[1]
|
|
generatePlots(path)
|