-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory-usage
More file actions
executable file
·23 lines (16 loc) · 799 Bytes
/
Copy pathmemory-usage
File metadata and controls
executable file
·23 lines (16 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
import sys, os, subprocess
filename = sys.argv[1]
flash_size, sram_size = {'atmega328p': (32768, 2048)}.get(sys.argv[2])
p = subprocess.Popen(['avr-size', '-A', filename], stdout=subprocess.PIPE, encoding='utf-8')
out, err = p.communicate()
section = dict()
for line in out.split('\n'):
line = line.split()
if len(line) == 3 and line[0].startswith('.'):
section[line[0]] = int(line[1])
flash_used = section.get('.data', 0) + section.get('.text', 0)
sram_used = section.get('.data', 0) + section.get('.bss', 0)
print("%s usage:" % filename)
print(" - Flash: %5d/%5d bytes (%.1f%%)" % (flash_used, flash_size, flash_used*100.0/flash_size))
print(" - SRAM: %5d/%5d bytes (%.1f%%) -- excluding stack!" % (sram_used, sram_size, sram_used*100.0/sram_size))