Skip to content

Commit 4aa9826

Browse files
authored
Merge pull request #354 from smuppand/performance
shellcheck: reduce false positives in performance scripts
2 parents e2005a1 + 3fcfcbc commit 4aa9826

5 files changed

Lines changed: 4 additions & 98 deletions

File tree

Runner/suites/Performance/Boot_Systemd_Validate/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ check_dependencies systemctl systemd-analyze uname sed awk grep find sort || {
257257

258258
# --- ensure CPU governors restored on exit (only if we changed it) ---
259259
GOV_CHANGED=0
260+
# shellcheck disable=SC2317 # cleanup is invoked via trap
260261
cleanup() {
261262
if [ "$GOV_CHANGED" -eq 1 ] 2>/dev/null; then
262263
restore_governor

Runner/suites/Performance/Geekbench/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ if [ "$SET_PERF_GOV" = "1" ]; then
297297
set_performance_governor || true
298298
fi
299299

300+
# shellcheck disable=SC2317 # cleanup is invoked via trap
300301
cleanup() {
301302
if [ "$SET_PERF_GOV" = "1" ]; then
302303
restore_governor || true

Runner/suites/Performance/Sysbench_Performance/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ if [ -n "$BASELINE_FILE" ] && [ ! -f "$BASELINE_FILE" ]; then
227227
BASELINE_FILE=""
228228
fi
229229

230+
# shellcheck disable=SC2317 # cleanup is invoked via trap
230231
cleanup() {
231232
restore_governor 2>/dev/null || true
232233
}

Runner/suites/Performance/Tiotest/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ if [ -n "$BASELINE_FILE" ] && [ ! -f "$BASELINE_FILE" ]; then
225225
BASELINE_FILE=""
226226
fi
227227

228+
# shellcheck disable=SC2317 # cleanup is invoked via trap
228229
cleanup() {
229230
restore_governor 2>/dev/null || true
230231
}

Runner/utils/lib_performance.sh

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -864,16 +864,6 @@ perf_kpi_check_previous_reboot() {
864864
perf_kpi_reboot_state_save "$state_file" "$PERF_KPI_BOOT_ID" "$PERF_KPI_UPTIME_SEC" "0" "$PERF_KPI_STATE_ITER_DONE"
865865
}
866866

867-
# ---------------------------------------------------------------------------
868-
# Small math / parsing helpers (POSIX)
869-
# ---------------------------------------------------------------------------
870-
perf_is_number() {
871-
printf '%s\n' "$1" | awk '
872-
BEGIN{ok=0}
873-
/^[0-9]+(\.[0-9]+)?$/ {ok=1}
874-
END{exit(ok?0:1)}'
875-
}
876-
877867
perf_avg_file() {
878868
f=$1
879869
[ -s "$f" ] || { echo ""; return 0; }
@@ -987,56 +977,6 @@ perf_baseline_get() {
987977
# ---------------------------------------------------------------------------
988978
# Sysbench helpers (run + parse + average + optional CSV)
989979
# ---------------------------------------------------------------------------
990-
991-
# Run a command and stream output to console while also writing to a logfile.
992-
# POSIX-safe: uses mkfifo + tee to preserve command exit code.
993-
# Usage: perf_run_cmd_tee /path/to/log -- cmd args...
994-
perf_run_cmd_tee() {
995-
log_file=$1
996-
shift
997-
998-
[ -n "$log_file" ] || return 1
999-
1000-
dir=$(dirname "$log_file")
1001-
mkdir -p "$dir" 2>/dev/null || true
1002-
1003-
fifo="${log_file}.fifo.$$"
1004-
rm -f "$fifo" 2>/dev/null || true
1005-
1006-
if ! mkfifo "$fifo" 2>/dev/null; then
1007-
# Fallback: no fifo support → just log (no live console)
1008-
"$@" >"$log_file" 2>&1
1009-
return $?
1010-
fi
1011-
1012-
# Start tee first (reader)
1013-
tee "$log_file" <"$fifo" &
1014-
tee_pid=$!
1015-
1016-
# Run command, write both stdout+stderr into FIFO (writer)
1017-
"$@" >"$fifo" 2>&1
1018-
rc=$?
1019-
1020-
# Give tee a short window to drain+exit; then kill if still alive (avoid hangs)
1021-
i=0
1022-
while kill -0 "$tee_pid" 2>/dev/null; do
1023-
i=$((i + 1))
1024-
[ "$i" -ge 5 ] && break
1025-
sleep 1
1026-
done
1027-
1028-
if kill -0 "$tee_pid" 2>/dev/null; then
1029-
# tee is still alive unexpectedly → terminate and move on
1030-
kill "$tee_pid" 2>/dev/null || true
1031-
wait "$tee_pid" 2>/dev/null || true
1032-
else
1033-
wait "$tee_pid" 2>/dev/null || true
1034-
fi
1035-
1036-
rm -f "$fifo" 2>/dev/null || true
1037-
return $rc
1038-
}
1039-
1040980
# Parse total time (sec) from sysbench 1.0+ output.
1041981
# Supports both:
1042982
# "total time: 30.0009s"
@@ -1092,44 +1032,6 @@ perf_values_avg() {
10921032
' "$values_file" 2>/dev/null
10931033
}
10941034

1095-
# Optional CSV append (only if CSV_FILE is non-empty).
1096-
# CSV format:
1097-
# timestamp,test,threads,metric,iteration,value
1098-
perf_sysbench_csv_append() {
1099-
csv=$1
1100-
test=$2
1101-
threads=$3
1102-
metric=$4
1103-
iteration=$5
1104-
value=$6
1105-
status=${7:-}
1106-
baseline=${8:-}
1107-
goal=${9:-}
1108-
op=${10:-}
1109-
score_pct=${11:-}
1110-
delta=${12:-}
1111-
1112-
[ -n "$csv" ] || return 0
1113-
[ -n "$value" ] || return 0
1114-
1115-
dir=$(dirname "$csv")
1116-
mkdir -p "$dir" 2>/dev/null || true
1117-
1118-
if [ ! -f "$csv" ] || [ ! -s "$csv" ]; then
1119-
# Backward-compatible: old columns first, new columns appended.
1120-
echo "timestamp,test,threads,metric,iteration,value,status,baseline,goal,op,score_pct,delta" >"$csv"
1121-
fi
1122-
1123-
if command -v nowstamp >/dev/null 2>&1; then
1124-
ts=$(nowstamp)
1125-
else
1126-
ts=$(date "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "unknown")
1127-
fi
1128-
1129-
# Always write all columns; empty fields are OK.
1130-
echo "$ts,$test,$threads,$metric,$iteration,$value,$status,$baseline,$goal,$op,$score_pct,$delta" >>"$csv" 2>/dev/null || true
1131-
}
1132-
11331035
# ---------------------------------------------------------------------------
11341036
# Sysbench helpers
11351037
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)