From d0f500119edaccc2d056414213c22b2731d5f2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89der=20F=2E=20Zulian?= Date: Thu, 2 Aug 2018 15:35:49 +0200 Subject: [PATCH] Improvement Reusing code instead of replicating it. --- DRAMSys/traceAnalyzer/scripts/metrics.py | 28 +++++++++--------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/DRAMSys/traceAnalyzer/scripts/metrics.py b/DRAMSys/traceAnalyzer/scripts/metrics.py index a06997af..460c3f33 100644 --- a/DRAMSys/traceAnalyzer/scripts/metrics.py +++ b/DRAMSys/traceAnalyzer/scripts/metrics.py @@ -73,10 +73,8 @@ 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]) + clk, unit = getClock(connection) + return (active[0]/clk) @metric @@ -84,10 +82,8 @@ 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]) + clk, unit = getClock(connection) + return (total[0]/clk) @metric @@ -95,13 +91,11 @@ 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] is None): return 0 else: - return (idle[0]/clk[0]) + clk, unit = getClock(connection) + return (idle[0]/clk) @metric @@ -249,14 +243,12 @@ def number_of_refreshes(connection): @metric def bank_overlap_ratio(connection): # Calculates how many banks are open in parallel - cursor = connection.cursor() - cursor.execute("SELECT clk FROM GeneralInfo ") - clk = cursor.fetchone() + clk, unit = getClock(connection) + cursor = connection.cursor() cursor.execute("select TraceEnd from GeneralInfo") traceEndTMP = cursor.fetchone() - traceEnd = int(traceEndTMP[0]/clk[0]) - + traceEnd = int(traceEndTMP[0]/clk) trace = [] cursor.execute(""" @@ -269,7 +261,7 @@ def bank_overlap_ratio(connection): prevTime = 0 for c in cursor: - trace.append([(int(c[0]/clk[0])), c[1]]) + trace.append([(int(c[0]/clk)), c[1]]) # Insert a pseudo precharge all to mark the end of the trace trace.append([traceEnd, "PRE_ALL"])