summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-09-07 10:42:43 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-09-07 10:42:43 +0200
commit315f0744b249cf483b9ce9a318066d2a54e21c25 (patch)
treeaf4efd2ca27e9545de4678f9abf021c0a6bfbdc9 /script
parentdd4cb31da6c7768dea7a62057057d5cd0f2bf8e2 (diff)
add machine-readable binary size output ("make attributes")
Diffstat (limited to 'script')
-rwxr-xr-xscript/size.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/script/size.py b/script/size.py
new file mode 100755
index 0000000..e553314
--- /dev/null
+++ b/script/size.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+import json
+import re
+import subprocess
+import sys
+
+
+def main(size_executable, rom_sections, ram_sections):
+ rom_sections = rom_sections.split(",")
+ ram_sections = ram_sections.split(",")
+
+ status = subprocess.run(
+ [size_executable, "-A", "build/system.elf"],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ universal_newlines=True,
+ )
+
+ section_size = dict()
+
+ for line in status.stdout.split("\n"):
+ match = re.match("[.](\S+)\s+(\d+)", line)
+ if match:
+ section = match.group(1)
+ size = int(match.group(2))
+ section_size[section] = size
+
+ total = {
+ "ROM": sum(map(lambda section: section_size[section], rom_sections)),
+ "RAM": sum(map(lambda section: section_size[section], ram_sections)),
+ }
+
+ output = {"section": section_size, "total": total}
+
+ print(json.dumps(output))
+
+
+if __name__ == "__main__":
+ main(*sys.argv[1:])