The Sol Programming Language!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gcstat.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import sys
  2. from collections import defaultdict
  3. f = open('gclog.txt', 'r')
  4. incs = defaultdict(lambda: 0)
  5. decs = defaultdict(lambda: 0)
  6. refs = defaultdict(lambda: 0)
  7. seenrefs = {}
  8. types = {}
  9. lineno = 0
  10. for line in f:
  11. lineno += 1
  12. if lineno % 10000 == 0:
  13. print 'Processing line', lineno
  14. if line[0] == '=':
  15. continue
  16. parts = line.split('\t')
  17. if parts[1] == 'I':
  18. incs[parts[0]] += 1
  19. refs[parts[3]] += 1
  20. types[parts[3]] = parts[2]
  21. seenrefs[parts[3]] = parts[6]
  22. elif parts[1] == 'D':
  23. decs[parts[0]] += 1
  24. refs[parts[3]] -= 1
  25. types[parts[3]] = parts[2]
  26. seenrefs[parts[3]] = parts[6]
  27. incpairs = incs.items()
  28. decpairs = decs.items()
  29. refpairs = refs.items()
  30. incpairs.sort(key=lambda it: it[1], reverse=True)
  31. decpairs.sort(key=lambda it: it[1], reverse=True)
  32. refpairs.sort(key=lambda it: it[1], reverse=True)
  33. for k in seenrefs:
  34. seenrefs[k] = int(seenrefs[k])
  35. totincs = sum((i[1] for i in incpairs))
  36. totdecs = sum((i[1] for i in decpairs))
  37. totliving = sum((i[1] for i in refpairs))
  38. totsol = sum(seenrefs.itervalues())
  39. out = open('gcstat.txt', 'w')
  40. sys.stdout = out
  41. print '=== Totals ==='
  42. print '= Increfs:', totincs
  43. print '= Decrefs:', totdecs
  44. print '= Diff:', totincs - totdecs
  45. print '= Living (our estimate):', totliving
  46. print '= Living (according to Sol):', totsol
  47. print '=== Functions, sorted by increments ==='
  48. print '= %-30s%-8s%-8s'%('name', 'incs', 'decs')
  49. for func, inccnt in incpairs:
  50. print '%-32s%-8d%-8d'%(func, inccnt, decs[func])
  51. print '=== Functions, sorted by decrements ==='
  52. print '= %-30s%-8s%-8s'%('name', 'decs', 'incs')
  53. for func, deccnt in decpairs:
  54. print '%-32s%-8d%-8d'%(func, deccnt, incs[func])
  55. print '=== Objects alive at cleanup ==='
  56. print '= %-14s%-16s%-8s%-8s'%('addr', 'type', 'refs', 'solrefs')
  57. for addr, refcnt in refpairs:
  58. print '%-16s%-16s%-8d%-8d'%(addr, types[addr], refcnt, seenrefs[addr])