44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
import sys
|
|
import sqlite3
|
|
|
|
|
|
metrics = []
|
|
|
|
def metric(function):
|
|
metrics.append(function)
|
|
return function
|
|
|
|
@metric
|
|
def average_response_latency(connection):
|
|
cursor = connection.cursor()
|
|
cursor.execute("SELECT avg(end-begin) FROM ranges")
|
|
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]
|
|
|
|
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)
|
|
|
|
connection.close()
|
|
return calculatedMetrics
|
|
|
|
if __name__ == "__main__":
|
|
path = sys.argv[1]
|
|
calculateMetrics(path)
|
|
|