From 7ee11c56ce4c1e7dab43ed78244e7660271354f6 Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Sun, 29 Jan 2023 18:15:17 +0100 Subject: [PATCH] perf/pm: Use bc while dumping all the readings This is done to calculate readings with better precision and fix the case where calculation of total reading from given entity would fail if it was < 1 (as bc drops the leading 0, leaving e.g. .42). Signed-off-by: Michal Berger Change-Id: I68f2df89c340dba28d15c4aaac3e106c9f8057d4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16586 Reviewed-by: Konrad Sztyber Tested-by: SPDK CI Jenkins Reviewed-by: Karol Latecki Reviewed-by: Jim Harris --- scripts/perf/pm/collect-bmc-pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/perf/pm/collect-bmc-pm b/scripts/perf/pm/collect-bmc-pm index 54f544700..45671eb12 100755 --- a/scripts/perf/pm/collect-bmc-pm +++ b/scripts/perf/pm/collect-bmc-pm @@ -7,6 +7,8 @@ set -e hex() { printf '0x%02x\n' "$@"; } +calc() { bc <<< "scale=2; $*"; } + is_root() { # Talking to local BMC device requires root privileges if ((UID)); then @@ -346,7 +348,7 @@ get_cpu_socket_reading() { ((${#socket_uj[@]} > 1)) || continue # Convert to Watts - use bc since $interval can be an actual float - reading=$(bc <<< "scale=2; (${socket_uj[-1]} - ${socket_uj[-2]}) / 1000000 / $interval") + reading=$(calc "(${socket_uj[-1]} - ${socket_uj[-2]}) / 1000000 / $interval") eval "_socket${_socket_idx}_readings+=($reading)" power_readings["$socket_name-$socket_idx"]="_socket${_socket_idx}_readings[@]" @@ -381,13 +383,13 @@ dump_readings() { fi total=0 for reading in "${readings[@]}"; do - ((total += ${reading%.*})) + total=$(calc "$total + $reading") done - avg=$((total / ${#readings[@]})) + avg=$(calc "$total / ${#readings[@]}") readings+=("Total: ${#readings[@]}") sensor="${sensor//[[:space:]]/_}" - printf '%u\n' "$avg" > "$output_dir/${prefix:+${prefix}_}avg_${sensor}.bmc.pm.txt" + printf '%s\n' "$avg" > "$output_dir/${prefix:+${prefix}_}avg_${sensor}.bmc.pm.txt" printf '%s\n' "${readings[@]}" > "$output_dir/${prefix:+${prefix}_}all_${sensor}.bmc.pm.txt" printf 'Dumped avg to %s\n' "$output_dir/${prefix:+${prefix}_}avg_${sensor}.bmc.pm.txt" >&2 printf 'Dumped all to %s\n' "$output_dir/${prefix:+${prefix}_}all_${sensor}.bmc.pm.txt" >&2