Merge "Add image size report"

This commit is contained in:
Jenkins 2016-04-02 15:45:42 +00:00 committed by Gerrit Code Review
commit 404ca1b944
2 changed files with 66 additions and 18 deletions

View File

@ -324,12 +324,50 @@ unmount_image
mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
if [ -n "$DIB_IMAGE_SIZE" ]; then 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 else
# in kb*0.60 - underreport to get a slightly bigger device du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built)
du_size=$(sudo du --block-size=600 -x -s ${TMP_BUILD_DIR}/built |\
awk ' { print $1 }') # 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 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 if [ "$FS_TYPE" = "ext4" ] ; then
# Very conservative to handle images being resized a lot # Very conservative to handle images being resized a lot
# We set journal size to 64M so our journal is large enough when we # We set journal size to 64M so our journal is large enough when we

View File

@ -1,19 +1,29 @@
Invocation Invocation
========== ==========
The scripts can generally just be run. Options can be set on the command line The scripts can generally just be run. Options can be set on the
or by exporting variables to override those present in lib/img-defaults. -h to command line or by exporting variables to override those present in
get help. 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.
Using the variable ELEMENTS\_PATH will allow to specify multiple elements locations. The image building scripts expect to be able to invoke commands with
It's a colon (:) separated path list, and it will work in a first path/element found, sudo, so if you want them to run non-interactively, you should either
first served approach. The included elements tree is used when no path is supplied, run them as root, with sudo -E, or allow your build user to run any
and is added to the end of the path if a path is supplied. sudo command without password.
By default, the image building scripts will not overwrite existing disk images, Using the variable ``ELEMENTS_PATH`` will allow to specify multiple
allowing you to compare the newly built image with the existing one. To change elements locations. It is a colon (:) separated path list, and it
that behaviour, set the variable OVERWRITE\_OLD\_IMAGE to any value that isn't will work in a first path/element found, first served approach. The
0. 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.