mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 06:52:13 +00:00
metrics: Add function keyword to to helper metrics functions
Use the 'function' keyword to prevent bash aliases from colliding with other function's name. Signed-off-by: David Esparza <david.esparza.borquez@intel.com>
This commit is contained in:
parent
1ca17c2f70
commit
4e396e7285
@ -47,14 +47,14 @@ quay.io/libpod"
|
|||||||
#
|
#
|
||||||
# cmds=(“cmd1” “cmd2”)
|
# cmds=(“cmd1” “cmd2”)
|
||||||
# check_cmds "${cmds[@]}"
|
# check_cmds "${cmds[@]}"
|
||||||
check_cmds()
|
function check_cmds()
|
||||||
{
|
{
|
||||||
local cmd req_cmds=( "$@" )
|
local cmd req_cmds=( "$@" )
|
||||||
for cmd in "${req_cmds[@]}"; do
|
for cmd in "${req_cmds[@]}"; do
|
||||||
if ! command -v "$cmd" > /dev/null 2>&1; then
|
if ! command -v "$cmd" > /dev/null 2>&1; then
|
||||||
die "command $cmd not available"
|
die "command $cmd not available"
|
||||||
fi
|
fi
|
||||||
echo "command: $cmd: yes"
|
info "command: $cmd: yes"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,19 +68,20 @@ check_cmds()
|
|||||||
#
|
#
|
||||||
# images=(“img1” “img2”)
|
# images=(“img1” “img2”)
|
||||||
# check_imgs "${images[@]}"
|
# check_imgs "${images[@]}"
|
||||||
check_images()
|
function check_images()
|
||||||
{
|
{
|
||||||
local img req_images=( "$@" )
|
local img req_images=( "$@" )
|
||||||
for img in "${req_images[@]}"; do
|
for img in "${req_images[@]}"; do
|
||||||
echo "ctr pull'ing: $img"
|
info "ctr pull'ing: $img"
|
||||||
if ! sudo "${CTR_EXE}" image pull "$img"; then
|
if ! sudo "${CTR_EXE}" image pull "$img"; then
|
||||||
die "Failed to pull image $img"
|
die "Failed to pull image $img"
|
||||||
fi
|
fi
|
||||||
echo "ctr pull'd: $img"
|
info "ctr pull'd: $img"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_build_dockerfile() {
|
function generate_build_dockerfile()
|
||||||
|
{
|
||||||
local dockerfile="$1"
|
local dockerfile="$1"
|
||||||
local image="$2"
|
local image="$2"
|
||||||
local map_key="$3"
|
local map_key="$3"
|
||||||
@ -99,14 +100,14 @@ generate_build_dockerfile() {
|
|||||||
# This function performs a build on the image names
|
# This function performs a build on the image names
|
||||||
# passed in, to ensure that we have the latest changes from
|
# passed in, to ensure that we have the latest changes from
|
||||||
# the dockerfiles
|
# the dockerfiles
|
||||||
build_dockerfile_image()
|
function build_dockerfile_image()
|
||||||
{
|
{
|
||||||
local image="$1"
|
local image="$1"
|
||||||
local dockerfile_path="$2"
|
local dockerfile_path="$2"
|
||||||
local dockerfile_dir=${2%/*}
|
local dockerfile_dir=${2%/*}
|
||||||
|
|
||||||
if [ -f "$dockerfile_path" ]; then
|
if [ -f "$dockerfile_path" ]; then
|
||||||
echo "docker building $image"
|
info "docker building $image"
|
||||||
if ! sudo "${DOCKER_EXE}" build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --label "$image" --tag "${image}" -f "$dockerfile_path" "$dockerfile_dir"; then
|
if ! sudo "${DOCKER_EXE}" build --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --label "$image" --tag "${image}" -f "$dockerfile_path" "$dockerfile_dir"; then
|
||||||
die "Failed to docker build image $image"
|
die "Failed to docker build image $image"
|
||||||
fi
|
fi
|
||||||
@ -119,7 +120,7 @@ build_dockerfile_image()
|
|||||||
|
|
||||||
# This function removes the ctr image, builds a new one using a dockerfile
|
# This function removes the ctr image, builds a new one using a dockerfile
|
||||||
# and imports the image from docker to ctr
|
# and imports the image from docker to ctr
|
||||||
check_ctr_images()
|
function check_ctr_images()
|
||||||
{
|
{
|
||||||
local ctr_image="$1"
|
local ctr_image="$1"
|
||||||
local dockerfile_path="$2"
|
local dockerfile_path="$2"
|
||||||
@ -138,7 +139,7 @@ check_ctr_images()
|
|||||||
|
|
||||||
# A one time (per uber test cycle) init that tries to get the
|
# A one time (per uber test cycle) init that tries to get the
|
||||||
# system to a 'known state' as much as possible
|
# system to a 'known state' as much as possible
|
||||||
metrics_onetime_init()
|
function metrics_onetime_init()
|
||||||
{
|
{
|
||||||
# The onetime init must be called once, and only once
|
# The onetime init must be called once, and only once
|
||||||
if [ ! -z "$onetime_init_done" ]; then
|
if [ ! -z "$onetime_init_done" ]; then
|
||||||
@ -155,14 +156,14 @@ metrics_onetime_init()
|
|||||||
|
|
||||||
# Print a banner to the logs noting clearly which test
|
# Print a banner to the logs noting clearly which test
|
||||||
# we are about to run
|
# we are about to run
|
||||||
test_banner()
|
function test_banner()
|
||||||
{
|
{
|
||||||
echo -e "\n===== starting test [$1] ====="
|
info -e "\n===== starting test [$1] ====="
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialization/verification environment. This function makes
|
# Initialization/verification environment. This function makes
|
||||||
# minimal steps for metrics/tests execution.
|
# minimal steps for metrics/tests execution.
|
||||||
init_env()
|
function init_env()
|
||||||
{
|
{
|
||||||
test_banner "${TEST_NAME}"
|
test_banner "${TEST_NAME}"
|
||||||
|
|
||||||
@ -183,7 +184,8 @@ init_env()
|
|||||||
# This function checks if there are containers or
|
# This function checks if there are containers or
|
||||||
# shim/proxy/hypervisor processes up, if found, they are
|
# shim/proxy/hypervisor processes up, if found, they are
|
||||||
# killed to start test with clean environment.
|
# killed to start test with clean environment.
|
||||||
kill_processes_before_start() {
|
function kill_processes_before_start()
|
||||||
|
{
|
||||||
DOCKER_PROCS=$(sudo "${DOCKER_EXE}" ps -q)
|
DOCKER_PROCS=$(sudo "${DOCKER_EXE}" ps -q)
|
||||||
[[ -n "${DOCKER_PROCS}" ]] && clean_env
|
[[ -n "${DOCKER_PROCS}" ]] && clean_env
|
||||||
|
|
||||||
@ -195,26 +197,29 @@ kill_processes_before_start() {
|
|||||||
|
|
||||||
# Generate a random name - generally used when creating containers, but can
|
# Generate a random name - generally used when creating containers, but can
|
||||||
# be used for any other appropriate purpose
|
# be used for any other appropriate purpose
|
||||||
random_name() {
|
function random_name()
|
||||||
|
{
|
||||||
mktemp -u kata-XXXXXX
|
mktemp -u kata-XXXXXX
|
||||||
}
|
}
|
||||||
|
|
||||||
show_system_ctr_state() {
|
function show_system_ctr_state()
|
||||||
echo "Showing system state:"
|
{
|
||||||
echo " --Check containers--"
|
info "Showing system state:"
|
||||||
|
info " --Check containers--"
|
||||||
sudo "${CTR_EXE}" c list
|
sudo "${CTR_EXE}" c list
|
||||||
echo " --Check tasks--"
|
info " --Check tasks--"
|
||||||
sudo "${CTR_EXE}" task list
|
sudo "${CTR_EXE}" task list
|
||||||
|
|
||||||
local processes="containerd-shim-kata-v2"
|
local processes="containerd-shim-kata-v2"
|
||||||
|
|
||||||
for p in ${processes}; do
|
for p in ${processes}; do
|
||||||
echo " --pgrep ${p}--"
|
info " --pgrep ${p}--"
|
||||||
pgrep -a ${p}
|
pgrep -a ${p}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
common_init(){
|
function common_init()
|
||||||
|
{
|
||||||
if [ "$CTR_RUNTIME" == "io.containerd.kata.v2" ] || [ "$RUNTIME" == "containerd-shim-kata-v2" ]; then
|
if [ "$CTR_RUNTIME" == "io.containerd.kata.v2" ] || [ "$RUNTIME" == "containerd-shim-kata-v2" ]; then
|
||||||
extract_kata_env
|
extract_kata_env
|
||||||
else
|
else
|
||||||
@ -225,17 +230,18 @@ common_init(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Save the current KSM settings so we can restore them later
|
# Save the current KSM settings so we can restore them later
|
||||||
save_ksm_settings(){
|
function save_ksm_settings()
|
||||||
echo "saving KSM settings"
|
{
|
||||||
|
info "saving KSM settings"
|
||||||
ksm_stored_run=$(cat ${KSM_ENABLE_FILE})
|
ksm_stored_run=$(cat ${KSM_ENABLE_FILE})
|
||||||
ksm_stored_pages=$(cat ${KSM_ENABLE_FILE})
|
ksm_stored_pages=$(cat ${KSM_ENABLE_FILE})
|
||||||
ksm_stored_sleep=$(cat ${KSM_ENABLE_FILE})
|
ksm_stored_sleep=$(cat ${KSM_ENABLE_FILE})
|
||||||
}
|
}
|
||||||
|
|
||||||
set_ksm_aggressive(){
|
function set_ksm_aggressive()
|
||||||
echo "setting KSM to aggressive mode"
|
{
|
||||||
|
info "setting KSM to aggressive mode"
|
||||||
# Flip the run off/on to ensure a restart/rescan
|
# Flip the run off/on to ensure a restart/rescan
|
||||||
sudo bash -c "echo 0 > ${KSM_ENABLE_FILE}"
|
sudo bash -c "echo 0 > ${KSM_ENABLE_FILE}"
|
||||||
sudo bash -c "echo ${KSM_AGGRESIVE_PAGES} > ${KSM_PAGES_FILE}"
|
sudo bash -c "echo ${KSM_AGGRESIVE_PAGES} > ${KSM_PAGES_FILE}"
|
||||||
@ -245,7 +251,7 @@ set_ksm_aggressive(){
|
|||||||
if [ "${KATA_HYPERVISOR}" == "qemu" ]; then
|
if [ "${KATA_HYPERVISOR}" == "qemu" ]; then
|
||||||
# Disable virtio-fs and save whether it was enabled previously
|
# Disable virtio-fs and save whether it was enabled previously
|
||||||
set_virtio_out=$(sudo -E PATH="$PATH" "${LIB_DIR}/../../.ci/set_kata_config.sh" shared_fs virtio-9p)
|
set_virtio_out=$(sudo -E PATH="$PATH" "${LIB_DIR}/../../.ci/set_kata_config.sh" shared_fs virtio-9p)
|
||||||
echo "${set_virtio_out}"
|
info "${set_virtio_out}"
|
||||||
grep -q "already" <<< "${set_virtio_out}" || was_virtio_fs=true;
|
grep -q "already" <<< "${set_virtio_out}" || was_virtio_fs=true;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -256,8 +262,9 @@ restore_virtio_fs(){
|
|||||||
info "Not restoring virtio-fs since it wasn't enabled previously"
|
info "Not restoring virtio-fs since it wasn't enabled previously"
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_ksm_settings(){
|
function restore_ksm_settings()
|
||||||
echo "restoring KSM settings"
|
{
|
||||||
|
info "restoring KSM settings"
|
||||||
# First turn off the run to ensure if we are then re-enabling
|
# First turn off the run to ensure if we are then re-enabling
|
||||||
# that any changes take effect
|
# that any changes take effect
|
||||||
sudo bash -c "echo 0 > ${KSM_ENABLE_FILE}"
|
sudo bash -c "echo 0 > ${KSM_ENABLE_FILE}"
|
||||||
@ -267,15 +274,17 @@ restore_ksm_settings(){
|
|||||||
[ "${KATA_HYPERVISOR}" == "qemu" ] && restore_virtio_fs
|
[ "${KATA_HYPERVISOR}" == "qemu" ] && restore_virtio_fs
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_ksm(){
|
function disable_ksm()
|
||||||
echo "disabling KSM"
|
{
|
||||||
|
info "disabling KSM"
|
||||||
sudo bash -c "echo 0 > ${KSM_ENABLE_FILE}"
|
sudo bash -c "echo 0 > ${KSM_ENABLE_FILE}"
|
||||||
[ "${KATA_HYPERVISOR}" == "qemu" ] && restore_virtio_fs
|
[ "${KATA_HYPERVISOR}" == "qemu" ] && restore_virtio_fs
|
||||||
}
|
}
|
||||||
|
|
||||||
# See if KSM is enabled.
|
# See if KSM is enabled.
|
||||||
# If so, amend the test name to reflect that
|
# If so, amend the test name to reflect that
|
||||||
check_for_ksm(){
|
function check_for_ksm()
|
||||||
|
{
|
||||||
if [ ! -f ${KSM_ENABLE_FILE} ]; then
|
if [ ! -f ${KSM_ENABLE_FILE} ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -294,7 +303,8 @@ check_for_ksm(){
|
|||||||
# a full scan has managed to do few new merges)
|
# a full scan has managed to do few new merges)
|
||||||
#
|
#
|
||||||
# arg1 - timeout in seconds
|
# arg1 - timeout in seconds
|
||||||
wait_ksm_settle(){
|
function wait_ksm_settle()
|
||||||
|
{
|
||||||
[[ "$RUNTIME" == "runc" ]] || [[ "$CTR_RUNTIME" == "io.containerd.runc.v2" ]] && return
|
[[ "$RUNTIME" == "runc" ]] || [[ "$CTR_RUNTIME" == "io.containerd.runc.v2" ]] && return
|
||||||
local t pcnt
|
local t pcnt
|
||||||
local oldscan=-1 newscan
|
local oldscan=-1 newscan
|
||||||
@ -305,7 +315,7 @@ wait_ksm_settle(){
|
|||||||
# Wait some time for KSM to kick in to avoid early dismissal
|
# Wait some time for KSM to kick in to avoid early dismissal
|
||||||
for ((t=0; t<5; t++)); do
|
for ((t=0; t<5; t++)); do
|
||||||
pages=$(cat "${KSM_PAGES_SHARED}")
|
pages=$(cat "${KSM_PAGES_SHARED}")
|
||||||
[[ "$pages" -ne 0 ]] && echo "Discovered KSM activity" && break
|
[[ "$pages" -ne 0 ]] && info "Discovered KSM activity" && break
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -315,13 +325,13 @@ wait_ksm_settle(){
|
|||||||
|
|
||||||
newscan=$(cat /sys/kernel/mm/ksm/full_scans)
|
newscan=$(cat /sys/kernel/mm/ksm/full_scans)
|
||||||
newpages=$(cat "${KSM_PAGES_SHARED}")
|
newpages=$(cat "${KSM_PAGES_SHARED}")
|
||||||
[[ "$newpages" -eq 0 ]] && echo "No need to wait for KSM to settle" && return
|
[[ "$newpages" -eq 0 ]] && info "No need to wait for KSM to settle" && return
|
||||||
|
|
||||||
if (( newscan != oldscan )); then
|
if (( newscan != oldscan )); then
|
||||||
echo -e "\nnew full_scan ($oldscan to $newscan)"
|
info -e "\nnew full_scan ($oldscan to $newscan)"
|
||||||
|
|
||||||
# Do we have a previous scan to compare with
|
# Do we have a previous scan to compare with
|
||||||
echo "check pages $oldpages to $newpages"
|
info "check pages $oldpages to $newpages"
|
||||||
|
|
||||||
if (( oldpages != -1 )); then
|
if (( oldpages != -1 )); then
|
||||||
# avoid divide by zero problems
|
# avoid divide by zero problems
|
||||||
@ -330,14 +340,14 @@ wait_ksm_settle(){
|
|||||||
# abs()
|
# abs()
|
||||||
pcnt=$(( $pcnt * -1 ))
|
pcnt=$(( $pcnt * -1 ))
|
||||||
|
|
||||||
echo "$oldpages to $newpages is ${pcnt}%"
|
info "$oldpages to $newpages is ${pcnt}%"
|
||||||
|
|
||||||
if (( $pcnt <= 5 )); then
|
if (( $pcnt <= 5 )); then
|
||||||
echo "KSM stabilised at ${t}s"
|
info "KSM stabilised at ${t}s"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$oldpages KSM pages... waiting"
|
info "$oldpages KSM pages... waiting"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
oldscan=$newscan
|
oldscan=$newscan
|
||||||
@ -347,7 +357,7 @@ wait_ksm_settle(){
|
|||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
echo "Timed out after ${1}s waiting for KSM to settle"
|
info "Timed out after ${1}s waiting for KSM to settle"
|
||||||
}
|
}
|
||||||
|
|
||||||
common_init
|
common_init
|
||||||
|
Loading…
Reference in New Issue
Block a user