forked from marxin/script-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcov-dump-dynamic.py
executable file
·89 lines (83 loc) · 4.1 KB
/
gcov-dump-dynamic.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
import os
import subprocess
import sys
counter = 0
location = sys.argv[1]
needles = ['indirect_call', 'topn']
threshold = 0.25
max_nodes = 32
interesting_coverage = .3
if len(sys.argv) == 3:
threshold = float(sys.argv[2])
print('Covered threshold: %.2f' % threshold)
print('== Stats for %s ==' % location)
for needle in needles:
print('stats for %s:' % needle)
histogram = {}
full_counters = []
counter_count = 0
total_freq = 0
total_freq_with_half = 0
total_tuples = 0
missing_freq = 0
for root, dirs, files in os.walk(location):
for f in files:
if f.endswith('.gcda'):
counter += 1
full = os.path.join(root, f)
r = subprocess.check_output('gcov-dump -l -r ' + full, encoding = 'utf8', shell = True)
for l in r.split('\n'):
if needle in l:
if ' 0 counts' in l:
continue
allvalues = [int(x) for x in l.split(':')[-1].split(' ') if x]
while allvalues:
if len(allvalues) == 1:
print('WARNING: ' + l)
break
counter_count += 1
n = allvalues[1]
values = allvalues[:2 + 2 * n]
allvalues = allvalues[len(values):]
total = abs(values[0])
total_freq += total
total_tuples += n
values = values[2:]
if len(values) != 2 * n:
print('WARNING: %s' + l)
break
if not n in histogram:
histogram[n] = [0, 0, 0]
histogram[n][0] += 1
if values:
zipped = sorted(list(zip(values[::2], values[1::2])), key = lambda x: x[1], reverse=True)
s = sum(x[1] for x in zipped)
if s > total:
print('WARNING: strange: %s' % l)
break
missing_freq += total - s
if n == max_nodes:
full_counters.append((total, s, zipped, values[0] > 0))
for z in zipped:
if z[1] >= (threshold * total):
histogram[n][1] += 1
histogram[n][2] += z[1]
total_freq_with_half += z[1]
elif n == 1:
assert False
print('Total: %d, total freq: %d, covered freq: %d (%.2f%%), missing freq: %d (%.2f%%)' % (counter_count, total_freq,
total_freq_with_half, 100.0 * total_freq_with_half / total_freq, missing_freq, 100.0 * missing_freq / total_freq))
print('Total tuples: %d (size before: 9*N=%d, after: 2*N + (2*TUPLE_COUNT)=%d'
% (total_tuples, 9 * counter_count, 2 * counter_count + 2 * total_tuples))
print('Histogram:')
for (k, v) in sorted(histogram.items(), key = lambda x: x[0]):
print(' %4d tracked: %7d (%2.2f%%), >=%.2f: %4d (cov. freq with prevailing: %12d (%.2f%%))' % (k, v[0], 100.0 * v[0] / counter_count, threshold, v[1], v[2], 100.0 * v[2] / total_freq))
print(f' full counters (>={interesting_coverage}%):')
for full in sorted(full_counters, key=lambda x: x[1], reverse=True):
covered_freq = 100.0 * full[1] / total_freq
if True:
#if covered_freq >= interesting_coverage:
missing = full[0] - full[1]
print(f' total: {full[1]} ({covered_freq:.2f}%) {"NEG" if full[3] else ""} missing: {missing} (of total: {100.0 * missing / full[0]:.2f}%), prevailing counter: {100.0 * full[2][0][1] / full[0]:.2f}%')
print()