Blame tests/p_sysstat/05-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
Carlos Rodriguez-Fernandez 4baccd
# Save our iostat output
Carlos Rodriguez-Fernandez 4baccd
output_file=$(mktemp)
Carlos Rodriguez-Fernandez 4baccd
trap "rm -f ${output_file}" EXIT
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
# Capture a storage device name
Carlos Rodriguez-Fernandez 4baccd
drive=$(fdisk -l|grep -Po -m1 '^/dev/[\D]+')
root 2bfd68
 
root 2bfd68
# Run iostat on the cpu
Carlos Rodriguez-Fernandez 4baccd
/usr/bin/iostat -c 1 5 >${output_file} 2>&1 &
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
# Time for iostat booting
Carlos Rodriguez-Fernandez 4baccd
sleep 1
root 2bfd68
root 2bfd68
# Give the CPU something to chew on
Carlos Rodriguez-Fernandez 4baccd
/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)
Carlos Rodriguez-Fernandez 4baccd
cpu_user_percent=$(awk '$1 ~ /[0-9]/ {$1>a ? a=$1 : $1} END {print int(a)}' ${output_file})
root 2bfd68
root 2bfd68
# Confirm the CPU registered some level of user activity
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
if [ "$cpu_user_percent" -eq 0 ]; then
Carlos Rodriguez-Fernandez 4baccd
  t_Log "FAIL: ${0}: no cpu activity registered"
Carlos Rodriguez-Fernandez 4baccd
  cat ${output_file}
Carlos Rodriguez-Fernandez 4baccd
  t_CheckExitStatus 1
Carlos Rodriguez-Fernandez 4baccd
fi
Carlos Rodriguez-Fernandez 4baccd
Carlos Rodriguez-Fernandez 4baccd
t_CheckExitStatus 0