I working on some code optimization and I would to inspect the size of my functions instead to read huge disassembly file. After compilation on Debug, I use the nm command to read the .o. We got this :
nm --size-sort $OBJFILEPATH.o
000000000000000b r __PRETTY_FUNCTION__.6473
0000000000000017 t extract_h
0000000000000036 t L_mult
000000000000003a t sature32
0000000000000042 t L_mac
0000000000000048 t L_add
000000000000005c t Mac16x11
0000000000000077 t L_shl
0000000000000083 t L_shr
00000000000000df T G729Convolve
0000000000000114 T G729Residu
00000000000001bc T G729Syn_filt_L_H
00000000000001bc T G729Syn_filt_L_SUBFR
read FUNCSIZE <<< $(nm --size-sort $OBJFILEPATH.o | awk '{print $1}')
SIZE=${#FUNCSIZE[@]}
echo size is $SIZE
for s in $FUNCSIZE
do
echo $s
done
size is 1
000000000000000b
0000000000000017
0000000000000036
000000000000003a
0000000000000042
0000000000000048
000000000000005c
0000000000000077
0000000000000083
00000000000000df
0000000000000114
00000000000001bc
00000000000001bc
read -a FUNCSIZE <<< $(nm --size-sort $OBJFILEPATH.o | awk '{print $1}')
SIZE=${#FUNCSIZE[*]}
for((i=0; i<SIZE; i++))
do
echo ${FUNCSIZE[$i]}
done
The way you wrote it, FUNCSIZE
is not an array, but a regular variable.
Add the -a
flag for read
:
read -a FUNCSIZE <<< $(nm --size-sort $OBJFILEPATH.o | awk '{print $1}')
Note that using all-uppercase names for user-defined variables is not recommended, to avoid conflicts (and confusion) with environmental variables and special shell variables.
(Thanks @mklement0 for the tips and links!)