From b780be7a7bccc00a36772e2fb3e3d0cbd412c616 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 18 Jul 2009 11:55:59 +0000 Subject: [PATCH] Various improvements: - Display a clear warning if the user running this script does not have sufficient privileges to drop the VM caches. - Made sure that header and data columns are aligned if dd reports an error, e.g. when trying to perform direct I/O on a device that does not support direct I/O. - Made sure that header and data columns are aligned when running a read-only test (-r). git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@961 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scripts/blockdev-perftest | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/blockdev-perftest b/scripts/blockdev-perftest index 65cdf3167..44ff2157f 100755 --- a/scripts/blockdev-perftest +++ b/scripts/blockdev-perftest @@ -38,7 +38,7 @@ usage() { echo " - block device to run the I/O performance test on." } -# Echo ((2**$1)) +# Compute two raised to the power $1. pow2() { if [ $1 = 0 ]; then echo 1 @@ -47,9 +47,15 @@ pow2() { fi } +# Report via the exit status whether or not the current user has sufficient +# privileges to drop the VM caches. +can_drop_cache() { + [ -w /proc/sys/vm/drop_caches ] +} + drop_caches() { sync - if [ -w /proc/sys/vm/drop_caches ]; then + if can_drop_cache; then echo 3 > /proc/sys/vm/drop_caches fi if [ "${target_login}" != "" ]; then @@ -128,6 +134,13 @@ then exit 1 fi +if ! can_drop_cache; then + echo "" + echo "WARNING: insufficient privileges to drop the file system cache" + echo "-- results will be unreliable." + echo "" +fi + if [ "${iotype}" = "direct" ]; then dd_oflags="oflag=direct conv=notrunc" dd_iflags="iflag=direct" @@ -191,9 +204,9 @@ do drop_caches dd if=/dev/zero of="${device}" bs=${bs} count=${count} \ ${dd_oflags} 2>&1 \ - | sed -n 's/.* \([0-9.]*\) s,.*/\1/p' + | sed -n -e 's/.* \([0-9.]*\) s,.*/\1/p' -e 's/^dd: .*/0/p' else - echo 0 + echo " 0 s," fi i=$((i+1)) done | echo_and_calc_avg "%8.3f " ${iosize} ${bs} @@ -204,7 +217,7 @@ do drop_caches dd if="${device}" of=/dev/null bs=${bs} count=${count} \ ${dd_iflags} 2>&1 \ - | sed -n 's/.* \([0-9.]*\) s,.*/\1/p' + | sed -n -e 's/.* \([0-9.]*\) s,.*/\1/p' -e 's/^dd: .*/0/p' i=$((i+1)) done | echo_and_calc_avg "%8.3f " ${iosize} ${bs} printf "\n"