-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsched-histo.py
executable file
·53 lines (44 loc) · 1.34 KB
/
sched-histo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import sys
import events
import math
import argparse
import filters
parser = argparse.ArgumentParser(description='Print histogram of events')
parser.add_argument('--max', '-m', type=float, default=1.0)
parser.add_argument('--sum', action='store_true')
filters.add_all_filters(parser)
args = parser.parse_args()
max_value = args.max
filter = filters.get_filter(args)
buckets = []
thresholds = []
th = 0
while True:
th = max(0.000001, th * 1.33)
thresholds.append(th)
buckets.append(0)
if th >= max_value:
break
thresholds.append(9999999999.0) # +inf
buckets.append(0)
for elem in events.get_sched_timeline(sys.stdin):
if filter(elem):
for i, th in enumerate(thresholds):
if elem.duration < th:
if args.sum:
buckets[i] += elem.duration
else:
buckets[i] += 1
break
max_count = max(buckets)
if max_count:
scale = 40.0 / max(buckets)
else:
scale = 1
print("%21s %12s" % ('duration [s]', ('count', 'sum')[args.sum]))
print("%21s %12s" % ('------------', '-----------'))
for i, count in enumerate(buckets):
count_pattern = ('%12d', '%12f')[args.sum]
print(("%20.9f: " + count_pattern + " %s") % (thresholds[i], count, '#' * int(math.ceil(scale * count))))
print("total: %10f" % (sum(buckets)))