From f0e844d26079f3dc0450560f5f1f5c3698849526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 20 Jan 2023 14:00:54 +0100 Subject: [PATCH] Add metrics measurements to tests runs --- lib/common.sh | 37 +++++++++++++++++++++++++++++++++++++ lib/tests_coordination.sh | 6 ++++++ 2 files changed, 43 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 5863fcf..bf0443f 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -180,6 +180,43 @@ stop_timer () { fi } +#================================================= +# Resource metrics helpers +#================================================= +# Communication between the background thread and the main one +# is done via a shared memory. + +get_ram_usage() { + free -m | grep Mem | awk '{print $3}' +} + +metrics_background_thread() { + declare -A resources=( [ram]=0 ) + while true; do + ram_usage=$(get_ram_usage) + echo "$ram_usage" + if ((ram_usage > resources[ram])); then + resources[ram]=$ram_usage + fi + declare -p resources > "$TEST_CONTEXT/metrics_vars" + sleep 1 + done +} + +metrics_start() { + ram_usage_base=$(get_ram_usage) + metrics_background_thread & + metrics_background_thread_pid=$! +} + +metrics_stop() { + kill "$metrics_background_thread_pid" + source "$TEST_CONTEXT/metrics_vars" + + max_ram_usage_diff=$((resources[ram] - ram_usage_base)) + log_info "RAM usage for this test: ${max_ram_usage_diff}MB (total: ${resources[ram]}MB)" +} + #================================================= # Package check self-upgrade #================================================= diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 7fefd3a..0fb5f59 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -104,6 +104,9 @@ TEST_LAUNCHER () { # And keep this value separately local global_start_timer=$starttime + # Start metrics measurement + metrics_start + current_test_id=$(basename $testfile | cut -d. -f1) current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json" current_test_results="$TEST_CONTEXT/results/$current_test_id.json" @@ -153,6 +156,9 @@ TEST_LAUNCHER () { # End the timer for the test stop_timer one_test + # Stop metrics and show results + metrics_stop + LXC_STOP $LXC_NAME # Update the lock file with the date of the last finished test.