File: cmp-size.py

package info (click to toggle)
gemmi 0.6.5%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,836 kB
  • sloc: cpp: 54,719; python: 4,743; ansic: 3,972; sh: 384; makefile: 73; f90: 42; javascript: 12
file content (38 lines) | stat: -rwxr-xr-x 1,001 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# Script for storing and comparing binary sizes.
# Uses $PWD/.size-save.txt to store output of the size command.

import os
import sys
import subprocess

SAVE = '.size-save.txt'
paths = sys.argv[1:]

old_output = None
if os.path.exists(SAVE):
    with open(SAVE) as f:
        old_output = f.read()

new_output = subprocess.check_output(['size'] + paths)
with open(SAVE, "wb") as f:
    f.write(new_output)

if old_output is None:
    sys.exit()

def parse_size(output):
    lines = output.splitlines()[1:]
    values = []
    for line in lines:
        text, data, bss, _ = line.split(None, 3)
        values.append([int(text), int(data), int(bss)])
    return values

for old, new, p in zip(parse_size(old_output), parse_size(new_output), paths):
    print("size of %s --> " % os.path.basename(p), end="")
    if old == new:
        print("the same")
    else:
        changes = tuple(a - b for a, b in zip(new, old))
        print("text: %+d  data: %+d  bss: %+d" % changes)