Add verbosity to a failing bench QA script.
[xfstests-dev.git] / bench
diff --git a/bench b/bench
index 71ebca83a97e6795f48024d86f3dc5af098ef3c3..4b5a5410d2c3c170c5977cf4aa98db1b99de5d9d 100755 (executable)
--- a/bench
+++ b/bench
@@ -1,7 +1,7 @@
 #!/bin/sh
 # 
 # Wrapper for automating benchmarking runs.
-# Usage:   bench [passes] [uid] [gid] [script]
+# Usage:   bench passes user group [script]
 # 
 # ..where passes is the number of times to run each script; uid/gid
 # gives credentials to use when running the script; and script is a
@@ -50,8 +50,7 @@
 owner=nathans@sgi.com
 
 tmp=/tmp/$$
-seq=bench
-here=`pwd`
+here=`pwd`; export here
 status=1       # failure is the default!
 
 # get standard environment, filters and checks
@@ -62,13 +61,12 @@ _cleanup()
 {
     echo "        *** umount"
     umount $SCRATCH_DEV >/dev/null 2>&1
+    rm -f $tmp.*
 }
 
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-ROOT="."
-LOG="$ROOT/soak.log"
-FULL="$ROOT/soak.full"
+OUT="bench.out"
+LOG="bench.log"
+FULL="bench.full"
 
 _log()
 {
@@ -90,31 +88,50 @@ _fail()
     exit 1
 }
 
+bench_mkfs_xfs()
+{
+    mkfs_xfs -f $extra_mkfs_options $@
+    [ $? -ne 0 ] && _fail "mkfs [$extra_mkfs_options] FAILED"
+}
+
+bench_mount_xfs()
+{
+    mount -t xfs $extra_mount_options $@
+    [ $? -ne 0 ] && _fail "mount [$extra_mount_options] FAILED"
+}
+
 _run_benchmark()
 {
     pass=1
+    uid=`id -u $user`
+    gid=`id -g $group`
     
     while [ $pass -le $passes -o $passes -lt 0 ]
     do
-        _log "        *** clean scratch device [starting pass $pass]"
-        mkfs_xfs -f $SCRATCH_DEV 2>&1 |  _fix_malloc >>$FULL \
-                        || _fail "            !!! failed to mkfs SCRATCH_DEV"
+        _log "        *** clean scratch device [$bench starting, pass $pass]"
+        bench_mkfs_xfs  $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL \
+                            || _fail "            !!! mkfs SCRATCH_DEV failed"
 
         _log "        *** mounting scratch device"
-        mount -t xfs $SCRATCH_DEV $SCRATCH_MNT \
+        bench_mount_xfs $SCRATCH_DEV $SCRATCH_MNT \
                             || _fail "            !!! failed to mount"
         
         _log "        *** mkdir"
         mkdir $SCRATCH_MNT/bench \
-                            || _fail "            !!! couldn't mkdir bench dir"
+                            || _fail "            !!! couldn't mkdir benchdir"
         chown -R $user.$group $SCRATCH_MNT/bench \
-                            || _fail "            !!! couldn't chown bench dir"
+                            || _fail "            !!! couldn't chown benchdir"
+
         cd $SCRATCH_MNT/bench
+        seq=`perl -e 'printf "results.%s.%03d\n", '$bench', '$pass`
+        rm -f $seq $tmp.out
+
+        _log "        *** bench [$seq]"
+        $here/src/runas -u $uid -g $gid $here/run.$bench >$tmp.out 2>>$FULL
+       [ $? -eq 0 ]        || _fail "            !!! $bench pass $pass failed"
 
-        _log "        *** bench"
-        $here/src/runas -u $user -g $group $here/run.$bench > $FULL
-        [ $? -eq 0 ]        || _fail "            !!! non-zero $bench exit code"
         cd $here
+        _fix_malloc < $tmp.out > $seq
 
         _log "        *** unmounting scratch device"
         umount $SCRATCH_DEV 2>&1 | _logp \
@@ -127,30 +144,67 @@ _run_benchmark()
     done
 }
 
+_merge_results()
+{
+    echo Results for $bench benchmark
+    headers=`$here/run.$bench -h`
+    echo "[$headers]"
+    echo results.$bench.* | sort -nu | xargs cat
+    echo
+}
+
 # real QA test starts here
 
+if [ $# -lt 3 ]; then
+    echo Usage:  bench passes user group [script]
+    exit 1
+fi
+
+passes=$1
+user=$2
+group=$3
+shift; shift; shift
+
+if [ $# -gt 0 ]; then
+       benches="$@"
+else
+       benches=`echo run.* | sed -e 's/run\.//g'`
+fi
+[ -z "$benches" -o "$benches" = "*" ] && _fail "no benchmark scripts found"
+
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
 _require_scratch
+rm -f bench.* results.*
+
+if [ ! -z "$SCRATCH_LOGDEV" -a ! -z "$USE_SCRATCH_LOGDEV" ]
+then
+       extra_log_options="-l $SCRATCH_LOGDEV"
+       extra_mkfs_options="-llogdev=$SCRATCH_LOGDEV"
+       extra_mount_options="-ologdev=$SCRATCH_LOGDEV"
+fi
 
-passes=-1
-user=root
-group=root
-benches=`echo run.*`
+# $OUT is the report which will ultimately be sent, keep it tidy.
+cat >$OUT <<EOF
+bench: MKFS_OPTIONS=$MKFS_OPTIONS $extra_mkfs_options
+bench: MOUNT_OPTIONS=$MOUNT_OPTIONS $extra_mount_options
 
-[ $# -gt 0 ] && passes=$1
-[ $# -gt 1 ] && user=$3
-[ $# -gt 2 ] && group=$4
-[ $# -gt 3 ] && benches=$2
+EOF
 
-for bench in "$benches"
-do 
+for bench in $benches
+do
     echo "" >$FULL
     echo "" >$LOG
-    _log "*** benchmark started (passes=$passes, benchmark=$bench)"
-    _log "***     (`date`)"
+    _log "*** benchmark started [passes=$passes, benchmark=$bench]"
+    _log "*** (`date`)"
+    _log "*** MKFS_OPTIONS=$MKFS_OPTIONS"
+    _log "*** MOUNT_OPTIONS=$MOUNT_OPTIONS"
     _log "        *** unmounting scratch device"
-    umount $SCRATCH_DEV 2>&1 |  _fix_malloc >>$FULL
-    
-    _run_benchmark  # $passes $bench $user $group
+    umount $SCRATCH_DEV 2>&1 | _fix_malloc >>$FULL
+
+    _run_benchmark | _fix_malloc
+    _merge_results >>$OUT
 
     _log "*** done $bench"
 done
+status=0