One output PDF file per channel with 2 subplots.

This commit is contained in:
Éder F. Zulian
2016-02-29 09:12:27 -03:00
parent 3bee70945d
commit 569fc4aafd
2 changed files with 36 additions and 25 deletions

View File

@@ -1,5 +1,3 @@
import sys
import sqlite3
import xml.etree.ElementTree as ET

View File

@@ -2,6 +2,8 @@ import sys
import sqlite3
from memUtil import *
from math import *
import ntpath
import os
plots = []
@@ -12,7 +14,7 @@ def plot(function):
@plot
def memory_utilisation_window(connection):
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 the data from the database, DataStrobeEnd and DataStrobeBegin, it is possible to assess when a data transfer begins or ends.
@@ -25,6 +27,8 @@ def memory_utilisation_window(connection):
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
@@ -38,7 +42,7 @@ def memory_utilisation_window(connection):
bandwidthPercentage = [0] * steps
bandwidth = [0] * steps
for i in range(steps):
#print(i)
# print(i)
bandwidthPercentage[i] = 0
cursor.execute(queryPart, (i*windowSize, (i+1)*windowSize))
result = cursor.fetchone()
@@ -65,43 +69,52 @@ def memory_utilisation_window(connection):
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(1)
plt.figure()
subplotIndex = 211
plt.subplot(subplotIndex)
plt.plot(time/1000, bandwidthPercentage)
plt.xlabel('Time (ns)')
plt.ylabel('Bandwidth (%)')
plt.ylim(0, 120)
plt.grid(True)
windowPercentage = PdfPages('windowPercentage.pdf')
windowPercentage.savefig()
windowPercentage.close()
plt.figure(2)
subplotIndex += 1
plt.subplot(subplotIndex)
plt.plot(time/1000, bandwidth)
plt.xlabel('Time (ns)')
plt.ylabel('Bandwidth (Gibit/s)')
plt.grid(True)
window = PdfPages('window.pdf')
window.savefig()
window.close()
#@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"
pdf = PdfPages(OUTPUT_FILE)
pdf.savefig()
pdf.close()
# @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):
@@ -111,7 +124,7 @@ def generatePlots(pathToTrace):
print("Generating plots for {0}".format(pathToTrace))
for p in plots:
p(connection)
p(connection, pathToTrace)
connection.close()