summaryrefslogtreecommitdiff
diff options
authorPMR <pmr@pmr-lander>2017-01-03 20:29:27 +0000
committerPMR <pmr@pmr-lander>2017-01-03 20:29:27 +0000
commit004fe2c354bc49eb498e58caf4ef1fa506171d4e (patch)
tree48e63eca2b3946b2213d6b10ffefafdcccdcc443
parent06e7e7853112fd63e8d64154ce2073526a355f3b (diff)
parent7c1fa80661af99fd64e24714d9624229773f0a01 (diff)
Merge #314029 from ~rodsmith/plainbox-provider-checkbox:fix-disk-cpu-load
-rwxr-xr-xbin/disk_cpu_load21
1 files changed, 19 insertions, 2 deletions
diff --git a/bin/disk_cpu_load b/bin/disk_cpu_load
index 5e0d0eb..93b1569 100755
--- a/bin/disk_cpu_load
+++ b/bin/disk_cpu_load
@@ -24,13 +24,14 @@
#
# Usage:
# disk_cpu_load [ --max-load <load> ] [ --xfer <mebibytes> ]
-# [ <device-filename> ]
+# [ --verbose ] [ <device-filename> ]
#
# Parameters:
# --max-load <load> -- The maximum acceptable CPU load, as a percentage.
# Defaults to 30.
# --xfer <mebibytes> -- The amount of data to read from the disk, in
# mebibytes. Defaults to 4096 (4 GiB).
+# --verbose -- If present, produce more verbose output
# <device-filename> -- This is the WHOLE-DISK device filename (with or
# without "/dev/"), e.g. "sda" or "/dev/sda". The
# script finds a filesystem on that device, mounts
@@ -44,6 +45,7 @@ set -e
get_params() {
disk_device="/dev/sda"
short_device="sda"
+ verbose=0
max_load=30
xfer=4096
while [ $# -gt 0 ] ; do
@@ -54,6 +56,8 @@ get_params() {
--xfer) xfer="$2"
shift
;;
+ --verbose) verbose=1
+ ;;
*) disk_device="/dev/$1"
disk_device=`echo $disk_device | sed "s/\/dev\/\/dev/\/dev/g"`
short_device=$(echo $disk_device | sed "s/\/dev//g")
@@ -109,8 +113,15 @@ compute_cpu_load() {
let diff_total=${end_total}-${start_total}
let diff_used=$diff_total-$diff_idle
+ if [ "$verbose" == "1" ] ; then
+ echo "Start CPU time = $start_total"
+ echo "End CPU time = $end_total"
+ echo "CPU time used = $diff_used"
+ echo "Total elapsed time = $diff_total"
+ fi
+
if [ "$diff_total" != "0" ] ; then
- let cpu_load=($diff_used*100)/$diff_total
+ cpu_load=$(echo "($diff_used*100)/$diff_total" | bc)
else
cpu_load=0
fi
@@ -127,7 +138,13 @@ echo "Testing CPU load when reading $xfer MiB from $disk_device"
echo "Maximum acceptable CPU load is $max_load"
blockdev --flushbufs $disk_device
start_load="$(grep "cpu " /proc/stat | tr -s " " | cut -d " " -f 2-)"
+if [ "$verbose" == "1" ] ; then
+ echo "Beginning disk read...."
+fi
dd if="$disk_device" of=/dev/null bs=1048576 count="$xfer" &> /dev/null
+if [ "$verbose" == "1" ] ; then
+ echo "Disk read complete!"
+fi
end_load="$(grep "cpu " /proc/stat | tr -s " " | cut -d " " -f 2-)"
compute_cpu_load "$start_load" "$end_load"
echo "Detected disk read CPU load is $cpu_load"