metrics: Remove duplicate check of processes from memory test.

This PR removes the common_init function call from the memory
usage script to eliminate duplicate checking that is also done
from the init_env function.

It also eliminates duplicaction of nested conditionals.

Fixes: #9984

Signed-off-by: David Esparza <david.esparza.borquez@intel.com>
This commit is contained in:
David Esparza 2024-07-09 12:34:51 -06:00
parent 37b907dfbc
commit e77d44614b
No known key found for this signature in database
GPG Key ID: EABE0B1A98CC3B7A

View File

@ -47,13 +47,16 @@ trap remove_tmp_file EXIT
# Show help about this script # Show help about this script
function help(){ function help(){
cat << EOF cat << EOF
Usage: $0 <count> <wait_time> [auto] Usage: $0 <count> <wait_time> [auto]
Description: Description:
<count> : Number of containers to run. <count> : Number of containers to run.
<wait_time> : Time in seconds to wait before taking <wait_time> : Time in seconds to wait before taking
metrics. metrics.
[auto] : Optional 'auto KSM settle' mode [auto] : Optional 'auto KSM settle' mode
waits for ksm pages_shared to settle down waits for ksm pages_shared to settle down
EOF EOF
} }
@ -281,7 +284,7 @@ function get_memory_usage(){
metrics_json_start_array metrics_json_start_array
# Check the runtime in order in order to determine which process will # Check the runtime in order in order to determine which process will
# be measured about PSS # be measured about PSS
if [ "${RUNTIME}" == "runc" ]; then if [ "${CTR_RUNTIME}" == "io.containerd.runc.v2" ]; then
runc_workload_mem="$(get_runc_pss_memory)" runc_workload_mem="$(get_runc_pss_memory)"
memory_usage="${runc_workload_mem}" memory_usage="${runc_workload_mem}"
@ -298,7 +301,7 @@ function get_memory_usage(){
} }
EOF EOF
)" )"
else [ "${RUNTIME}" == "kata-runtime" ] || [ "${RUNTIME}" == "kata-qemu" ] else [ "${CTR_RUNTIME}" == "io.containerd.kata.v2" ]
# Get PSS memory of VM runtime components. # Get PSS memory of VM runtime components.
# And check that the smem search has found the process - we get a "0" # And check that the smem search has found the process - we get a "0"
# back if that procedure fails (such as if a process has changed its name # back if that procedure fails (such as if a process has changed its name
@ -371,38 +374,30 @@ EOF
} }
function main(){ function main(){
# Collect kata-env data
common_init
# Verify enough arguments # Verify enough arguments
if [ $# != 2 ] && [ $# != 3 ];then if [ $# != 2 ] && [ $# != 3 ];then
echo >&2 "error: Not enough arguments [$@]"
help help
exit 1 die "Not enough arguments [$@]"
fi
if [ "${CTR_RUNTIME}" != "io.containerd.runc.v2" ] && [ "${CTR_RUNTIME}" != "io.containerd.kata.v2" ]; then
die "Unknown runtime: ${CTR_RUNTIME}."
fi fi
#Check for KSM before reporting test name, as it can modify it #Check for KSM before reporting test name, as it can modify it
check_for_ksm check_for_ksm
check_cmds "${SMEM_BIN}" bc check_cmds "${SMEM_BIN}" bc
clean_env_ctr
init_env init_env
check_images "${IMAGE}" check_images "${IMAGE}"
if [ "${CTR_RUNTIME}" == "io.containerd.kata.v2" ]; then
export RUNTIME="kata-runtime"
elif [ "${CTR_RUNTIME}" == "io.containerd.runc.v2" ]; then
export RUNTIME="runc"
else
die "Unknown runtime ${CTR_RUNTIME}"
fi
metrics_json_init metrics_json_init
save_config save_config
get_memory_usage get_memory_usage
if [ "${RUNTIME}" == "runc" ]; then if [ "${CTR_RUNTIME}" == "io.containerd.kata.v2" ]; then
get_runc_individual_memory
elif [ "${RUNTIME}" == "kata-runtime" ]; then
get_individual_memory get_individual_memory
elif [ "${CTR_RUNTIME}" == "io.containerd.runc.v2" ]; then
get_runc_individual_memory
fi fi
info "memory usage test completed" info "memory usage test completed"