bloat-o-meter 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/python
  2. #
  3. # Copyright 2004 Matt Mackall <mpm@selenic.com>
  4. #
  5. # inspired by perl Bloat-O-Meter (c) 1997 by Andi Kleen
  6. #
  7. # This software may be used and distributed according to the terms
  8. # of the GNU General Public License, incorporated herein by reference.
  9. import sys, os, re
  10. if len(sys.argv) != 3:
  11. sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
  12. sys.exit(-1)
  13. def getsizes(file):
  14. sym = {}
  15. for l in os.popen("nm --size-sort " + file).readlines():
  16. size, type, name = l[:-1].split()
  17. if type in "tTdDbBrR":
  18. # strip generated symbols
  19. if name[:6] == "__mod_": continue
  20. # function names begin with '.' on 64-bit powerpc
  21. if "." in name[1:]: name = "static." + name.split(".")[0]
  22. sym[name] = sym.get(name, 0) + int(size, 16)
  23. return sym
  24. old = getsizes(sys.argv[1])
  25. new = getsizes(sys.argv[2])
  26. grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
  27. delta, common = [], {}
  28. for a in old:
  29. if a in new:
  30. common[a] = 1
  31. for name in old:
  32. if name not in common:
  33. remove += 1
  34. down += old[name]
  35. delta.append((-old[name], name))
  36. for name in new:
  37. if name not in common:
  38. add += 1
  39. up += new[name]
  40. delta.append((new[name], name))
  41. for name in common:
  42. d = new.get(name, 0) - old.get(name, 0)
  43. if d>0: grow, up = grow+1, up+d
  44. if d<0: shrink, down = shrink+1, down-d
  45. delta.append((d, name))
  46. delta.sort()
  47. delta.reverse()
  48. print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
  49. (add, remove, grow, shrink, up, -down, up-down)
  50. print "%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")
  51. for d, n in delta:
  52. if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)