Dean Moldovan | d079f41 | 2016-11-20 05:31:02 +0100 | [diff] [blame^] | 1 | from __future__ import print_function, division |
Jason Rhinelander | dc0b4bd | 2016-11-04 09:47:41 -0400 | [diff] [blame] | 2 | import os |
| 3 | import sys |
| 4 | |
| 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 | |
| 10 | if len(sys.argv) != 3: |
| 11 | sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt") |
| 12 | |
| 13 | lib = sys.argv[1] |
| 14 | save = sys.argv[2] |
| 15 | |
| 16 | if not os.path.exists(lib): |
| 17 | sys.exit("Error: requested file ({}) does not exist".format(lib)) |
| 18 | |
| 19 | libsize = os.path.getsize(lib) |
| 20 | |
| 21 | print("------", os.path.basename(lib), "file size:", libsize, end='') |
| 22 | |
| 23 | if os.path.exists(save): |
| 24 | with open(save) as sf: |
| 25 | oldsize = int(sf.readline()) |
| 26 | |
| 27 | if oldsize > 0: |
| 28 | change = libsize - oldsize |
| 29 | if change == 0: |
| 30 | print(" (no change)") |
| 31 | else: |
| 32 | print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize)) |
| 33 | else: |
| 34 | print() |
| 35 | |
| 36 | with open(save, 'w') as sf: |
| 37 | sf.write(str(libsize)) |
| 38 | |