-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgcstat.py
71 lines (58 loc) · 1.81 KB
/
gcstat.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
import sys
from collections import defaultdict
f = open('gclog.txt', 'r')
incs = defaultdict(lambda: 0)
decs = defaultdict(lambda: 0)
refs = defaultdict(lambda: 0)
seenrefs = {}
types = {}
lineno = 0
for line in f:
lineno += 1
if lineno % 10000 == 0:
print 'Processing line', lineno
if line[0] == '=':
continue
parts = line.split('\t')
if parts[1] == 'I':
incs[parts[0]] += 1
refs[parts[3]] += 1
types[parts[3]] = parts[2]
seenrefs[parts[3]] = parts[6]
elif parts[1] == 'D':
decs[parts[0]] += 1
refs[parts[3]] -= 1
types[parts[3]] = parts[2]
seenrefs[parts[3]] = parts[6]
incpairs = incs.items()
decpairs = decs.items()
refpairs = refs.items()
incpairs.sort(key=lambda it: it[1], reverse=True)
decpairs.sort(key=lambda it: it[1], reverse=True)
refpairs.sort(key=lambda it: it[1], reverse=True)
for k in seenrefs:
seenrefs[k] = int(seenrefs[k])
totincs = sum((i[1] for i in incpairs))
totdecs = sum((i[1] for i in decpairs))
totliving = sum((i[1] for i in refpairs))
totsol = sum(seenrefs.itervalues())
out = open('gcstat.txt', 'w')
sys.stdout = out
print '=== Totals ==='
print '= Increfs:', totincs
print '= Decrefs:', totdecs
print '= Diff:', totincs - totdecs
print '= Living (our estimate):', totliving
print '= Living (according to Sol):', totsol
print '=== Functions, sorted by increments ==='
print '= %-30s%-8s%-8s'%('name', 'incs', 'decs')
for func, inccnt in incpairs:
print '%-32s%-8d%-8d'%(func, inccnt, decs[func])
print '=== Functions, sorted by decrements ==='
print '= %-30s%-8s%-8s'%('name', 'decs', 'incs')
for func, deccnt in decpairs:
print '%-32s%-8d%-8d'%(func, deccnt, incs[func])
print '=== Objects alive at cleanup ==='
print '= %-14s%-16s%-8s%-8s'%('addr', 'type', 'refs', 'solrefs')
for addr, refcnt in refpairs:
print '%-16s%-16s%-8d%-8d'%(addr, types[addr], refcnt, seenrefs[addr])