Improving the generation of plots
This commit is contained in:
@@ -14,7 +14,7 @@ def plot(function):
|
||||
|
||||
|
||||
@plot
|
||||
def memory_utilisation_window(connection, tracePath):
|
||||
def memory_utilisation_window(connection, tracePath, steps):
|
||||
# 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.
|
||||
@@ -23,101 +23,93 @@ def memory_utilisation_window(connection, tracePath):
|
||||
# The bandwidth data are then plotted in two graphics.
|
||||
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT time FROM Power """)
|
||||
outputFile = ""
|
||||
if(cursor.fetchone() is not None):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT max(time) FROM Power")
|
||||
maxTime = pow(10,12)*cursor.fetchone()[0]
|
||||
cursor.execute("SELECT min(time) FROM Power WHERE time > 0")
|
||||
windowSize = pow(10,12)*cursor.fetchone()[0]
|
||||
steps = ceil(float(maxTime)/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)
|
||||
maximumPercentage = 0
|
||||
bandwidthPercentage = [0] * (steps+1)
|
||||
bandwidth = [0] * (steps+1)
|
||||
bandwidthPercentage[0] = 0
|
||||
bandwidth[0] = 0
|
||||
for i in range(steps):
|
||||
bandwidthPercentage[i+1] = 0
|
||||
cursor.execute(queryPart, (i*windowSize, (i+1)*windowSize))
|
||||
cursor.execute("SELECT min(time) FROM Power")
|
||||
windowSize = pow(10,12)*float(cursor.fetchone()[0])
|
||||
# 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)
|
||||
maximumPercentage = 0
|
||||
bandwidthPercentage = [0] * (steps+1)
|
||||
bandwidth = [0] * (steps+1)
|
||||
bandwidthPercentage[0] = 0
|
||||
bandwidth[0] = 0
|
||||
for i in range(steps):
|
||||
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 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])
|
||||
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])
|
||||
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])
|
||||
else:
|
||||
bandwidthPercentage[i+1] = windowSize
|
||||
bandwidthPercentage[i+1] = float(bandwidthPercentage[i+1]/windowSize)
|
||||
bandwidth[i+1] = float(bandwidthPercentage[i+1])*float(maxDataRate)/1024
|
||||
bandwidthPercentage[i+1] *= 100
|
||||
if(maximumPercentage < 100 and maximumPercentage < bandwidthPercentage[i+1]):
|
||||
maximumPercentage = bandwidthPercentage[i+1]
|
||||
if(result[0] is not None):
|
||||
bandwidthPercentage[i+1] += int(result[0])
|
||||
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])
|
||||
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])
|
||||
else:
|
||||
bandwidthPercentage[i+1] = windowSize
|
||||
bandwidthPercentage[i+1] = float(bandwidthPercentage[i+1]/windowSize)
|
||||
bandwidth[i+1] = float(bandwidthPercentage[i+1])*float(maxDataRate)/1024
|
||||
bandwidthPercentage[i+1] *= 100
|
||||
if(maximumPercentage < 100 and maximumPercentage < bandwidthPercentage[i+1]):
|
||||
maximumPercentage = bandwidthPercentage[i+1]
|
||||
|
||||
name = ntpath.basename(tracePath)
|
||||
basename, extension = os.path.splitext(name)
|
||||
name = ntpath.basename(tracePath)
|
||||
basename, extension = os.path.splitext(name)
|
||||
|
||||
OUTPUT_FILE = 'memory_utilization_' + basename + '.pdf'
|
||||
outputFile = "Output file is {0}".format(OUTPUT_FILE)
|
||||
OUTPUT_FILE = 'memory_utilization_' + basename + '.pdf'
|
||||
outputFile = "Output file is {0}".format(OUTPUT_FILE)
|
||||
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib.backends.backend_pdf import PdfPages
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib.backends.backend_pdf import PdfPages
|
||||
|
||||
time = np.arange(0, (steps+1)*windowSize, windowSize)
|
||||
time = np.arange(0, (steps+1)*windowSize, windowSize)
|
||||
|
||||
plt.figure()
|
||||
plt.figure()
|
||||
|
||||
subplotIndex = 211
|
||||
plt.subplot(subplotIndex)
|
||||
plt.plot(time/1000, bandwidthPercentage)
|
||||
plt.xlabel('Time (ns)')
|
||||
plt.ylabel('Bandwidth (%)')
|
||||
plt.ylim(0, maximumPercentage + (10 - maximumPercentage%10))
|
||||
plt.grid(True)
|
||||
subplotIndex = 211
|
||||
plt.subplot(subplotIndex)
|
||||
plt.plot(time/1000, bandwidthPercentage)
|
||||
plt.xlabel('Time (ns)')
|
||||
plt.ylabel('Bandwidth (%)')
|
||||
plt.ylim(0, maximumPercentage + (10 - maximumPercentage%10))
|
||||
plt.grid(True)
|
||||
|
||||
subplotIndex += 1
|
||||
plt.subplot(subplotIndex)
|
||||
plt.plot(time, bandwidth)
|
||||
plt.xlabel('Time (ns)')
|
||||
plt.ylabel('Bandwidth (Gibit/s)')
|
||||
plt.grid(True)
|
||||
subplotIndex += 1
|
||||
plt.subplot(subplotIndex)
|
||||
plt.plot(time, bandwidth)
|
||||
plt.xlabel('Time (ns)')
|
||||
plt.ylabel('Bandwidth (Gibit/s)')
|
||||
plt.grid(True)
|
||||
|
||||
pdf = PdfPages(OUTPUT_FILE)
|
||||
pdf.savefig()
|
||||
pdf.close()
|
||||
plt.close()
|
||||
pdf = PdfPages(OUTPUT_FILE)
|
||||
pdf.savefig()
|
||||
pdf.close()
|
||||
plt.close()
|
||||
return outputFile
|
||||
|
||||
|
||||
@plot
|
||||
def power_window(connection, tracePath):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT time FROM Power """)
|
||||
def power_window(connection, tracePath, steps):
|
||||
|
||||
outputFile = ""
|
||||
if(cursor.fetchone() is not None):
|
||||
cursor = connection.cursor()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(" SELECT time FROM Power WHERE averagePower = 0")
|
||||
if(cursor.fetchone() is None):
|
||||
cursor.execute("SELECT max(time) FROM Power")
|
||||
maxTime = pow(10,9)*cursor.fetchone()[0]
|
||||
cursor.execute("SELECT min(time) FROM Power WHERE time > 0")
|
||||
windowSize = pow(10,9)*cursor.fetchone()[0]
|
||||
steps = ceil(float(maxTime)/float(windowSize))
|
||||
maxTime = cursor.fetchone()[0]
|
||||
cursor.execute("SELECT min(time) FROM Power")
|
||||
windowSize = cursor.fetchone()[0]
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT * FROM Power """)
|
||||
time = [0] * (steps+1)
|
||||
power = [0] * (steps+1)
|
||||
@@ -168,9 +160,19 @@ def generatePlots(pathToTrace):
|
||||
#print("================================")
|
||||
#print("Generating plots for {0}".format(pathToTrace))
|
||||
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(" SELECT time FROM Power ")
|
||||
outputFiles = ""
|
||||
for p in plots:
|
||||
outputFiles += p(connection, pathToTrace)
|
||||
if(cursor.fetchone() is None):
|
||||
outputFiles = "No output file created"
|
||||
else:
|
||||
cursor.execute(" SELECT TraceEnd FROM GeneralInfo ")
|
||||
traceEnd = float(cursor.fetchone()[0])
|
||||
cursor.execute(" SELECT min(time) FROM Power ")
|
||||
windowSize = pow(10,12)*float(cursor.fetchone()[0])
|
||||
steps = ceil(traceEnd/windowSize)
|
||||
for p in plots:
|
||||
outputFiles += p(connection, pathToTrace, steps)
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
@@ -230,6 +230,8 @@ struct Dram : sc_module
|
||||
cout << name() << string("\tTotal Energy: \t") << fixed <<std::setprecision( 2 )<< totalEnergy << string(" pJ") << endl;
|
||||
cout << name() << string("\tAverage Power: \t") << fixed <<std::setprecision( 2 )<< averagePower<< string(" mW") << endl;
|
||||
}
|
||||
else if(Configuration::getInstance().EnableWindowing)
|
||||
tlmRecorder->recordPower(powerWindowSize.to_seconds(), 0);
|
||||
|
||||
// Bandwidth:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user