Scarab  v2.9.0
Project 8 C++ Utility Library
libsize.py
Go to the documentation of this file.
1 from __future__ import print_function, division
2 import os
3 import sys
4 
5 # Internal build script for generating debugging test .so size.
6 # Usage:
7 # python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the
8 # size in it, then overwrites save.txt with the new size for future runs.
9 
10 if len(sys.argv) != 3:
11  sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt")
12 
13 lib = sys.argv[1]
14 save = sys.argv[2]
15 
16 if not os.path.exists(lib):
17  sys.exit("Error: requested file ({}) does not exist".format(lib))
18 
19 libsize = os.path.getsize(lib)
20 
21 print("------", os.path.basename(lib), "file size:", libsize, end='')
22 
23 if os.path.exists(save):
24  with open(save) as sf:
25  oldsize = int(sf.readline())
26 
27  if oldsize > 0:
28  change = libsize - oldsize
29  if change == 0:
30  print(" (no change)")
31  else:
32  print(" (change of {:+} bytes = {:+.2%})".format(change, change / oldsize))
33 else:
34  print()
35 
36 with open(save, 'w') as sf:
37  sf.write(str(libsize))
38 
size_t len(handle h)
Definition: pytypes.h:1361
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > &>(), fmt, tp), std::basic_string< CharT >
Definition: date.h:5663
return os str()
void print(Args &&...args)
Definition: pybind11.h:1849