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