1 #! /usr/bin/env python3
7 def print_increase(x
, y
, name
):
9 print("{} increase by: {} (0x{:08X}) bytes ({}%)".format(name
, x
-y
, x
-y
, (x
-y
)*100/y
))
11 print("{} decrease by: {} (0x{:08X}) bytes ({}%)".format(name
, y
-x
, y
-x
, (y
-x
)*100/x
))
12 dbname
= "tools/data.json"
14 db
= json
.load(open(dbname
,"r"))
15 except FileNotFoundError
:
19 print("Usage: analyzesize.py <info|add|diff> <datasetname>")
21 action
, name
= sys
.argv
[1:3]
22 currentdata
= subprocess
.run(["arm-none-eabi-size","armsrc/obj/fullimage.stage1.elf"], stdout
=subprocess
.PIPE
).stdout
23 currentdata
= currentdata
.split(b
"\n")[1].strip()
24 text
,data
,bss
= [int(x
) for x
in currentdata
.split(b
"\t")[:3]]
25 if action
.lower() == "add":
26 db
[name
] = [text
, data
, bss
]
27 json
.dump(db
, open(dbname
, "w"))
28 elif action
.lower() == "diff":
29 text_ref
, data_ref
, bss_ref
= db
[name
]
30 flash_ref
= text_ref
+data_ref
32 print_increase(flash
, flash_ref
, "Flash")
33 print_increase(bss
, bss_ref
, "RAM")