Commit 7ee11c56 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

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: default avatarMichal Berger <michal.berger@intel.com>
Change-Id: I68f2df89c340dba28d15c4aaac3e106c9f8057d4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16586


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent ece50640
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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