Skip to content

Instantly share code, notes, and snippets.

@geky
Last active June 5, 2024 03:17
Show Gist options
  • Save geky/31f79a3be0abfdbb2020f17140c4d4bb to your computer and use it in GitHub Desktop.
Save geky/31f79a3be0abfdbb2020f17140c4d4bb to your computer and use it in GitHub Desktop.
Watch littlefs cross-compiled thumb sizes easily
#!/bin/bash
set -eu -o pipefail
# run in watch mode?
if [[ "$@" == *-w* ]]
then
./scripts/watch.py \
$([[ "$@" == *-z* ]] && echo -z || echo -n4) \
-K lfs.h -K lfs_util.h \
-K lfs.c -K lfs_util.c \
$0 $(echo "$@" | sed 's/-w//')
exit
fi
# compile for thumb
BUILDDIR=thumb \
CC='arm-linux-gnueabi-gcc -mthumb --static -Wno-stringop-overflow' \
CFLAGS='-DLFS_NO_ASSERT -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR' \
make clean build \
thumb/lfs.code.csv \
thumb/lfs.data.csv \
thumb/lfs.stack.csv \
thumb/lfs.structs.csv
# success?
if [ $? -eq 0 ]
then
# keep last three builds
cp thumb/liblfs{.2,.3}.a || true
cp thumb/lfs{.2,.3}.o || true
cp thumb/lfs_util{.2,.3}.o || true
cp thumb/lfs{.2,.3}.ci || true
cp thumb/lfs_util{.2,.3}.ci || true
cp thumb/lfs.code{.2,.3}.csv || true
cp thumb/lfs.data{.2,.3}.csv || true
cp thumb/lfs.stack{.2,.3}.csv || true
cp thumb/lfs.structs{.2,.3}.csv || true
cp thumb/liblfs{.1,.2}.a || true
cp thumb/lfs{.1,.2}.o || true
cp thumb/lfs_util{.1,.2}.o || true
cp thumb/lfs{.1,.2}.ci || true
cp thumb/lfs_util{.1,.2}.ci || true
cp thumb/lfs.code{.1,.2}.csv || true
cp thumb/lfs.data{.1,.2}.csv || true
cp thumb/lfs.stack{.1,.2}.csv || true
cp thumb/lfs.structs{.1,.2}.csv || true
cp thumb/liblfs{,.1}.a
cp thumb/lfs{,.1}.o
cp thumb/lfs_util{,.1}.o
cp thumb/lfs{,.1}.ci
cp thumb/lfs_util{,.1}.ci
cp thumb/lfs.code{,.1}.csv
cp thumb/lfs.data{,.1}.csv
cp thumb/lfs.stack{,.1}.csv
cp thumb/lfs.structs{,.1}.csv
if git diff --exit-code --quiet
then
cp thumb/liblfs{,.c}.a
cp thumb/lfs{,.c}.o
cp thumb/lfs_util{,.c}.o
cp thumb/lfs{,.c}.ci
cp thumb/lfs_util{,.c}.ci
cp thumb/lfs.code{,.c}.csv
cp thumb/lfs.data{,.c}.csv
cp thumb/lfs.stack{,.c}.csv
cp thumb/lfs.structs{,.c}.csv
fi
# show results
(
if [[ "$@" == *-d* ]]
then
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.c.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.c.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.c.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.c.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.3.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.3.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.3.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.3.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y \
-p -d <(./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.c.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.c.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.c.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.c.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
-q -o-)
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.2.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.2.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.2.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.2.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y \
-p -d <(./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.c.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.c.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.c.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.c.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
-q -o-)
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y \
-p -d <(./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.c.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.c.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.c.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.c.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
-q -o-)
else
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.c.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.c.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.c.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.c.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.3.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.3.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.3.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.3.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.2.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.2.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.2.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.2.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y
./scripts/summary.py \
<(./scripts/summary.py thumb/lfs.code.csv \
-fcode=size -q -o-) \
<(./scripts/summary.py thumb/lfs.data.csv \
-fdata=size -q -o-) \
<(./scripts/summary.py thumb/lfs.stack.csv \
-fstack=limit -q -o-) \
<(./scripts/summary.py thumb/lfs.structs.csv \
-fstructs=size -q -o-) \
-fcode -fdata -fstack -fstructs \
--max=stack \
-Y
fi
) | awk '
NR==1 { $0=":" $0; $1="" }
NR==2 { $1="commit:" }
NR==4 { $1="prev~2:" }
NR==6 { $1="prev~1:" }
NR==8 { $1="current:" }
NR>2 && NR%2==1 { next }
{
nr++;
c=0;
for (i=1; i<=NF; i++) {
if (c > 0 && $i ~ /^\(/) {
n[nr,c] = $i;
} else {
a[nr,++c] = $i;
}
}
if (c > nc) nc = c;
}
END {
for (r=1; r<=nr; r++) {
for (c=1; c<=nc; c++) {
if (length(a[r,c]) > wa[c]) wa[c] = length(a[r,c]);
if (length(n[r,c]) > wn[c]) wn[c] = length(n[r,c]);
}
}
for (r=1; r<=nr; r++) {
printf "%-*s ", wa[1], a[r,1];
if (wn[1]) {
printf "%-*s ", wn[1], n[r,1];
}
for (c=2; c<=nc; c++) {
printf " %*s", int((wa[c]+1+4-1)/4)*4-1, a[r,c];
if (wn[c]) {
printf " %-*s", wn[c], n[r,c];
}
}
printf "\n";
}
}'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment