libsize.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import print_function, division
  2. import os
  3. import sys
  4. # Internal build script for generating debugging test .so size.
  5. # Usage:
  6. # python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the
  7. # size in it, then overwrites save.txt with the new size for future runs.
  8. if len(sys.argv) != 3:
  9. sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt")
  10. lib = sys.argv[1]
  11. save = sys.argv[2]
  12. if not os.path.exists(lib):
  13. sys.exit("Error: requested file ({}) does not exist".format(lib))
  14. libsize = os.path.getsize(lib)
  15. print("------", os.path.basename(lib), "file size:", libsize, end='')
  16. if os.path.exists(save):
  17. with open(save) as sf:
  18. oldsize = int(sf.readline())
  19. if oldsize > 0:
  20. change = libsize - oldsize
  21. if change == 0:
  22. print(" (no change)")
  23. else:
  24. print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize))
  25. else:
  26. print()
  27. with open(save, 'w') as sf:
  28. sf.write(str(libsize))