Blame tests/p_sysstat/5-iostat-cpu-basic.sh

root 2bfd68
#!/bin/bash
root 2bfd68
# Author: Steve Barnes (steve@echo.id.au)
root 2bfd68
root 2bfd68
# A simple iostat test to verify cpu loads are being recorded
root 2bfd68
root 2bfd68
t_Log "Running $0 - a basic iostat test to verify cpu measurement"
root 2bfd68
root 2bfd68
# Save our iostat output somewhere
root 2bfd68
TMP=/tmp/iostat.cpu.scratch
root 2bfd68
root 2bfd68
# Clear out the pagecache to get an accurate reading
root 2bfd68
echo 1 > /proc/sys/vm/drop_caches
root 2bfd68
root 2bfd68
# Clean up after ourselves
root 2bfd68
trap "[ -e $TMP ] && { /bin/rm -f $TMP; }" EXIT
root 2bfd68
root 2bfd68
# Capture a storage device name
root 2bfd68
DRIVE=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+')
root 2bfd68
 
root 2bfd68
# Run iostat on the cpu
root 2bfd68
/usr/bin/iostat -c 1 5 >$TMP &
root 2bfd68
root 2bfd68
# Let the dust settle
Athmane Madjoudj b5d067
sleep 4
root 2bfd68
root 2bfd68
# Give the CPU something to chew on
root 2bfd68
/bin/dd if=$DRIVE bs=4k count=25000 2>/dev/null|sha1sum -b - &>/dev/null
root 2bfd68
root 2bfd68
# Give iostat a chance to log our task
Athmane Madjoudj b5d067
sleep 6
root 2bfd68
root 2bfd68
# Extract the CPU utilisation (user field, percentage)
root 2bfd68
CPU_USER_PCENT=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' $TMP)
root 2bfd68
root 2bfd68
# Confirm the CPU registered some level of user activity
root 2bfd68
[ "$CPU_USER_PCENT" -gt 3 ] || { t_Log "iostat didn't log any CPU activity?!...that ain't good"; exit $FAIL; }
root 2bfd68
root 2bfd68
t_CheckExitStatus $?