mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-03 18:47:03 +00:00
tests: Show summary of image sizes
At the end of the tests, show a summary of the size of all the rootfs's, images and initrd's. Fixes #162. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
93ad0491ef
commit
9f2461061f
@ -14,13 +14,13 @@ source "${cidir}/lib.sh"
|
|||||||
source /etc/os-release
|
source /etc/os-release
|
||||||
|
|
||||||
if [ "$ID" == fedora ];then
|
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
|
elif [ "$ID" == centos ];then
|
||||||
sudo -E yum -y install epel-release
|
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
|
elif [ "$ID" == ubuntu ];then
|
||||||
sudo apt-get -qq update
|
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
|
sudo pip install yamllint
|
||||||
else
|
else
|
||||||
echo "Linux distribution not supported"
|
echo "Linux distribution not supported"
|
||||||
|
@ -33,6 +33,12 @@ readonly docker_build_runtime="runc"
|
|||||||
test_images_only="false"
|
test_images_only="false"
|
||||||
test_initrds_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()
|
usage()
|
||||||
{
|
{
|
||||||
cat <<EOT
|
cat <<EOT
|
||||||
@ -60,6 +66,73 @@ Notes:
|
|||||||
EOT
|
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()
|
exit_handler()
|
||||||
{
|
{
|
||||||
if [ "$?" -eq 0 ]
|
if [ "$?" -eq 0 ]
|
||||||
@ -270,6 +343,8 @@ handle_options()
|
|||||||
|
|
||||||
build_rootfs "${distro}" "${rootfs}"
|
build_rootfs "${distro}" "${rootfs}"
|
||||||
|
|
||||||
|
local rootfs_size=$(du -sb "${rootfs}" | awk '{print $1}')
|
||||||
|
|
||||||
if [ "$type" = "image" ]
|
if [ "$type" = "image" ]
|
||||||
then
|
then
|
||||||
# Images need systemd
|
# Images need systemd
|
||||||
@ -278,12 +353,20 @@ handle_options()
|
|||||||
local image_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"
|
local image_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"
|
||||||
|
|
||||||
build_image "${image_path}" "${rootfs}"
|
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}"
|
install_image_create_container "${image_path}"
|
||||||
elif [ "$type" = "initrd" ]
|
elif [ "$type" = "initrd" ]
|
||||||
then
|
then
|
||||||
local initrd_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"
|
local initrd_path="${images_dir}/${type}-${distro}-agent-init-${AGENT_INIT}.img"
|
||||||
|
|
||||||
build_initrd "${initrd_path}" "${rootfs}"
|
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}"
|
install_initrd_create_container "${initrd_path}"
|
||||||
else
|
else
|
||||||
die "invalid type: '$type' for distro $distro option $opt"
|
die "invalid type: '$type' for distro $distro option $opt"
|
||||||
@ -459,6 +542,8 @@ test_all_distros()
|
|||||||
# previous tests.
|
# previous tests.
|
||||||
test_distro_euleros
|
test_distro_euleros
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
show_stats
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user