libsize.py 1.1 KB

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