(original) (raw)
import sys, collections stat1 = collections.Counter() stat2 = collections.defaultdict(collections.Counter) for line in sys.stdin: if not line.startswith('PyObject_INIT'): continue try: s, t, *r = line.split() stat1[t] += 1 if s == 'PyObject_INIT_VAR': stat2[t][int(r[0])] += 1 except Exception as e: print('*** ERROR: %r %r' % (line, e), file=sys.stderr) total = sum(stat1.values()) acc = 0 print('%-30s %10s %7s %7s' % ('type', 'count', '%', 'acc.%')) print() for t, c in stat1.most_common(30): acc += c print('%-30s %10d %6.2f%% %6.2f%%' % (t, c, 100 * c / total, 100 * acc / total)) for t in sorted(stat2, key=stat1.__getitem__, reverse=True)[:20]: c = stat1[t] print() print('%-30s %10d %6.2f%%' % (t, c, 100 * c / total)) acc = 0 for s, c2 in sorted(stat2[t].items()): acc += c2 print('%30d %10d %6.2f%% %6.2f%%' % (s, c2, 100 * c2 / c, 100 * acc / c)) c2 = c - sum(stat2[t].values()) if c2: print('%30s %10d %6.2f%% %6.2f%%' % ('-', c2, 100 * c2 / c, 100))