133 lines
4.6 KiB
Python
133 lines
4.6 KiB
Python
import sys
|
|
import sqlite3
|
|
|
|
metrics = []
|
|
threadMetrics = []
|
|
|
|
def metric(function):
|
|
metrics.append(function)
|
|
return function
|
|
|
|
def threadMetric(function):
|
|
threadMetrics.append(function)
|
|
return function
|
|
|
|
def getThreads(connection):
|
|
cursor = connection.cursor()
|
|
cursor.execute("SELECT DISTINCT(TThread) FROM transactions WHERE TThread != 0 ORDER BY TThread")
|
|
result = []
|
|
for currentRow in cursor:
|
|
result.append(currentRow[0])
|
|
return result
|
|
|
|
def getNumberOfBanks(connection):
|
|
cursor = connection.cursor()
|
|
cursor.execute("SELECT NumberOfBanks FROM generalInfo")
|
|
result = cursor.fetchone()
|
|
return result[0]
|
|
|
|
|
|
@metric
|
|
def average_response_latency_in_ns(connection):
|
|
cursor = connection.cursor()
|
|
cursor.execute("""SELECT avg(ranges.end-ranges.begin) FROM transactions INNER JOIN ranges
|
|
ON transactions.range = ranges.ID where TThread != 0""")
|
|
|
|
result = cursor.fetchone()
|
|
return round(result[0],1)
|
|
|
|
@threadMetric
|
|
def average_response_latency_in_ns(connection, thread):
|
|
cursor = connection.cursor()
|
|
query = """SELECT avg(ranges.end-ranges.begin) FROM transactions INNER JOIN ranges
|
|
ON transactions.range = ranges.ID where TThread = :Thread """
|
|
|
|
cursor.execute(query, {"Thread": thread})
|
|
result = cursor.fetchone()
|
|
return round(result[0],1)
|
|
|
|
@metric
|
|
def number_of_activates(connection):
|
|
cursor = connection.cursor()
|
|
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName = 'ACT'")
|
|
result = cursor.fetchone()
|
|
return result[0]
|
|
|
|
@metric
|
|
def number_of_precharges(connection):
|
|
cursor = connection.cursor()
|
|
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName IN ('PRE','PRE_ALL','RDA','WRA')")
|
|
result = cursor.fetchone()
|
|
return result[0]
|
|
|
|
def passRatio(connection):
|
|
|
|
numberOfPassWins = {}
|
|
numberOfPassLosses = {}
|
|
|
|
for thread in getThreads(connection):
|
|
numberOfPassWins[thread] = 0
|
|
numberOfPassLosses[thread] = 0
|
|
|
|
for bankNumber in range(getNumberOfBanks(connection)):
|
|
cursor = connection.cursor()
|
|
query = """SELECT begin,end,transactions.ID,TThread,
|
|
TBank from transactions inner join ranges on transactions.range = ranges.id WHERE TBank = :Bank AND TThread != 0"""
|
|
cursor.execute(query, {"Bank":bankNumber})
|
|
|
|
for passedRequest in cursor:
|
|
passedBegin = passedRequest[0]
|
|
passedEnd = passedRequest[1]
|
|
passedId = passedRequest[2]
|
|
passedThread = passedRequest[3]
|
|
|
|
cursor2 = connection.cursor()
|
|
query2 = """SELECT begin,end,transactions.ID,TThread,
|
|
TBank from transactions inner join ranges on transactions.range = ranges.id
|
|
WHERE TBank = :Bank AND :Begin<begin AND end<:End AND TThread != :Thread AND TThread != 0"""
|
|
cursor2.execute(query2, {"Bank" : bankNumber, "Thread": passedThread, "Begin" : passedBegin, "End" : passedEnd})
|
|
|
|
for passingRequest in cursor2:
|
|
numberOfPassLosses[passedThread] += 1
|
|
numberOfPassWins[passingRequest[3]] += 1
|
|
# print("""Transaction {0} (thread:{1} begin:{2} end:{3}) was passed by Transaction {4} (thread:{5} begin:{6} end:{7}) on bank {8}""".format(passedId,passedThread, passedBegin,passedEnd,
|
|
# passingRequest[2], passingRequest[3], passingRequest[0], passingRequest[1], bankNumber))
|
|
|
|
result = []
|
|
for thread in getThreads(connection):
|
|
print("Thread {0} passed other threads {1} times and was passed {2} times. Ratio is {3}".format
|
|
(thread, numberOfPassWins[thread], numberOfPassLosses[thread], numberOfPassWins[thread]*1.0/(numberOfPassWins[thread]+numberOfPassLosses[thread])))
|
|
result.append(("Thread {0} pass ratio".format(thread), numberOfPassWins[thread]*1.0/(numberOfPassWins[thread]+numberOfPassLosses[thread])))
|
|
return result
|
|
|
|
|
|
|
|
def calculateMetrics(pathToTrace):
|
|
connection = sqlite3.connect(pathToTrace)
|
|
calculatedMetrics = []
|
|
|
|
print("================================")
|
|
print("Calculating metrics for {0}".format(pathToTrace))
|
|
|
|
|
|
for metric in metrics:
|
|
res = (metric.__name__.replace("_"," "), metric(connection))
|
|
print("{0}: {1}".format(res[0],res[1]))
|
|
calculatedMetrics.append(res)
|
|
|
|
for thread in getThreads(connection):
|
|
for metric in threadMetrics:
|
|
res = ("Thread " + str(thread) + " " + metric.__name__.replace("_"," "), metric(connection, thread))
|
|
print("{0}: {1}".format(res[0],res[1]))
|
|
calculatedMetrics.append(res)
|
|
|
|
calculatedMetrics.extend(passRatio(connection))
|
|
|
|
|
|
connection.close()
|
|
return calculatedMetrics
|
|
|
|
if __name__ == "__main__":
|
|
path = sys.argv[1]
|
|
calculateMetrics(path)
|
|
|