PEP8 related changes.
These changes are a step forward in the direction of the PEP8 style guide for python code. They do not affect functionality itself. See also: https://www.python.org/dev/peps/pep-0008/
This commit is contained in:
@@ -4,60 +4,68 @@ import sqlite3
|
||||
metrics = []
|
||||
threadMetrics = []
|
||||
|
||||
|
||||
def metric(function):
|
||||
metrics.append(function)
|
||||
return function
|
||||
metrics.append(function)
|
||||
return function
|
||||
|
||||
|
||||
def threadMetric(function):
|
||||
threadMetrics.append(function)
|
||||
return 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
|
||||
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]
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT NumberOfBanks FROM generalInfo")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
|
||||
def getTraceLength(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT TraceEnd FROM GeneralInfo")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT TraceEnd FROM GeneralInfo")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
|
||||
def getClock(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT clk FROM GeneralInfo")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT clk FROM GeneralInfo")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
#@metric
|
||||
#def latency_histogram(connection):
|
||||
# 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"
|
||||
|
||||
#@metric
|
||||
#def average_response_latency_in_ns(connection):
|
||||
# cursor = connection.cursor()
|
||||
# cursor.execute("""SELECT avg(PhaseBegin-timeOfGeneration)/1000 FROM transactions INNER JOIN Phases
|
||||
# ON phases.transact = transactions.ID WHERE PhaseName='RESP' """)
|
||||
# @metric
|
||||
# def latency_histogram(connection):
|
||||
# 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"
|
||||
|
||||
|
||||
# @metric
|
||||
# def average_response_latency_in_ns(connection):
|
||||
# cursor = connection.cursor()
|
||||
# cursor.execute("""SELECT avg(PhaseBegin-timeOfGeneration)/1000 FROM transactions INNER JOIN Phases ON phases.transact = transactions.ID WHERE PhaseName='RESP' """)
|
||||
#
|
||||
# result = cursor.fetchone()
|
||||
# return round(result[0],1)
|
||||
# result = cursor.fetchone()
|
||||
# return round(result[0],1)
|
||||
|
||||
|
||||
@metric
|
||||
def trace_length_in_ns(connection):
|
||||
@@ -66,300 +74,308 @@ def trace_length_in_ns(connection):
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
|
||||
@metric
|
||||
def average_response_latency_in_ns(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""SELECT AVG(RESP.PHASEBEGIN - REQ.PHASEBEGIN)/1000 FROM PHASES REQ, PHASES RESP WHERE REQ.PHASENAME = 'REQ' AND RESP.PHASENAME='RESP' AND REQ.TRANSACT = RESP.TRANSACT """)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""SELECT AVG(RESP.PHASEBEGIN - REQ.PHASEBEGIN)/1000 FROM PHASES REQ, PHASES RESP WHERE REQ.PHASENAME = 'REQ' AND RESP.PHASENAME='RESP' AND REQ.TRANSACT = RESP.TRANSACT """)
|
||||
|
||||
result = cursor.fetchone()
|
||||
return round(result[0], 1)
|
||||
|
||||
result = cursor.fetchone()
|
||||
return round(result[0],1)
|
||||
|
||||
@metric
|
||||
def trans_with_max_response_latency(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT REQ.TRANSACT, max(RESP.PHASEBEGIN - REQ.PHASEBEGIN)/1000 FROM PHASES REQ, PHASES RESP WHERE REQ.PHASENAME = 'REQ' AND RESP.PHASENAME='RESP' AND REQ.TRANSACT = RESP.TRANSACT """)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT REQ.TRANSACT, max(RESP.PHASEBEGIN - REQ.PHASEBEGIN)/1000 FROM PHASES REQ, PHASES RESP WHERE REQ.PHASENAME = 'REQ' AND RESP.PHASENAME='RESP' AND REQ.TRANSACT = RESP.TRANSACT """)
|
||||
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
@metric
|
||||
def memory_active(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT sum(DataStrobeEnd - DataStrobeBegin) FROM transactions """)
|
||||
active = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT clk FROM GeneralInfo """)
|
||||
clk = cursor.fetchone()
|
||||
return (active[0]/clk[0])
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT sum(DataStrobeEnd - DataStrobeBegin) FROM transactions """)
|
||||
active = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT clk FROM GeneralInfo """)
|
||||
clk = cursor.fetchone()
|
||||
return (active[0]/clk[0])
|
||||
|
||||
|
||||
@metric
|
||||
def memory_total(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT max(DataStrobeEnd) FROM Transactions """)
|
||||
total = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT clk FROM GeneralInfo """)
|
||||
clk = cursor.fetchone()
|
||||
return (total[0]/clk[0])
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT max(DataStrobeEnd) FROM Transactions """)
|
||||
total = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT clk FROM GeneralInfo """)
|
||||
clk = cursor.fetchone()
|
||||
return (total[0]/clk[0])
|
||||
|
||||
|
||||
@metric
|
||||
def memory_idle(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT sum(p1.PhaseEnd - p2.PhaseBegin) FROM Phases p1, Phases p2 Where p1.PhaseName = "REQ" and p2.PhaseName = "RESP" and ((p1.Transact-1) = (p2.Transact)) and (p1.PhaseEnd > p2.PhaseBegin) """)
|
||||
idle = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT clk FROM GeneralInfo """)
|
||||
clk = cursor.fetchone()
|
||||
if idle[0] == None:
|
||||
return 0;
|
||||
else:
|
||||
return (idle[0]/clk[0])
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT sum(p1.PhaseEnd - p2.PhaseBegin) FROM Phases p1, Phases p2 Where p1.PhaseName = "REQ" and p2.PhaseName = "RESP" and ((p1.Transact-1) = (p2.Transact)) and (p1.PhaseEnd > p2.PhaseBegin) """)
|
||||
idle = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT clk FROM GeneralInfo """)
|
||||
clk = cursor.fetchone()
|
||||
if (idle[0] is None):
|
||||
return 0
|
||||
else:
|
||||
return (idle[0]/clk[0])
|
||||
|
||||
|
||||
@metric
|
||||
def memory_utilisation_percent_new(connection):
|
||||
total = memory_total(connection)
|
||||
active = memory_active(connection)
|
||||
idle = memory_idle(connection)
|
||||
return (active/(total-idle))*100
|
||||
total = memory_total(connection)
|
||||
active = memory_active(connection)
|
||||
idle = memory_idle(connection)
|
||||
return (active/(total-idle))*100
|
||||
|
||||
|
||||
@metric
|
||||
def memory_utilisation_percent_old(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT sum(DataStrobeEnd - DataStrobeBegin) FROM transactions """)
|
||||
active = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT max(DataStrobeEnd) FROM Transactions """)
|
||||
total = cursor.fetchone()
|
||||
return (active[0]/total[0])*100
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT sum(DataStrobeEnd - DataStrobeBegin) FROM transactions """)
|
||||
active = cursor.fetchone()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(""" SELECT max(DataStrobeEnd) FROM Transactions """)
|
||||
total = cursor.fetchone()
|
||||
return (active[0]/total[0])*100
|
||||
|
||||
|
||||
def refreshMissDecision(connection, calculatedMetrics):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""SELECT phases.ID,PhaseBegin,PhaseEnd,TBank FROM Phases INNER JOIN transactions on transactions.id = phases.transact WHERE PhaseName='AUTO_REFRESH' """)
|
||||
queryMinREQ = """SELECT id,min(PhaseBegin) FROM (SELECT transactions.id, PhaseBegin FROM transactions
|
||||
inner join ranges on ranges.id = transactions.range inner join phases on phases.transact = transactions.id
|
||||
where tthread != 0 and tbank = :bank and PhaseName = "REQ" and ranges.begin<:begin and ranges.end>:end)"""
|
||||
|
||||
def refreshMissDecision(connection,calculatedMetrics):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""SELECT phases.ID,PhaseBegin,PhaseEnd,TBank FROM Phases INNER JOIN transactions on transactions.id = phases.transact WHERE PhaseName='AUTO_REFRESH' """)
|
||||
queryMinREQ = """SELECT id,min(PhaseBegin) FROM (SELECT transactions.id, PhaseBegin FROM transactions
|
||||
inner join ranges on ranges.id = transactions.range inner join phases on phases.transact = transactions.id
|
||||
where tthread != 0 and tbank = :bank and PhaseName = "REQ" and ranges.begin<:begin and ranges.end>:end)"""
|
||||
|
||||
queryMinRESP = """SELECT id,min(PhaseBegin) FROM (SELECT transactions.id, PhaseBegin FROM transactions
|
||||
inner join ranges on ranges.id = transactions.range inner join phases on phases.transact = transactions.id
|
||||
where tthread != 0 and tbank = :bank and PhaseName = "RESP" and ranges.begin<:begin and ranges.end>:end) """
|
||||
queryMinRESP = """SELECT id,min(PhaseBegin) FROM (SELECT transactions.id, PhaseBegin FROM transactions
|
||||
inner join ranges on ranges.id = transactions.range inner join phases on phases.transact = transactions.id
|
||||
where tthread != 0 and tbank = :bank and PhaseName = "RESP" and ranges.begin<:begin and ranges.end>:end) """
|
||||
|
||||
missDecisions = 0
|
||||
totalDecisios = 0
|
||||
missDecisions = 0
|
||||
totalDecisios = 0
|
||||
|
||||
for refresh in cursor:
|
||||
id = refresh[0]
|
||||
begin = refresh[1]
|
||||
end = refresh[2]
|
||||
bank = refresh[3]
|
||||
#print('Refresh: {0} {1} {2} {3}'.format(id,begin,end,bank))
|
||||
|
||||
cursorMinREQ = connection.cursor()
|
||||
cursorMinRESP = connection.cursor()
|
||||
|
||||
cursorMinREQ.execute(queryMinREQ, {"bank":bank, "begin":begin, "end":end})
|
||||
cursorMinRESP.execute(queryMinRESP, {"bank":bank, "begin":begin, "end":end})
|
||||
for refresh in cursor:
|
||||
id = refresh[0]
|
||||
begin = refresh[1]
|
||||
end = refresh[2]
|
||||
bank = refresh[3]
|
||||
# print('Refresh: {0} {1} {2} {3}'.format(id,begin,end,bank))
|
||||
|
||||
earliestReq = cursorMinREQ.fetchone()
|
||||
earliestResp = cursorMinRESP.fetchone()
|
||||
if(earliestReq[0] != None):
|
||||
totalDecisios = totalDecisios + 1
|
||||
cursorMinREQ = connection.cursor()
|
||||
cursorMinRESP = connection.cursor()
|
||||
|
||||
cursorMinREQ.execute(queryMinREQ, {"bank": bank, "begin": begin, "end": end})
|
||||
cursorMinRESP.execute(queryMinRESP, {"bank": bank, "begin": begin, "end": end})
|
||||
|
||||
earliestReq = cursorMinREQ.fetchone()
|
||||
earliestResp = cursorMinRESP.fetchone()
|
||||
if (earliestReq[0] is not None):
|
||||
totalDecisios = totalDecisios + 1
|
||||
if(earliestReq[0] != earliestResp[0]):
|
||||
missDecisions = missDecisions + 1
|
||||
#print("earliest Req: {0}| earliest Res: {1}".format(earliestReq[0], earliestResp[0]))
|
||||
end
|
||||
missDecisions = missDecisions + 1
|
||||
# print("earliest Req: {0}| earliest Res: {1}".format(earliestReq[0], earliestResp[0]))
|
||||
|
||||
if (totalDecisios != 0):
|
||||
# calculatedMetrics.append(("Total Missdecisions", missDecisions))
|
||||
calculatedMetrics.append(("Relative Missdecisions", 1.0*missDecisions/totalDecisios))
|
||||
else:
|
||||
calculatedMetrics.append(("Total Missdecisions", 0))
|
||||
calculatedMetrics.append(("Relative Missdecisions", 0))
|
||||
|
||||
|
||||
if(totalDecisios != 0):
|
||||
#calculatedMetrics.append(("Total Missdecisions", missDecisions))
|
||||
calculatedMetrics.append(("Relative Missdecisions", 1.0*missDecisions/totalDecisios))
|
||||
else:
|
||||
calculatedMetrics.append(("Total Missdecisions", 0))
|
||||
calculatedMetrics.append(("Relative Missdecisions", 0))
|
||||
|
||||
@threadMetric
|
||||
def average_response_latency_in_ns(connection, thread):
|
||||
cursor = connection.cursor()
|
||||
query = """SELECT avg(PhaseBegin-timeOfGeneration)/1000 FROM transactions INNER JOIN Phases
|
||||
ON phases.transact = transactions.ID WHERE PhaseName='RESP' AND TThread = :Thread """
|
||||
cursor = connection.cursor()
|
||||
query = """SELECT avg(PhaseBegin-timeOfGeneration)/1000 FROM transactions INNER JOIN Phases
|
||||
ON phases.transact = transactions.ID WHERE PhaseName='RESP' AND TThread = :Thread """
|
||||
|
||||
cursor.execute(query, {"Thread": thread})
|
||||
result = cursor.fetchone()
|
||||
return round(result[0],1)
|
||||
cursor.execute(query, {"Thread": thread})
|
||||
result = cursor.fetchone()
|
||||
return round(result[0], 1)
|
||||
|
||||
def addStallTime(times,begin,end):
|
||||
time = begin
|
||||
while time <= end:
|
||||
if(time in times):
|
||||
times[time] = times[time] + 1
|
||||
else:
|
||||
times[time] = 1
|
||||
time = time + 1
|
||||
|
||||
#@threadMetric
|
||||
def addStallTime(times, begin, end):
|
||||
time = begin
|
||||
while time <= end:
|
||||
if(time in times):
|
||||
times[time] = times[time] + 1
|
||||
else:
|
||||
times[time] = 1
|
||||
time = time + 1
|
||||
|
||||
|
||||
# @threadMetric
|
||||
def paralellism(connection, thread):
|
||||
cursor = connection.cursor()
|
||||
stalltimes = {}
|
||||
query = """SELECT transactions.ID,MIN(phaseBegin)/:clk,MAX(phaseEnd)/:clk
|
||||
from phases inner join transactions on phases.transact=transactions.id
|
||||
where phaseName Not in ('REQ','RESP') and tthread=:Thread group by transactions.ID """
|
||||
cursor = connection.cursor()
|
||||
stalltimes = {}
|
||||
query = """SELECT transactions.ID,MIN(phaseBegin)/:clk,MAX(phaseEnd)/:clk
|
||||
from phases inner join transactions on phases.transact=transactions.id
|
||||
where phaseName Not in ('REQ','RESP') and tthread=:Thread group by transactions.ID """
|
||||
|
||||
cursor.execute(query, {"Thread": thread, "clk": getClock(connection)})
|
||||
for currentRow in cursor:
|
||||
addStallTime(stalltimes, currentRow[1], currentRow[2])
|
||||
para = 0
|
||||
for time in stalltimes:
|
||||
para = para + stalltimes[time]
|
||||
return round(para/len(stalltimes), 2)
|
||||
|
||||
cursor.execute(query, {"Thread": thread, "clk" : getClock(connection)})
|
||||
for currentRow in cursor:
|
||||
addStallTime(stalltimes,currentRow[1],currentRow[2])
|
||||
para = 0
|
||||
for time in stalltimes:
|
||||
para = para + stalltimes[time]
|
||||
return round(para/len(stalltimes),2)
|
||||
|
||||
@metric
|
||||
def number_of_activates(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName = 'ACT'")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName = 'ACT'")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
|
||||
|
||||
@metric
|
||||
def number_of_accesses(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName IN ('REQ')")
|
||||
result = cursor.fetchone()
|
||||
return result[0]
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName IN ('REQ')")
|
||||
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]
|
||||
# cursor = connection.cursor()
|
||||
# cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName IN ('PRE','PRE_ALL','RDA','WRA')")
|
||||
# result = cursor.fetchone()
|
||||
# return result[0]
|
||||
|
||||
|
||||
@metric
|
||||
def accesses_per_activate(connection):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName IN ('REQ')")
|
||||
result = cursor.fetchone()
|
||||
return round(result[0]*1.0/number_of_activates(connection),1)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM Phases WHERE PhaseName IN ('REQ')")
|
||||
result = cursor.fetchone()
|
||||
return round(result[0]*1.0/number_of_activates(connection), 1)
|
||||
|
||||
|
||||
@metric
|
||||
def timeInPowerStates(connection):
|
||||
totalTimeAllBanks = getTraceLength(connection)#*getNumberOfBanks(connection)
|
||||
cursor = connection.cursor()
|
||||
result = []
|
||||
totalTimeAllBanks = getTraceLength(connection) # *getNumberOfBanks(connection)
|
||||
cursor = connection.cursor()
|
||||
result = []
|
||||
|
||||
cursor.execute("SELECT SUM(PhaseEnd-PhaseBegin) from Phases where PhaseName = 'PDNA'")
|
||||
timeInPDNA = cursor.fetchone()
|
||||
totalTimeInPDNA = timeInPDNA[0]
|
||||
if(totalTimeInPDNA == None):
|
||||
totalTimeInPDNA = 0.0
|
||||
fractionInPDNA = totalTimeInPDNA*1.0/totalTimeAllBanks
|
||||
result.append(("Time in PDNA (%)", fractionInPDNA*100))
|
||||
print("{0} {1}".format(result[-1][0],result[-1][1]))
|
||||
cursor.execute("SELECT SUM(PhaseEnd-PhaseBegin) from Phases where PhaseName = 'PDNA'")
|
||||
timeInPDNA = cursor.fetchone()
|
||||
totalTimeInPDNA = timeInPDNA[0]
|
||||
if (totalTimeInPDNA is None):
|
||||
totalTimeInPDNA = 0.0
|
||||
fractionInPDNA = totalTimeInPDNA*1.0/totalTimeAllBanks
|
||||
result.append(("Time in PDNA (%)", fractionInPDNA*100))
|
||||
print("{0} {1}".format(result[-1][0], result[-1][1]))
|
||||
|
||||
cursor.execute("SELECT SUM(PhaseEnd-PhaseBegin) from Phases where PhaseName = 'PDNP'")
|
||||
timeInPDNP = cursor.fetchone()
|
||||
totalTimeInPDNP = timeInPDNP[0]
|
||||
if(totalTimeInPDNP == None):
|
||||
totalTimeInPDNP = 0.0
|
||||
fractionInPDNP = totalTimeInPDNP*1.0/totalTimeAllBanks
|
||||
result.append(("Time in PDNP (%)", fractionInPDNP*100))
|
||||
print("{0} {1}".format(result[-1][0],result[-1][1]))
|
||||
cursor.execute("SELECT SUM(PhaseEnd-PhaseBegin) from Phases where PhaseName = 'PDNP'")
|
||||
timeInPDNP = cursor.fetchone()
|
||||
totalTimeInPDNP = timeInPDNP[0]
|
||||
if (totalTimeInPDNP is None):
|
||||
totalTimeInPDNP = 0.0
|
||||
fractionInPDNP = totalTimeInPDNP*1.0/totalTimeAllBanks
|
||||
result.append(("Time in PDNP (%)", fractionInPDNP*100))
|
||||
print("{0} {1}".format(result[-1][0], result[-1][1]))
|
||||
|
||||
cursor.execute("SELECT SUM(PhaseEnd-PhaseBegin) from Phases where PhaseName = 'SREF'")
|
||||
timeInSREF = cursor.fetchone()
|
||||
totalTimeInSREF = timeInSREF[0]
|
||||
if(totalTimeInSREF == None):
|
||||
totalTimeInSREF = 0.0
|
||||
fractionInSREF = totalTimeInSREF*1.0/totalTimeAllBanks
|
||||
result.append(("Time in SREF (%)", fractionInSREF*100))
|
||||
print("{0} {1}".format(result[-1][0],result[-1][1]))
|
||||
result.insert(0,("Active time (%)", (1-fractionInPDNA-fractionInPDNP-fractionInSREF)*100))
|
||||
print("{0} {1}".format(result[0][0],result[0][1]))
|
||||
cursor.execute("SELECT SUM(PhaseEnd-PhaseBegin) from Phases where PhaseName = 'SREF'")
|
||||
timeInSREF = cursor.fetchone()
|
||||
totalTimeInSREF = timeInSREF[0]
|
||||
if (totalTimeInSREF is None):
|
||||
totalTimeInSREF = 0.0
|
||||
fractionInSREF = totalTimeInSREF*1.0/totalTimeAllBanks
|
||||
result.append(("Time in SREF (%)", fractionInSREF*100))
|
||||
print("{0} {1}".format(result[-1][0], result[-1][1]))
|
||||
result.insert(0, ("Active time (%)", (1-fractionInPDNA-fractionInPDNP-fractionInSREF)*100))
|
||||
print("{0} {1}".format(result[0][0], result[0][1]))
|
||||
|
||||
return result
|
||||
|
||||
return result
|
||||
|
||||
def passRatio(connection):
|
||||
|
||||
numberOfPassWins = {}
|
||||
numberOfPassLosses = {}
|
||||
numberOfPassWins = {}
|
||||
numberOfPassLosses = {}
|
||||
|
||||
for thread in getThreads(connection):
|
||||
numberOfPassWins[thread] = 0
|
||||
numberOfPassLosses[thread] = 0
|
||||
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 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):
|
||||
totalPassedInvolved = numberOfPassWins[thread]+numberOfPassLosses[thread]
|
||||
if(totalPassedInvolved > 0):
|
||||
passRatio = numberOfPassWins[thread]*1.0/(numberOfPassWins[thread]+numberOfPassLosses[thread])
|
||||
else:
|
||||
passRatio = 0.5
|
||||
print("Thread {0} passed other threads {1} times and was passed {2} times. Pass ratio is {3}".format
|
||||
(thread, numberOfPassWins[thread], numberOfPassLosses[thread],passRatio))
|
||||
result.append(("Thread {0} pass ratio".format(thread), passRatio))
|
||||
return result
|
||||
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):
|
||||
totalPassedInvolved = numberOfPassWins[thread]+numberOfPassLosses[thread]
|
||||
if(totalPassedInvolved > 0):
|
||||
passRatio = numberOfPassWins[thread]*1.0/(numberOfPassWins[thread]+numberOfPassLosses[thread])
|
||||
else:
|
||||
passRatio = 0.5
|
||||
print("Thread {0} passed other threads {1} times and was passed {2} times. Pass ratio is {3}".format(thread, numberOfPassWins[thread], numberOfPassLosses[thread], passRatio))
|
||||
result.append(("Thread {0} pass ratio".format(thread), passRatio))
|
||||
return result
|
||||
|
||||
|
||||
def calculateMetrics(pathToTrace):
|
||||
connection = sqlite3.connect(pathToTrace)
|
||||
calculatedMetrics = []
|
||||
connection = sqlite3.connect(pathToTrace)
|
||||
calculatedMetrics = []
|
||||
|
||||
print("================================")
|
||||
print("Calculating metrics for {0}".format(pathToTrace))
|
||||
print("================================")
|
||||
print("Calculating metrics for {0}".format(pathToTrace))
|
||||
|
||||
if (len(getThreads(connection)) == 1):
|
||||
for metric in metrics:
|
||||
res = (metric.__name__.replace("_", " "), metric(connection))
|
||||
print("{0}: {1}".format(res[0], res[1]))
|
||||
calculatedMetrics.append(res)
|
||||
|
||||
if(len(getThreads(connection))==1):
|
||||
for metric in metrics:
|
||||
res = (metric.__name__.replace("_"," "), metric(connection))
|
||||
print("{0}: {1}".format(res[0],res[1]))
|
||||
calculatedMetrics.append(res)
|
||||
if (len(getThreads(connection)) > 1):
|
||||
# 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))
|
||||
# refreshMissDecision(connection, calculatedMetrics)
|
||||
|
||||
if(len(getThreads(connection))>1):
|
||||
# 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))
|
||||
#refreshMissDecision(connection, calculatedMetrics)
|
||||
# calculatedMetrics.extend(timeInPowerStates(connection))
|
||||
# print(calculatedMetrics[-1])
|
||||
# print(calculatedMetrics[-2])
|
||||
|
||||
#calculatedMetrics.extend(timeInPowerStates(connection))
|
||||
#print(calculatedMetrics[-1])
|
||||
#print(calculatedMetrics[-2])
|
||||
|
||||
#refreshMissDecision(connection, calculatedMetrics)
|
||||
print(calculatedMetrics[-1])
|
||||
print(calculatedMetrics[-2])
|
||||
connection.close()
|
||||
return calculatedMetrics
|
||||
# refreshMissDecision(connection, calculatedMetrics)
|
||||
print(calculatedMetrics[-1])
|
||||
print(calculatedMetrics[-2])
|
||||
connection.close()
|
||||
return calculatedMetrics
|
||||
|
||||
if __name__ == "__main__":
|
||||
path = sys.argv[1]
|
||||
calculateMetrics(path)
|
||||
|
||||
path = sys.argv[1]
|
||||
calculateMetrics(path)
|
||||
|
||||
Reference in New Issue
Block a user