mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
metrics: fix parsing issue on memory-usage test
This PR fixes an issues in the parsing results stage, by collecting just the n-results from the n-running containers, discarding irrelevant data. Fixes: #7774 Signed-off-by: David Esparza <david.esparza.borquez@intel.com>
This commit is contained in:
parent
708b0a3052
commit
538c965c2b
@ -19,7 +19,7 @@ source "${SCRIPT_PATH}/../lib/common.bash"
|
|||||||
# Busybox image: Choose a small workload image, this is
|
# Busybox image: Choose a small workload image, this is
|
||||||
# in order to measure the runtime footprint, not the workload
|
# in order to measure the runtime footprint, not the workload
|
||||||
# footprint.
|
# footprint.
|
||||||
IMAGE='quay.io/prometheus/busybox:latest'
|
IMAGE="quay.io/prometheus/busybox:latest"
|
||||||
|
|
||||||
CMD='tail -f /dev/null'
|
CMD='tail -f /dev/null'
|
||||||
NUM_CONTAINERS="$1"
|
NUM_CONTAINERS="$1"
|
||||||
@ -31,6 +31,11 @@ KSM_ENABLE_FILE="/sys/kernel/mm/ksm/run"
|
|||||||
MEM_TMP_FILE=$(mktemp meminfo.XXXXXXXXXX)
|
MEM_TMP_FILE=$(mktemp meminfo.XXXXXXXXXX)
|
||||||
PS_TMP_FILE=$(mktemp psinfo.XXXXXXXXXX)
|
PS_TMP_FILE=$(mktemp psinfo.XXXXXXXXXX)
|
||||||
|
|
||||||
|
# Variables used to collect memory footprint
|
||||||
|
global_hypervisor_mem=0
|
||||||
|
global_virtiofsd_mem=0
|
||||||
|
global_shim_mem=0
|
||||||
|
|
||||||
function remove_tmp_file() {
|
function remove_tmp_file() {
|
||||||
rm -rf "${MEM_TMP_FILE}" "${PS_TMP_FILE}"
|
rm -rf "${MEM_TMP_FILE}" "${PS_TMP_FILE}"
|
||||||
}
|
}
|
||||||
@ -85,14 +90,14 @@ EOF
|
|||||||
# This function measures the PSS average
|
# This function measures the PSS average
|
||||||
# memory of a process.
|
# memory of a process.
|
||||||
function get_pss_memory(){
|
function get_pss_memory(){
|
||||||
ps="$1"
|
local ps="${1}"
|
||||||
mem_amount=0
|
local shim_result_on="${2:-0}"
|
||||||
count=0
|
local mem_amount=0
|
||||||
avg=0
|
local count=0
|
||||||
|
local avg=0
|
||||||
|
|
||||||
if [ -z "${ps}" ]; then
|
[ -z "${ps}" ] && die "No argument to get_pss_memory()"
|
||||||
die "No argument to get_pss_memory()"
|
ps="$(readlink -f ${ps})"
|
||||||
fi
|
|
||||||
|
|
||||||
# Save all the processes names
|
# Save all the processes names
|
||||||
# This will be help us to retrieve raw information
|
# This will be help us to retrieve raw information
|
||||||
@ -104,19 +109,23 @@ function get_pss_memory(){
|
|||||||
# This will help us to retrieve raw information
|
# This will help us to retrieve raw information
|
||||||
echo "${data}" >> "${MEM_TMP_FILE}"
|
echo "${data}" >> "${MEM_TMP_FILE}"
|
||||||
|
|
||||||
gral_data=$(echo "${data// /+}" | bc)
|
for i in ${data[*]}; do
|
||||||
for i in "${gral_data}"; do
|
if [ ${i} -gt 0 ]; then
|
||||||
if (( $i > 0 ));then
|
let "mem_amount+=i"
|
||||||
mem_amount=$(( i + mem_amount ))
|
let "count+=1"
|
||||||
(( count++ ))
|
[ $count -eq $NUM_CONTAINERS ] && break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( "${count}" > 0 ));then
|
[ ${count} -eq 0 ] && die "No pss memory was measured for PID: ${ps}"
|
||||||
avg=$(bc -l <<< "scale=2; ${mem_amount} / ${count}")
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${avg}"
|
avg=$(bc -l <<< "scale=2; ${mem_amount} / ${count}")
|
||||||
|
|
||||||
|
if [ "${shim_result_on}" -eq "1" ]; then
|
||||||
|
global_shim_mem="${avg}"
|
||||||
|
else
|
||||||
|
global_hypervisor_mem="${avg}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ppid() {
|
function ppid() {
|
||||||
@ -137,12 +146,9 @@ function get_pss_memory_virtiofsd() {
|
|||||||
avg=0
|
avg=0
|
||||||
|
|
||||||
virtiofsd_path=${1:-}
|
virtiofsd_path=${1:-}
|
||||||
if [ -z "${virtiofsd_path}" ]; then
|
[ -z "${virtiofsd_path}" ] && die "virtiofsd_path not provided"
|
||||||
die "virtiofsd_path not provided"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${virtiofsd_path}" >> "${PS_TMP_FILE}"
|
echo "${virtiofsd_path}" >> "${PS_TMP_FILE}"
|
||||||
|
|
||||||
virtiofsd_pids=$(ps aux | grep [v]irtiofsd | awk '{print $2}' | head -1)
|
virtiofsd_pids=$(ps aux | grep [v]irtiofsd | awk '{print $2}' | head -1)
|
||||||
data=$(sudo smem --no-header -P "^${virtiofsd_path}" -c pid -c "pid pss")
|
data=$(sudo smem --no-header -P "^${virtiofsd_path}" -c pid -c "pid pss")
|
||||||
|
|
||||||
@ -164,15 +170,13 @@ function get_pss_memory_virtiofsd() {
|
|||||||
|
|
||||||
if ((pss_process > 0)); then
|
if ((pss_process > 0)); then
|
||||||
mem_amount=$((pss_process + mem_amount))
|
mem_amount=$((pss_process + mem_amount))
|
||||||
((count++))
|
let "count+=1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( "${count}" > 0 ));then
|
[ "${count}" -gt 0 ] && global_virtiofsd_mem=$(bc -l <<< "scale=2; ${mem_amount} / ${count}")
|
||||||
avg=$(bc -l <<< "scale=2; ${mem_amount} / ${count}")
|
|
||||||
fi
|
|
||||||
echo "${avg}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_individual_memory(){
|
function get_individual_memory(){
|
||||||
@ -278,22 +282,25 @@ EOF
|
|||||||
# Now if you do not have enough rights
|
# Now if you do not have enough rights
|
||||||
# the smem failure to read the stats will also be trapped.
|
# the smem failure to read the stats will also be trapped.
|
||||||
|
|
||||||
hypervisor_mem="$(get_pss_memory ${HYPERVISOR_PATH})"
|
get_pss_memory ${HYPERVISOR_PATH}
|
||||||
if [ "${hypervisor_mem}" == "0" ]; then
|
|
||||||
|
if [ "${global_hypervisor_mem}" == "0" ]; then
|
||||||
die "Failed to find PSS for ${HYPERVISOR_PATH}"
|
die "Failed to find PSS for ${HYPERVISOR_PATH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
virtiofsd_mem="$(get_pss_memory_virtiofsd ${VIRTIOFSD_PATH})"
|
get_pss_memory_virtiofsd ${VIRTIOFSD_PATH}
|
||||||
if [ "${virtiofsd_mem}" == "0" ]; then
|
|
||||||
|
if [ "${global_virtiofsd_mem}" == "0" ]; then
|
||||||
echo >&2 "WARNING: Failed to find PSS for ${VIRTIOFSD_PATH}"
|
echo >&2 "WARNING: Failed to find PSS for ${VIRTIOFSD_PATH}"
|
||||||
fi
|
fi
|
||||||
shim_mem="$(get_pss_memory ${SHIM_PATH})"
|
|
||||||
if [ "${shim_mem}" == "0" ]; then
|
get_pss_memory ${SHIM_PATH} 1
|
||||||
|
|
||||||
|
if [ "${global_shim_mem}" == "0" ]; then
|
||||||
die "Failed to find PSS for ${SHIM_PATH}"
|
die "Failed to find PSS for ${SHIM_PATH}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mem_usage="$(bc -l <<< "scale=2; ${hypervisor_mem} +${virtiofsd_mem} + ${shim_mem}")"
|
mem_usage="$(bc -l <<< "scale=2; ${global_hypervisor_mem} + ${global_virtiofsd_mem} + ${global_shim_mem}")"
|
||||||
memory_usage="${mem_usage}"
|
|
||||||
|
|
||||||
local json="$(cat << EOF
|
local json="$(cat << EOF
|
||||||
{
|
{
|
||||||
@ -302,15 +309,15 @@ EOF
|
|||||||
"Units" : "KB"
|
"Units" : "KB"
|
||||||
},
|
},
|
||||||
"qemus": {
|
"qemus": {
|
||||||
"Result": ${hypervisor_mem},
|
"Result": ${global_hypervisor_mem},
|
||||||
"Units" : "KB"
|
"Units" : "KB"
|
||||||
},
|
},
|
||||||
"virtiofsds": {
|
"virtiofsds": {
|
||||||
"Result": ${virtiofsd_mem},
|
"Result": ${global_virtiofsd_mem},
|
||||||
"Units" : "KB"
|
"Units" : "KB"
|
||||||
},
|
},
|
||||||
"shims": {
|
"shims": {
|
||||||
"Result": ${shim_mem},
|
"Result": ${global_shim_mem},
|
||||||
"Units" : "KB"
|
"Units" : "KB"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -354,9 +361,7 @@ function main(){
|
|||||||
|
|
||||||
#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
|
||||||
|
# init_env
|
||||||
init_env
|
|
||||||
|
|
||||||
check_cmds "${SMEM_BIN}" bc
|
check_cmds "${SMEM_BIN}" bc
|
||||||
check_images "${IMAGE}"
|
check_images "${IMAGE}"
|
||||||
|
|
||||||
@ -378,6 +383,7 @@ function main(){
|
|||||||
get_individual_memory
|
get_individual_memory
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
info "memory usage test completed"
|
||||||
metrics_json_save
|
metrics_json_save
|
||||||
clean_env_ctr
|
clean_env_ctr
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user