Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SQLCounter(object):
- @classmethod
- def clear_data(cls):
- cls.current_code = ‘’
- cls.check = False
- cls.data = defaultdict(list)
- cls.hit_count = defaultdict(int)
- @classmethod
- def before(cls, activity, lineno, colno):
- cls.check = True
- cls.current_code = (“line no {:<4}: {}”.format(lineno, activity),
- lineno)
- cls.hit_count[cls.current_code] += 1
- @classmethod
- def after(cls, activity, lineno, colno):
- cls.check = False
- @classmethod
- def insert(cls, data):
- cls.data[cls.current_code].append(data)
- @classmethod
- def current_func(cls, func):
- cls.func = func
- @classmethod
- def show_data(cls):
- if not cls.data:
- return
- data = sorted(cls.data.items(),key=lambda a: a[0][1])
- table = []
- headers = [‘Location’, ‘Hit’, ‘Queries’, ‘Time (ms)’, ‘Avg Time (ms)’]
- total_tm = 0.0
- total_qs = 0
- for current_code, qdata in data:
- activity, _ = current_code
- qs = len(qdata)
- total_qs += qs
- tm = sum(k[‘time’] for k in qdata)
- total_tm += tm
- avg_tm = tm / qs
- hit = cls.hit_count[current_code]
- table.append([activity, hit, qs, tm, avg_tm])
- print “Total SQL queries: {}, Total time: {} ms”.format(
- total_qs, total_tm)
- tabular_table = tabulate(table, headers, tablefmt=”simple”)
- print tabular_table
Add Comment
Please, Sign In to add comment