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 <michal.berger@intel.com>
Change-Id: I68f2df89c340dba28d15c4aaac3e106c9f8057d4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16586
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Michal Berger 2023-01-29 18:15:17 +01:00 committed by Tomasz Zawadzki
parent ece50640a2
commit 7ee11c56ce

View File

@ -7,6 +7,8 @@ set -e
hex() { printf '0x%02x\n' "$@"; } hex() { printf '0x%02x\n' "$@"; }
calc() { bc <<< "scale=2; $*"; }
is_root() { is_root() {
# Talking to local BMC device requires root privileges # Talking to local BMC device requires root privileges
if ((UID)); then if ((UID)); then
@ -346,7 +348,7 @@ get_cpu_socket_reading() {
((${#socket_uj[@]} > 1)) || continue ((${#socket_uj[@]} > 1)) || continue
# Convert to Watts - use bc since $interval can be an actual float # 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)" eval "_socket${_socket_idx}_readings+=($reading)"
power_readings["$socket_name-$socket_idx"]="_socket${_socket_idx}_readings[@]" power_readings["$socket_name-$socket_idx"]="_socket${_socket_idx}_readings[@]"
@ -381,13 +383,13 @@ dump_readings() {
fi fi
total=0 total=0
for reading in "${readings[@]}"; do for reading in "${readings[@]}"; do
((total += ${reading%.*})) total=$(calc "$total + $reading")
done done
avg=$((total / ${#readings[@]})) avg=$(calc "$total / ${#readings[@]}")
readings+=("Total: ${#readings[@]}") readings+=("Total: ${#readings[@]}")
sensor="${sensor//[[:space:]]/_}" 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 '%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 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 printf 'Dumped all to %s\n' "$output_dir/${prefix:+${prefix}_}all_${sensor}.bmc.pm.txt" >&2