2016-07-28 01:41:28 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
from collections import defaultdict
|
2016-10-16 07:27:55 +02:00
|
|
|
from typing import Any, Dict, Iterable
|
2016-07-28 01:41:28 +02:00
|
|
|
import ujson
|
|
|
|
|
|
|
|
def analyze_url_coverage():
|
2016-10-16 07:27:55 +02:00
|
|
|
# type: () -> None
|
2016-07-28 01:41:28 +02:00
|
|
|
fn = 'var/url_coverage.txt' # TODO: make path more robust, maybe use json suffix
|
|
|
|
calls = []
|
|
|
|
for line in open(fn):
|
|
|
|
calls.append(ujson.loads(line))
|
|
|
|
|
|
|
|
show_slow_endpoints(calls)
|
|
|
|
show_best_coverage(calls)
|
|
|
|
show_which_tests_ran_endpoints(calls)
|
|
|
|
|
|
|
|
def show_slow_endpoints(calls):
|
2016-10-16 07:27:55 +02:00
|
|
|
# type: (Iterable[Dict[str, Any]]) -> None
|
2016-07-28 01:41:28 +02:00
|
|
|
tups = []
|
|
|
|
for call in calls:
|
|
|
|
tups.append((call['delay'], call['url'], call['method']))
|
|
|
|
|
|
|
|
tups.sort(reverse=True)
|
|
|
|
|
|
|
|
num = 10
|
|
|
|
print('%d slowest endpoints' % (num,))
|
|
|
|
|
|
|
|
for delay, url, method in tups[:num]:
|
|
|
|
print('%.03f %s %s' % (delay, url, method))
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
def show_best_coverage(calls):
|
2016-10-16 07:27:55 +02:00
|
|
|
# type: (Iterable[Dict[str, Any]]) -> None
|
2016-07-28 01:41:28 +02:00
|
|
|
count = defaultdict(int) # type: Dict[str, int]
|
|
|
|
|
|
|
|
for call in calls:
|
|
|
|
count[call['url']] += 1
|
|
|
|
|
|
|
|
counts = [(v, k) for k, v in count.items()]
|
|
|
|
counts.sort(reverse=True)
|
|
|
|
num = 10
|
|
|
|
|
|
|
|
print('%d best covered endpoints' % (num,))
|
|
|
|
for cnt, url in counts[:num]:
|
|
|
|
print('%3d %s' % (cnt, url))
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
def show_which_tests_ran_endpoints(calls):
|
2016-10-16 07:27:55 +02:00
|
|
|
# type: (Iterable[Dict[str, Any]]) -> None
|
2016-07-28 01:41:28 +02:00
|
|
|
test_name_dct = defaultdict(list) # type: Dict[str, List[str]]
|
|
|
|
|
|
|
|
for call in calls:
|
|
|
|
url = call['url']
|
|
|
|
test_name_dct[url].append(call['test_name'])
|
|
|
|
|
|
|
|
for k in sorted(test_name_dct):
|
|
|
|
print(k)
|
|
|
|
for test_name in sorted(test_name_dct[k]):
|
|
|
|
print(' %s' % (test_name,))
|
|
|
|
print()
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
analyze_url_coverage()
|