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.

38 lines
1.1 KiB

3 months ago
  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))