Bsongis/sonar (#5382)
[opentx.git] / radio / util / checksize.py
blob6ca91755fc700a10ef8514866d1b16bbbecda852
1 #!/usr/bin/env python
3 # The commands used to compare 2.2 flash usage
4 # on 2.1 release: make PCB=9X EXT=FRSKY VOICE=YES AUDIO=YES AUTOSOURCE=YES AUTOSWITCH=YES HELI=YES TEMPLATES=YES GAUGES=NO
5 # => 64818 (program) + 3236 (data)
6 # on 2.2 release: cmake -DPCB=9X -DTELEMETRY=FRSKY -DAUDIO=YES -DVOICE=YES -DHELI=YES -DTEMPLATES=YES ~/git/opentx
7 # => 64828 (program) + 3236 (data)
9 from __future__ import print_function
10 import os
11 import sys
12 import subprocess
14 index = -1
15 size = None
17 options = sys.argv[1:]
18 srcdir = os.path.dirname(os.path.realpath(__file__)) + "/../.."
19 buildir = os.getcwd()
21 while 1:
22 sys.stdout.flush()
23 index += 1
25 os.chdir(srcdir)
26 cmd = ["git", "reset", "--hard", "FETCH_HEAD~%d" % index]
27 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
28 output, error = proc.communicate()
29 if proc.returncode != 0:
30 print("HEAD~%d git reset failed" % index)
31 continue
33 os.chdir(buildir)
34 cmd = ["cmake"] + options + [srcdir]
35 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
36 output, error = proc.communicate()
37 if proc.returncode != 0:
38 print("HEAD~%d cmake failed" % index)
39 continue
41 cmd = ["make", "-j4", "firmware"]
42 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43 output, error = proc.communicate()
44 if proc.returncode != 0:
45 print("HEAD~%d make firmware failed" % index)
46 continue
48 if os.path.isfile("firmware.bin"):
49 oldsize = os.stat("firmware.bin").st_size
50 else:
51 oldsize = int(subprocess.check_output('avr-size -A firmware.hex | grep Total | cut -f2- -d " "', shell=True))
52 if size:
53 if size > oldsize:
54 print("HEAD~%d %d: increase by %d bytes" % (index-1, size, size-oldsize))
55 elif size < oldsize:
56 print("HEAD~%d %d: decrease by %d bytes" % (index-1, size, oldsize-size))
57 else:
58 print("HEAD~%d %d" % (index-1, size))
59 size = oldsize