Improved the structure of the IDLE query
This commit is contained in:
@@ -81,41 +81,45 @@ def memory_total(connection):
|
||||
def memory_idle(connection):
|
||||
# This complex query identifies idle times where the DRAM is not used.
|
||||
# The code works also if schedulers are used.
|
||||
subquery = """ -- The subquery selects all TLM phases and sorts them according to BEGIN_RESP
|
||||
SELECT
|
||||
ROW_NUMBER () OVER (
|
||||
ORDER BY q.PhaseBegin
|
||||
) RowNum,
|
||||
p.PhaseBegin AS BeginRequest,
|
||||
p.PhaseEnd AS EndRequest,
|
||||
q.PhaseBegin AS BeginResponse,
|
||||
q.PhaseEnd AS EndResponse
|
||||
|
||||
FROM
|
||||
Phases p,
|
||||
Phases q
|
||||
|
||||
WHERE
|
||||
p.PhaseName = "REQ"
|
||||
AND q.PhaseName = "RESP"
|
||||
AND p.Transact = q.Transact
|
||||
"""
|
||||
|
||||
query = """
|
||||
SELECT sum(b.BeginRequest - a.EndResponse) as idle FROM
|
||||
(
|
||||
{}
|
||||
) AS a,
|
||||
(
|
||||
{}
|
||||
) AS b
|
||||
WHERE
|
||||
(a.RowNum)=(b.RowNum-1) -- In the list of ordered transactions always compare two adjacent
|
||||
AND b.BeginRequest > a.EndResponse; -- This makes sure that no negative summands exists
|
||||
""".format(subquery, subquery)
|
||||
|
||||
cursor = connection.cursor()
|
||||
|
||||
query = """
|
||||
DROP TABLE IF EXISTS phasesInOrder;
|
||||
"""
|
||||
cursor.execute(query)
|
||||
|
||||
query = """
|
||||
-- The temporary table selects all TLM phases and sorts them according to BEGIN_RESP
|
||||
CREATE TEMPORARY TABLE phasesInOrder AS
|
||||
SELECT
|
||||
ROW_NUMBER () OVER (ORDER BY q.PhaseBegin) RowNum,
|
||||
p.PhaseBegin AS BeginRequest,
|
||||
p.PhaseEnd AS EndRequest,
|
||||
q.PhaseBegin AS BeginResponse,
|
||||
q.PhaseEnd AS EndResponse
|
||||
FROM
|
||||
Phases p,
|
||||
Phases q
|
||||
WHERE
|
||||
p.PhaseName = "REQ" AND
|
||||
q.PhaseName = "RESP" AND
|
||||
p.Transact = q.Transact;
|
||||
"""
|
||||
cursor.execute(query)
|
||||
|
||||
query = """
|
||||
|
||||
SELECT
|
||||
sum(b.BeginRequest - a.EndResponse) AS idle
|
||||
FROM
|
||||
phasesInOrder AS a, phasesInOrder AS b
|
||||
WHERE
|
||||
(a.RowNum)=(b.RowNum-1) AND -- In the list of ordered transactions always compare two adjacent
|
||||
b.BeginRequest > a.EndResponse; -- This makes sure that no negative summands exists
|
||||
"""
|
||||
cursor.execute(query)
|
||||
|
||||
idle = cursor.fetchone()
|
||||
if (idle[0] is None):
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user