Commit da65d353 authored by Hanno Schlichting's avatar Hanno Schlichting

Finish the switch to named tuples

parent 84ae8cea
...@@ -110,6 +110,8 @@ Duration = namedtuple('Duration', ['start', 'end']) ...@@ -110,6 +110,8 @@ Duration = namedtuple('Duration', ['start', 'end'])
IndexMeasurement = namedtuple('IndexMeasurement', IndexMeasurement = namedtuple('IndexMeasurement',
['name', 'duration', 'num']) ['name', 'duration', 'num'])
Benchmark = namedtuple('Benchmark', ['num', 'duration', 'hits']) Benchmark = namedtuple('Benchmark', ['num', 'duration', 'hits'])
RecentQuery = namedtuple('RecentQuery', ['duration', 'details'])
Report = namedtuple('Report', ['hits', 'duration', 'last'])
class CatalogPlan(object): class CatalogPlan(object):
...@@ -231,7 +233,7 @@ class CatalogPlan(object): ...@@ -231,7 +233,7 @@ class CatalogPlan(object):
return return
key = self.key key = self.key
res = (total, self.res) recent = RecentQuery(duration=total, details=self.res)
reports_lock.acquire() reports_lock.acquire()
try: try:
...@@ -242,9 +244,9 @@ class CatalogPlan(object): ...@@ -242,9 +244,9 @@ class CatalogPlan(object):
if previous: if previous:
counter, mean, last = previous counter, mean, last = previous
mean = (mean * counter + total) / float(counter + 1) mean = (mean * counter + total) / float(counter + 1)
reports[self.cid][key] = (counter + 1, mean, res) reports[self.cid][key] = Report(counter + 1, mean, recent)
else: else:
reports[self.cid][key] = (1, total, res) reports[self.cid][key] = Report(1, total, recent)
finally: finally:
reports_lock.release() reports_lock.release()
...@@ -256,34 +258,21 @@ class CatalogPlan(object): ...@@ -256,34 +258,21 @@ class CatalogPlan(object):
reports_lock.release() reports_lock.release()
def report(self): def report(self):
"""Returns a statistic report of catalog queries as list of dicts as """Returns a statistic report of catalog queries as list of dicts.
follows:
[{'query': <query_key>,
'counter': <hits>
'duration': <mean duration>,
'last': <details of recent query>,
},
...
]
<details of recent query> := {'duration': <duration of last query>,
'details': <duration of single indexes>,
}
The duration is provided in millisecond. The duration is provided in millisecond.
""" """
rval = [] rval = []
for k, v in reports.get(self.cid, {}).items(): for key, report in reports.get(self.cid, {}).items():
last = report.last
info = { info = {
'query': k, 'query': key,
'counter': v[0], 'counter': report.hits,
'duration': v[1] * 1000, 'duration': report.duration * 1000,
'last': {'duration': v[2][0] * 1000, 'last': {'duration': last.duration * 1000,
'details': [dict(id=i.name, 'details': [dict(id=d.name,
duration=i.duration * 1000, duration=d.duration * 1000,
length=i.num) length=d.num)
for i in v[2][1]], for d in last.details],
}, },
} }
rval.append(info) rval.append(info)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment