Add image size report
In the common case of not specifying a size, we are already running "du" over the image to figure out how big it is. Leverage that by saving it's output and displaying a pruned list of big files when requested. We add a flag to show a summarised option (files >10MiB) and another to show full output, should you wish that level of detail. "Invocation" documentation is updated (and formatted a little better while we're here). Change-Id: I255800790a62fed1c82fcd311f1cc29c9867766d
This commit is contained in:
parent
103b7dea6d
commit
fa3c5e3056
@ -306,12 +306,50 @@ unmount_image
|
||||
mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
|
||||
|
||||
if [ -n "$DIB_IMAGE_SIZE" ]; then
|
||||
du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}')
|
||||
du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}')
|
||||
else
|
||||
# in kb*0.60 - underreport to get a slightly bigger device
|
||||
du_size=$(sudo du --block-size=600 -x -s ${TMP_BUILD_DIR}/built |\
|
||||
awk ' { print $1 }')
|
||||
du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built)
|
||||
|
||||
# the last line is the total size from "-c".
|
||||
# scale this by 0.6 to create a slightly bigger image
|
||||
du_size=$(echo "$du_output" | tail -n1 | cut -f1 | \
|
||||
awk '{print int($1 / 0.6)}')
|
||||
fi
|
||||
|
||||
if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then
|
||||
xtrace=$(set +o | grep xtrace)
|
||||
set +o xtrace
|
||||
|
||||
if [ -z "$du_output" ]; then
|
||||
du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built)
|
||||
fi
|
||||
|
||||
# by default show the 10MiB and greater files & directories -- a
|
||||
# dir with lots of little files will still show up, but this helps
|
||||
# signal:noise ratio
|
||||
if [[ ${DIB_SHOW_IMAGE_USAGE_FULL:-0} == 0 ]]; then
|
||||
# numfmt will start giving a decimal place when < 10MiB
|
||||
du_output_limit="| egrep 'MiB|GiB|TiB|PiB' | grep -v '\..MiB'"
|
||||
echo "================================="
|
||||
echo "Image size report (files > 10MiB)"
|
||||
echo "================================="
|
||||
else
|
||||
du_output_limit=""
|
||||
echo "================="
|
||||
echo "Image size report"
|
||||
echo "================="
|
||||
fi
|
||||
|
||||
echo "$du_output" | sort -nr | \
|
||||
numfmt --to=iec-i --padding=7 --suffix=B --field=1 --from-unit=1024 \
|
||||
$du_output_limit
|
||||
echo
|
||||
echo "===== end image size report ====="
|
||||
echo
|
||||
|
||||
$xtrace
|
||||
fi
|
||||
|
||||
if [ "$FS_TYPE" = "ext4" ] ; then
|
||||
# Very conservative to handle images being resized a lot
|
||||
# We set journal size to 64M so our journal is large enough when we
|
||||
|
@ -1,19 +1,29 @@
|
||||
Invocation
|
||||
==========
|
||||
|
||||
The scripts can generally just be run. Options can be set on the command line
|
||||
or by exporting variables to override those present in lib/img-defaults. -h to
|
||||
get help.
|
||||
The image building scripts expect to be able to invoke commands with sudo, so if you
|
||||
want them to run non-interactively, you should either run them as root, with
|
||||
sudo -E, or allow your build user to run any sudo command without password.
|
||||
The scripts can generally just be run. Options can be set on the
|
||||
command line or by exporting variables to override those present in
|
||||
lib/img-defaults. -h to get help.
|
||||
|
||||
Using the variable ELEMENTS\_PATH will allow to specify multiple elements locations.
|
||||
It's a colon (:) separated path list, and it will work in a first path/element found,
|
||||
first served approach. The included elements tree is used when no path is supplied,
|
||||
and is added to the end of the path if a path is supplied.
|
||||
The image building scripts expect to be able to invoke commands with
|
||||
sudo, so if you want them to run non-interactively, you should either
|
||||
run them as root, with sudo -E, or allow your build user to run any
|
||||
sudo command without password.
|
||||
|
||||
By default, the image building scripts will not overwrite existing disk images,
|
||||
allowing you to compare the newly built image with the existing one. To change
|
||||
that behaviour, set the variable OVERWRITE\_OLD\_IMAGE to any value that isn't
|
||||
0.
|
||||
Using the variable ``ELEMENTS_PATH`` will allow to specify multiple
|
||||
elements locations. It is a colon (:) separated path list, and it
|
||||
will work in a first path/element found, first served approach. The
|
||||
included elements tree is used when no path is supplied, and is added
|
||||
to the end of the path if a path is supplied.
|
||||
|
||||
By default, the image building scripts will not overwrite existing
|
||||
disk images, allowing you to compare the newly built image with the
|
||||
existing one. To change that behaviour, set the variable
|
||||
``OVERWRITE_OLD_IMAGE`` to any value that isn't ``0``.
|
||||
|
||||
Setting the variable ``DIB_SHOW_IMAGE_USAGE`` will print out a
|
||||
summarised disk-usage report for the final image of files and
|
||||
directories over 10MiB in size. Setting ``DIB_SHOW_IMAGE_USAGE_FULL``
|
||||
will show all files and directories. These settings can be useful
|
||||
additions to the logs in automated build situations where debugging
|
||||
image-growth may be important.
|
||||
|
Loading…
Reference in New Issue
Block a user