Merge pull request #136 from Salamandar/metrics

Add metrics measurements to tests runs
This commit is contained in:
Alexandre Aubin 2023-02-21 15:37:38 +01:00 committed by GitHub
commit 7ca73f80b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View file

@ -180,6 +180,43 @@ stop_timer () {
fi 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 # Package check self-upgrade
#================================================= #=================================================

View file

@ -111,6 +111,9 @@ TEST_LAUNCHER () {
# And keep this value separately # And keep this value separately
local global_start_timer=$starttime local global_start_timer=$starttime
# Start metrics measurement
metrics_start
current_test_id=$(basename $testfile | cut -d. -f1) current_test_id=$(basename $testfile | cut -d. -f1)
current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json" current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json"
current_test_results="$TEST_CONTEXT/results/$current_test_id.json" current_test_results="$TEST_CONTEXT/results/$current_test_id.json"
@ -168,6 +171,9 @@ TEST_LAUNCHER () {
# End the timer for the test # End the timer for the test
stop_timer one_test stop_timer one_test
# Stop metrics and show results
metrics_stop
LXC_STOP $LXC_NAME LXC_STOP $LXC_NAME
# Update the lock file with the date of the last finished test. # Update the lock file with the date of the last finished test.