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 size of all the rootfs's,
images and initrd's.

Fixes kata-containers#162.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
  • Loading branch information
jodh-intel committed Sep 10, 2018
1 parent 93ad049 commit 9f24610
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ source "${cidir}/lib.sh"
source /etc/os-release

if [ "$ID" == fedora ];then
sudo -E dnf -y install automake yamllint coreutils moreutils
sudo -E dnf -y install automake yamllint coreutils moreutils bc
elif [ "$ID" == centos ];then
sudo -E yum -y install epel-release
sudo -E yum -y install automake yamllint coreutils moreutils
sudo -E yum -y install automake yamllint coreutils moreutils bc
elif [ "$ID" == ubuntu ];then
sudo apt-get -qq update
sudo apt-get install -y -qq make automake qemu-utils python-pip coreutils moreutils
sudo apt-get install -y -qq make automake qemu-utils python-pip coreutils moreutils bc
sudo pip install yamllint
else
echo "Linux distribution not supported"
Expand Down
85 changes: 85 additions & 0 deletions tests/test_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ readonly docker_build_runtime="runc"
test_images_only="false"
test_initrds_only="false"

# Hashes used to keep track of image sizes.
# - Key: name of distro.
# - Value: colon-separated roots and image sizes ("${rootfs_size}:${image_size}").
typeset -A built_images
typeset -A built_initrds

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

# Add an entry to the specified stats file
add_to_stats_file()
{
local statsfile="$1"
local name="$2"
local entry="$3"
local entry_type="$4"

local rootfs_size_bytes
local rootfs_size_mb

local image_size_bytes
local image_size_mb

rootfs_size_bytes=$(echo "$entry"|cut -d: -f1)
image_size_bytes=$(echo "$entry"|cut -d: -f2)

rootfs_size_mb=$(bc <<< "scale=2; ${rootfs_size_bytes} / 2^20")
image_size_mb=$(bc <<< "scale=2; ${image_size_bytes} / 2^20")

printf '%12.12s\t%10.10s\t%12.12s\t%10.10s\t%-8.8s\t%-20.20s\n' \
"${image_size_bytes}" \
"${image_size_mb}" \
"${rootfs_size_bytes}" \
"${rootfs_size_mb}" \
"${entry_type}" \
"${name}" >> "$statsfile"
}

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

local tmpfile=$(mktemp)

# images
for name in "${!built_images[@]}"
do
sizes=${built_images[$name]}
add_to_stats_file "$tmpfile" "$name" "$sizes" 'image'
done

# initrds
for name in "${!built_initrds[@]}"
do
sizes=${built_initrds[$name]}
add_to_stats_file "$tmpfile" "$name" "$sizes" 'initrd'
done

info "Image and rootfs sizes (in bytes and MB), smallest image first:"
echo

printf '%12.12s\t%10.10s\t%12.12s\t%10.10s\t%-8.8s\t%-20.20s\n' \
"image-bytes" \
"image-MB" \
"rootfs-bytes" \
"rootfs-MB" \
"Type" \
"Name"

sort -k1,1n "$tmpfile"

rm -f "${tmpfile}"
}

exit_handler()
{
if [ "$?" -eq 0 ]
Expand Down Expand Up @@ -270,6 +343,8 @@ handle_options()

build_rootfs "${distro}" "${rootfs}"

local rootfs_size=$(du -sb "${rootfs}" | awk '{print $1}')

if [ "$type" = "image" ]
then
# Images need systemd
Expand All @@ -278,12 +353,20 @@ handle_options()
local image_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"

build_image "${image_path}" "${rootfs}"
local image_size=$(stat -c "%s" "${image_path}")

built_images["${distro}"]="${rootfs_size}:${image_size}"

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}"
local initrd_size=$(stat -c "%s" "${initrd_path}")

built_initrds["${distro}"]="${rootfs_size}:${initrd_size}"

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

show_stats
}

main()
Expand Down

0 comments on commit 9f24610

Please sign in to comment.