blob: 50f88bdb3dc57ac6df11a249d789ac5018a7fc86 [file] [log] [blame]
Henry Schreinerd8c7ee02020-07-20 13:35:21 -04001# -*- coding: utf-8 -*-
Dean Moldovand079f412016-11-20 05:31:02 +01002from __future__ import print_function, division
Jason Rhinelanderdc0b4bd2016-11-04 09:47:41 -04003import os
4import sys
5
6# Internal build script for generating debugging test .so size.
7# Usage:
8# python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the
9# size in it, then overwrites save.txt with the new size for future runs.
10
11if len(sys.argv) != 3:
12 sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt")
13
14lib = sys.argv[1]
15save = sys.argv[2]
16
17if not os.path.exists(lib):
18 sys.exit("Error: requested file ({}) does not exist".format(lib))
19
20libsize = os.path.getsize(lib)
21
22print("------", os.path.basename(lib), "file size:", libsize, end='')
23
24if os.path.exists(save):
25 with open(save) as sf:
26 oldsize = int(sf.readline())
27
28 if oldsize > 0:
29 change = libsize - oldsize
30 if change == 0:
31 print(" (no change)")
32 else:
33 print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize))
34else:
35 print()
36
37with open(save, 'w') as sf:
38 sf.write(str(libsize))