#!/usr/bin/env bash # The state of the machine while the tests run: every few seconds one line with the time, the load and the available # memory and swap of the runner host and, where the kernel offers them, its CPU, memory and disk pressure (PSI). Runs # 502 and 532 stopped for half an hour with every test in progress, browser or not: a hole in the times of this file # says the host (or the container) was suspended, lines without holes say what it was short of. # # .gitea/scripts/macchina.sh [secondi fra una riga e l'altra] [righe, 0 = senza fine] # # It runs in the background of the test step, which ends it. Only numbers of the machine: no names, paths or tokens. set -euo pipefail file="${1:?Indica il file da scrivere.}" ogni="${2:-15}" righe="${3:-0}" [[ "$ogni" =~ ^[0-9]+$ && "$righe" =~ ^[0-9]+$ ]] || { echo "I secondi e le righe devono essere numeri interi." >&2; exit 2; } mkdir -p "$(dirname "$file")" # One value of /proc/meminfo, in MB; nothing where there is no /proc. memoria() { awk -v nome="$1:" '$1 == nome { printf "%d", $2 / 1024 }' /proc/meminfo 2> /dev/null || true } # The ten-second average of the «some» line of one PSI file; nothing where the kernel does not offer it. pressione() { awk '$1 == "some" { sub(/^avg10=/, "", $2); printf "%s", $2 }' "/proc/pressure/$1" 2> /dev/null || true } fatte=0 while :; do carico=$(cut -d ' ' -f 1-3 /proc/loadavg 2> /dev/null || true) printf '%s carico=%s memoria=%s MB scambio=%s MB psi cpu=%s memoria=%s disco=%s\n' \ "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$carico" "$(memoria MemAvailable)" "$(memoria SwapFree)" \ "$(pressione cpu)" "$(pressione memory)" "$(pressione io)" >> "$file" fatte=$((fatte + 1)) if ((righe > 0 && fatte >= righe)); then break fi # With no share in the output of the step: killing the script must not leave the step waiting for this sleep. sleep "$ogni" > /dev/null 2>&1 done