2024-06-22 04:55:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2016-11-04 13:47:41 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# Internal build script for generating debugging test .so size.
|
|
|
|
# Usage:
|
|
|
|
# python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the
|
|
|
|
# size in it, then overwrites save.txt with the new size for future runs.
|
|
|
|
|
|
|
|
if len(sys.argv) != 3:
|
|
|
|
sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt")
|
|
|
|
|
|
|
|
lib = sys.argv[1]
|
|
|
|
save = sys.argv[2]
|
|
|
|
|
|
|
|
if not os.path.exists(lib):
|
2022-02-12 00:06:16 +00:00
|
|
|
sys.exit(f"Error: requested file ({lib}) does not exist")
|
2016-11-04 13:47:41 +00:00
|
|
|
|
|
|
|
libsize = os.path.getsize(lib)
|
|
|
|
|
2020-10-14 18:08:41 +00:00
|
|
|
print("------", os.path.basename(lib), "file size:", libsize, end="")
|
2016-11-04 13:47:41 +00:00
|
|
|
|
|
|
|
if os.path.exists(save):
|
|
|
|
with open(save) as sf:
|
|
|
|
oldsize = int(sf.readline())
|
|
|
|
|
|
|
|
if oldsize > 0:
|
|
|
|
change = libsize - oldsize
|
|
|
|
if change == 0:
|
|
|
|
print(" (no change)")
|
|
|
|
else:
|
2022-02-12 00:06:16 +00:00
|
|
|
print(f" (change of {change:+} bytes = {change / oldsize:+.2%})")
|
2016-11-04 13:47:41 +00:00
|
|
|
else:
|
|
|
|
print()
|
|
|
|
|
2020-10-14 18:08:41 +00:00
|
|
|
with open(save, "w") as sf:
|
2016-11-04 13:47:41 +00:00
|
|
|
sf.write(str(libsize))
|