• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2from __future__ import print_function, division
3import 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))
39