μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
libsize.py
Go to the documentation of this file.
1# -*- coding: utf-8 -*-
2from __future__ import division, print_function
3
4import os
5import sys
6
7# Internal build script for generating debugging test .so size.
8# Usage:
9# python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the
10# size in it, then overwrites save.txt with the new size for future runs.
11
12if len(sys.argv) != 3:
13 sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt")
14
15lib = sys.argv[1]
16save = sys.argv[2]
17
18if not os.path.exists(lib):
19 sys.exit("Error: requested file ({}) does not exist".format(lib))
20
21libsize = os.path.getsize(lib)
22
23print("------", os.path.basename(lib), "file size:", libsize, end="")
24
25if os.path.exists(save):
26 with open(save) as sf:
27 oldsize = int(sf.readline())
28
29 if oldsize > 0:
30 change = libsize - oldsize
31 if change == 0:
32 print(" (no change)")
33 else:
34 print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize))
35else:
36 print()
37
38with open(save, "w") as sf:
39 sf.write(str(libsize))
Definition: pytypes.h:1200
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2002