bloat-o-meter 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.startswith("__mod_"): continue
  20. if name.startswith("SyS_"): continue
  21. if name.startswith("compat_SyS_"): continue
  22. if name == "linux_banner": continue
  23. # statics and some other optimizations adds random .NUMBER
  24. name = re.sub(r'\.[0-9]+', '', name)
  25. sym[name] = sym.get(name, 0) + int(size, 16)
  26. return sym
  27. old = getsizes(sys.argv[1])
  28. new = getsizes(sys.argv[2])
  29. grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
  30. delta, common = [], {}
  31. for a in old:
  32. if a in new:
  33. common[a] = 1
  34. for name in old:
  35. if name not in common:
  36. remove += 1
  37. down += old[name]
  38. delta.append((-old[name], name))
  39. for name in new:
  40. if name not in common:
  41. add += 1
  42. up += new[name]
  43. delta.append((new[name], name))
  44. for name in common:
  45. d = new.get(name, 0) - old.get(name, 0)
  46. if d>0: grow, up = grow+1, up+d
  47. if d<0: shrink, down = shrink+1, down-d
  48. delta.append((d, name))
  49. delta.sort()
  50. delta.reverse()
  51. print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
  52. (add, remove, grow, shrink, up, -down, up-down))
  53. print("%-40s %7s %7s %+7s" % ("function", "old", "new", "delta"))
  54. for d, n in delta:
  55. if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d))