Skip to content

Commit

Permalink
tests: Show summary of image sizes
Browse files Browse the repository at this point in the history
At the end of the tests, show a summary of the sizes of all the images
and initrds along with their sizes.

Fixes kata-containers#162.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Sep 9, 2018
1 parent 62aab2f commit c36c9e7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/test_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ readonly docker_build_runtime="runc"
test_images_only="false"
test_initrds_only="false"

# Hashes used to keep track of image sizes
typeset -A built_images
typeset -A built_initrds

usage()
{
cat <<EOT
Expand Down Expand Up @@ -60,6 +64,51 @@ Notes:
EOT
}

# Show the sizes of all the generated initrds and images
show_stats()
{
local name
local size
local sizeMB
local tmpfile

tmpfile=$(mktemp)

# images
for name in "${!built_images[@]}"
do
size=${built_images[$name]}
sizeMB=$(bc <<< "scale=2; ${size} / 2^20")

printf '%12.12s\t-8.8%s\t-8.8%s\t%-20.20s\n' \
"${size}" \
"${sizeMB}" \
'image' \
"${name}" >> "$tmpfile"
done

# initrds
for name in "${!built_initrds[@]}"
do
size=${built_initrds[$name]}
sizeMB=$(bc <<< "scale=2; ${size} / 2^20")

printf '%12.12s\t-8.8%s\t-8.8%s\t%-20.20s\n' \
"${size}" \
"${sizeMB}" \
'initrd' \
"${name}" >> "$tmpfile"
done

info "Image sizes (bytes) and types (small [better] to large)"
echo

printf '%12.12s\t-8.8%s\t-8.8%s\t%-20.20s\n\n' "Bytes" "MB" "Type" "Name"
sort -k1,1n "$tmpfile" | cat -n

rm -f "${tmpfile}"
}

exit_handler()
{
if [ "$?" -eq 0 ]
Expand Down Expand Up @@ -278,12 +327,16 @@ handle_options()
local image_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"

build_image "${image_path}" "${rootfs}"
built_images["${distro}"]=$(stat -c "%s" "${image_path}")

install_image_create_container "${image_path}"
elif [ "$type" = "initrd" ]
then
local initrd_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"

build_initrd "${initrd_path}" "${rootfs}"
built_initrds["${distro}"]=$(stat -c "%s" "${initrd_path}")

install_initrd_create_container "${initrd_path}"
else
die "invalid type: '$type' for distro $distro option $opt"
Expand Down Expand Up @@ -459,6 +512,8 @@ test_all_distros()
# previous tests.
test_distro_euleros
fi

show_stats
}

main()
Expand Down

0 comments on commit c36c9e7

Please sign in to comment.