Skip to content

Commit 386607d

Browse files
committed
add script sdsize.sh to display the resource usage similar to the size tool
1 parent 87f15d6 commit 386607d

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

  • sduino/hardware/sduino/tools/wrapper
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh
2+
# works on bash, dash or busybox ash
3+
4+
print_usage ()
5+
{
6+
cat << EOF
7+
Print the memory usage of a binary compiled by SDCC
8+
9+
usage: $0 mapfile
10+
11+
The display format mimics the output of the size tool. The values are
12+
calculated from the segment definitions in the map file as follows:
13+
14+
text (code in flash)
15+
- CODE: program code
16+
- GSINIT: code to copy the globaly initialized data
17+
- GSFINAL: code after the initialization is done
18+
19+
data (initialized data in flash)
20+
- HOME: Interrupt vectors etc.
21+
- CONST: Constants (tables)
22+
- INITIALIZER: Content of initialized variables (to be copied to
23+
INITIALIZED)
24+
25+
bss (uninitialized, zeroed and initialized, total RAM usage)
26+
- DATA: uninitialized
27+
- INITIALIZED: initialized, copied from INITIALIZER
28+
29+
dec (total flash usage in decimal)
30+
- text+data
31+
32+
hex (total flash usage in hex)
33+
- text+data
34+
35+
filename
36+
- the filename of the map file
37+
38+
LGPL-2.1, (c) 2018 M. Mayer
39+
EOF
40+
exit 1
41+
}
42+
43+
44+
VERBOSE=0
45+
46+
while getopts ":hv" opt; do
47+
case "$opt" in
48+
v)
49+
echo "verbose!"
50+
VERBOSE=1
51+
;;
52+
*)
53+
print_usage
54+
;;
55+
esac
56+
done
57+
shift $((OPTIND-1))
58+
59+
if [ $# -lt 1 ]; then
60+
print_usage;
61+
fi
62+
63+
FILENAME="$1"
64+
65+
awk -v filename="$FILENAME" -v verbose=$VERBOSE '
66+
/^[A-Z]+ / {
67+
if (verbose) print $1, $3, $5; size[$1]=$5;
68+
}
69+
END {
70+
text = size["CODE"]+size["GSINIT"]+size["GSFINAL"];
71+
data = size["HOME"]+size["CONST"]+size["INITIALIZER"];
72+
bss = size["DATA"]+size["INITIALIZED"];
73+
print " text\t data\t bss\t dec\t hex\tfilename";
74+
# print text, data, bss;
75+
printf "%7d\t%7d\t%7d\t%7d\t%7x\t%s\n", text, data, bss, text+data, text+data, filename;
76+
}' "$FILENAME"

0 commit comments

Comments
 (0)