Merge branch 'traceAnalyzer/metrics_argparse' into 'develop'
Added metric selection through command-line See merge request ems/astdm/dram.sys!296
This commit is contained in:
@@ -909,6 +909,71 @@ def calculateMetrics(pathToTrace, selectedMetrics=[]):
|
||||
connection.close()
|
||||
return calculatedMetrics
|
||||
|
||||
def calculateMetricsFromFuncs(pathToTrace, selectedMetrics):
|
||||
|
||||
calculatedMetrics = []
|
||||
connection = sqlite3.connect(pathToTrace)
|
||||
|
||||
mcconfig = MCConfig(connection)
|
||||
|
||||
print("================================")
|
||||
print("Calculating metrics for {0}".format(pathToTrace))
|
||||
|
||||
print("Number of threads is {0}".format(len(getThreads(connection))))
|
||||
|
||||
if not selectedMetrics:
|
||||
selectedMetrics = [0] * (len(metrics) + len(getThreads(connection))*len(threadMetrics) + 1)
|
||||
for i in range(len(selectedMetrics)):
|
||||
selectedMetrics[i] = True
|
||||
|
||||
for metric in selectedMetrics:
|
||||
mres = metric(connection)
|
||||
mname = metric.__name__.replace("_", " ")
|
||||
res = (mname, mres)
|
||||
|
||||
if (metric.__name__ == "bank_overlap_ratio"):
|
||||
values = mres.split(",")
|
||||
nbanks = 0
|
||||
for v in values:
|
||||
name = mname + " (" + str(nbanks) + " banks active)"
|
||||
nbanks = nbanks + 1
|
||||
r = (name, float(v))
|
||||
calculatedMetrics.append(r)
|
||||
else:
|
||||
calculatedMetrics.append(res)
|
||||
|
||||
print("{0}: {1}".format(res[0], res[1]))
|
||||
|
||||
# refreshMissDecision(connection, calculatedMetrics)
|
||||
connection.close()
|
||||
return calculatedMetrics
|
||||
|
||||
import argparse
|
||||
|
||||
if __name__ == "__main__":
|
||||
path = sys.argv[1]
|
||||
calculateMetrics(path)
|
||||
"""
|
||||
Only non-threaded metrics are implemented for selection through command line
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="Calculates metrics of a given .tdb file")
|
||||
|
||||
parser.add_argument('path', type=str, help="The path to the .tdb file to be used")
|
||||
|
||||
dic_metric_functions = {}
|
||||
for m in metrics:
|
||||
parser.add_argument("--"+m.__name__, action='store_true')
|
||||
dic_metric_functions[m.__name__] = m
|
||||
|
||||
arg_namespace = parser.parse_args(sys.argv[1:])
|
||||
|
||||
selected_metrics = []
|
||||
for k, v in arg_namespace.__dict__.items():
|
||||
if k == 'path':
|
||||
continue
|
||||
if v:
|
||||
selected_metrics.append(dic_metric_functions[k])
|
||||
|
||||
|
||||
if selected_metrics == []:
|
||||
calculateMetrics(arg_namespace.path)
|
||||
else:
|
||||
calculateMetricsFromFuncs(arg_namespace.path, selected_metrics)
|
||||
|
||||
Reference in New Issue
Block a user