Virtual memory sizes are now printed too.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8252 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/exp-drd/scripts/measurement-functions b/exp-drd/scripts/measurement-functions
index 59536b7..d90a292 100644
--- a/exp-drd/scripts/measurement-functions
+++ b/exp-drd/scripts/measurement-functions
@@ -35,7 +35,45 @@
 ## Read a stream of numbers from stdin (one per line), and print the average
 #  and standard deviation.
 function avgstddev {
-  awk '{n++;sum+=$1;sumsq+=$1*$1}END{d=sumsq/n-sum*sum/n/n;print sum/n,(d>0?sqrt(d):0)}'
+  awk '{n++;m=NF;for(i=1;i<=NF;i++){sum[i]+=$i;sumsq[i]+=$i*$i}}END{for(i=1;i<=m;i++){d=sumsq[i]/n-sum[i]*sum[i]/n/n;printf "%g %g ",sum[i]/n,(d>0?sqrt(d):0)}}'
+}
+
+## Query the virtual memory size for the last invocation of command $1 from
+#  the information logged by the kernel (BSD process accounting).
+function query_cmd_vsz {
+  if [ ! -e /usr/sbin/dump-acct ]; then
+    echo "Error: userspace tools for BSD process accounting have not been" >&2
+    echo "installed. Please install the acct package (Debian systems)."    >&2
+    return 1
+  fi
+
+  /usr/sbin/dump-acct /var/log/account/pacct | \
+    grep -- "^$(basename "$1")" | \
+    cut -f8 -d'|' | \
+    tail -n 1
+}
+
+## Query the virtual memory size for the last invocation of command $1 from
+#  the information logged by the kernel (BSD process accounting).
+function query_vsz {
+  local cmd tool
+
+  cmd="$(basename "$1")"
+  if [ "${cmd}" = "vg-in-place" ]; then
+    tool="tool-not-found"
+    for arg in "${@}"
+    do
+      if [ "${arg#--tool=}" != "${arg}" ]; then
+        tool="${arg#--tool=}"
+	break
+      fi
+    done
+    vsz_tool="$(query_cmd_vsz "${tool}")"
+    awk "END{print $(query_cmd_vsz ${cmd}) + ${vsz_tool:-0}}" \
+      </dev/null
+  else
+    query_cmd_vsz "${cmd}"
+  fi
 }
 
 ## Echo all arguments on stderr, run the command passed in $1 .. ${$#} three
@@ -43,21 +81,32 @@
 #  command output to the file specified in ${test_output}, and print the
 #  runtime of the command on stdout.
 function measure_runtime {
+  local i
+
   echo "$@" >&2
   for ((i=0;i<3;i++))
   do
-    cat "${test_input:-/dev/null}" | \
+    echo -n "$(cat "${test_input:-/dev/null}" | \
       /usr/bin/time --format="%e" "$@" 2>&1 | \
       tee "${test_output:-/dev/null}" | \
-      tail -n 1
+      tail -n 1) "
+    query_vsz "$@"
   done
 }
 
-## Print the average runtime of the command passed in $1 .. ${$#} and the ratio
-#  of the runtime to ${avg1} +/- ${stddev1}.
+## Print the average runtime of the command passed in $5 .. ${$#}, the ratio
+#  of the runtime to $1 +/- $2 and the ratio of the VSZ to $3 +/- $4.
 function print_runtime_ratio {
-  local tmp avg1="$1" avg2="$2"
+  local tmp avg1="$1" stddev1="$2" vsz1="$3" vszdev1="$4"
+  local avg2 stddev2 vsz2 vszdev2
 
+  if [ "${avg1}" = "" -o "${stddev1}" = "" -o "${vsz1}" = "" -o "${vszdev1}" = "" ]; then
+    echo "Error: invalid arguments ($@)."
+    exit 1
+  fi
+
+  shift
+  shift
   shift
   shift
 
@@ -65,8 +114,8 @@
   rm -f "${tmp}"
 
   measure_runtime "$@" | avgstddev > "$tmp"
-  read avg2 stddev2 < "$tmp"
-  echo "Average time: ${avg2} +/- ${stddev2} seconds"
-  awk "END{print "'"'"Ratio ="'"'", ${avg2}/${avg1}, "'"'"+/-"'"'", ${avg2}/${avg1}*(${stddev1}/${avg1}+${stddev2}/${avg2})}" </dev/null
+  read avg2 stddev2 vsz2 vszdev2 < "$tmp"
+  echo "Average time: ${avg2} +/- ${stddev2} seconds / VSZ ${vsz2} +/- ${vszdev2} KB"
+  awk "END{print "'"'"Ratio ="'"'", ${avg2}/${avg1}, "'"'"+/-"'"'", ${avg2}/${avg1}*(${stddev1}/${avg1}+${stddev2}/${avg2}), "'"; VSZ ratio: "'", ${vsz2:-0}/${vsz1}, "'"'"+/-"'"'", ${vsz2:-0}/${vsz1}*(${vszdev1}/${vsz1}+${vszdev2:-0}/${vsz2:-1})}" </dev/null
 }
 
diff --git a/exp-drd/scripts/run-matinv b/exp-drd/scripts/run-matinv
index 0f80c4b..ad8d7fa 100755
--- a/exp-drd/scripts/run-matinv
+++ b/exp-drd/scripts/run-matinv
@@ -25,14 +25,15 @@
   rm -f "${tmp}"
 
   measure_runtime ${MATINV} $n | avgstddev > "$tmp"
-  read avg1 stddev1 < "$tmp"
-  echo "Average time: ${avg1} +/- ${stddev1} seconds"
+  read avg1 stddev1 vsz1 vszdev1 < "$tmp"
+  echo "Average time: ${avg1} +/- ${stddev1} seconds." \
+       " VSZ: ${vsz1} +/- ${vszdev1} KB"
 
   for i in 1 10
   do
-    print_runtime_ratio ${avg1} ${stddev1} \
+    print_runtime_ratio ${avg1} ${stddev1} ${vsz1} ${vszdev1} \
       ${VG} --tool=none    ${MATINV} $n -t$i
-    print_runtime_ratio ${avg1} ${stddev1} \
+    print_runtime_ratio ${avg1} ${stddev1} ${vsz1} ${vszdev1} \
       ${VG} --tool=exp-drd ${MATINV} $n -t$i
   done
 done
diff --git a/exp-drd/scripts/run-splash2 b/exp-drd/scripts/run-splash2
index 4931638..8bc4062 100755
--- a/exp-drd/scripts/run-splash2
+++ b/exp-drd/scripts/run-splash2
@@ -7,7 +7,7 @@
 source "$(dirname $0)/measurement-functions"
 
 function run_test {
-  local tmp avg1 stddev1 avg2 stddev2 avg4 stddev4 p
+  local tmp avg1 stddev1 avg2 stddev2 avg4 stddev4
 
   tmp="/tmp/test-timing.$$"
   rm -f "${tmp}"
@@ -32,14 +32,14 @@
 
   test_output="${1}-drd-with-stack-var-${p}.out" \
   print_runtime_ratio ${avg4} ${stddev4} \
-    $VG --tool=exp-drd --check-stack-var=yes "$@" -p$p
+    $VG --tool=exp-drd --check-stack-var=yes "$@" -p4
 
   test_output="${1}-drd-without-stack-var-${p}.out" \
   print_runtime_ratio ${avg4} ${stddev4} \
-    $VG --tool=exp-drd --check-stack-var=no  "$@" -p$p
+    $VG --tool=exp-drd --check-stack-var=no  "$@" -p4
 
   test_output="${1}-helgrind-${p}.out" \
-  print_runtime_ratio ${avg4} ${stddev4} $VG --tool=helgrind "$@" -p$p
+  print_runtime_ratio ${avg4} ${stddev4} $VG --tool=helgrind "$@" -p4
 
   echo ''
 
@@ -71,43 +71,61 @@
   exit 1
 fi
 
-###############################################################################
-# Results:                native    native  none none  DRD  DRD   HG ITC   ITC
-#                         -p1    -p2   -p4   -p1  -p4  -p4 -p4+f -p4 -p4  -p4+f
-# .............................................................................
-# Cholesky                0.29  0.21  4.46   8.5   0.7    5    4    2  239   82
-# FFT                     0.19  0.12  0.12   5.2   8.5   82   54 4237   90   41
-# LU, contiguous          0.76  0.47  0.47   7.7  12.8   66   61  155  428  128
-# LU, non-contiguous      0.80  0.45  0.48   7.4  13.1   88   86  102  428  128
-# Ocean, contiguous      19.45 12.59 12.65   2.7   4.1   57   49   86   90   28
-# Ocean, non-contiguous   0.30  0.18  0.19   4.4   7.3   39   46   85   90   28
-# Radiosity               3.14  3.11  3.11  16.4  16.4  164   60   58  485  163
-# Radix                   4.07  2.12  2.12   5.7  10.9   30   27  147  222   56
-# Raytrace                2.22  2.19  2.20   7.8   7.9  166   55   93  172   53
-# Water-n2                0.18  0.17  0.17  11.4  11.5  126   34   52  189   39
-# Water-sp                0.19  0.18  0.18  10.4  10.2   96   34   51  183   34
-# .............................................................................
+######################################################################################################################
+# Results:                native       native      native     none     none       DRD       DRD      HG       ITC ITC
+#                         -p1          -p2         -p4         -p1      -p4       -p4      -p4+f     -p4     -p4 -p4+f
+# ....................................................................................................................
+# Cholesky                0.37 .....  0.25 .....  0.20 .....  8.3 .... 17.3 .... 173 .... 118 ....   57 .... 239   82
+# FFT                     0.23 .....  0.14 .....  0.10 .....  7.5 .... 16.2 .... 119 ....  80 .... 2336 ....  90   41
+# LU, contiguous          0.95 .....  0.64 .....  0.43 .....  7.9 .... 18.0 .... 119 .... 113 ....  223 .... 428  128
+# LU, non-contiguous      1.18 .....  0.69 .....  0.41 .....  6.7 .... 19.5 .... 204 .... 187 ....  164 .... 428  128
+# Ocean, contiguous      24.53 ..... 13.97 .....  9.28 .....  2.4 ....  6.5 ....  89 ....  76 ....  147 ....  90   28
+# Ocean, non-contiguous   0.36 .....  0.19 .....  0.17 .....  4.2 .... 10.0 ....  56 ....  68 ....  121 ....  90   28
+# Radiosity               4.77 .....  4.77 .....  4.75 ..... 16.6 .... 16.6 .... 116 ....  .. ....   .. .... 485  163
+# Radix                   .... .....  .... .....  .... .....  ... .... .... ....  .. ....  .. ....  ... .... 222   56
+# Raytrace                .... .....  .... .....  .... .....  ... ....  ... .... ... ....  .. ....   .. .... 172   53
+# Water-n2                .... .....  .... .....  .... ..... .... .... .... .... ... ....  .. ....   .. .... 189   39
+# Water-sp                .... .....  .... .....  .... ..... .... .... .... ....  .. ....  .. ....   .. .... 183   34
+# ....................................................................................................................
+# Hardware: Two quad-core Intel Xeon L5130, 1.6 GHz, 4 MB L2 cache, 16 GB RAM.
+# Software: Ubuntu 8.04 server, 64-bit, gcc 4.3.1.
+######################################################################################################################
+# Results:                native       native      native     none     none       DRD       DRD      HG       ITC ITC
+#                         -p1          -p2         -p4         -p1      -p4       -p4      -p4+f     -p4     -p4 -p4+f
+# ....................................................................................................................
+# Cholesky                0.29 10968  0.21 63669  4.60 70621  8.6 2.21  1.0 1.75    5 2.05   4 2.16    2 3.22 239  82
+# FFT                     0.19 .....  0.12 .....  0.12 .....  7.0 1.01 11.3 1.01   87 1.02  59 1.02 .... ....  90  41
+# LU, contiguous          0.79 .....  0.54 .....  0.53 .....  8.3 4.27 11.7 2.33   79 ....  75 ....  148 .... 428 128
+# LU, non-contiguous      0.86 .....  0.47 .....  0.49 .....  7.5 .... 12.6 ....  136 .... 124 ....  109 .... 428 128
+# Ocean, contiguous      19.46 ..... 12.59 ..... 12.61 .....  2.4 ....  3.7 ....   53 ....  47 ....   86 ....  90  28
+# Ocean, non-contiguous   0.30 .....  0.19 .....  0.19 .....  4.0 ....  6.8 ....   38 ....  47 ....   84 ....  90  28
+# Radiosity               3.86 .....  3.84 .....  3.84 ..... 16.3 .... 16.4 ....  ... ....  .. ....   .. .... 485 163
+# Radix                   4.07 .....  2.12 .....  2.12 .....  5.7 .... 10.9 ....   .. ....  .. ....  ... .... 222  56
+# Raytrace                2.22 .....  2.19 .....  2.20 .....  7.8 ....  7.9 ....  ... ....  .. ....   .. .... 172  53
+# Water-n2                0.18 .....  0.17 .....  0.17 ..... 11.4 .... 11.5 ....  ... ....  .. ....   .. .... 189  39
+# Water-sp                0.19 .....  0.18 .....  0.18 ..... 10.4 .... 10.2 ....   .. ....  .. ....   .. .... 183  34
+# ....................................................................................................................
 # Hardware: dual-core Intel Xeon 5130, 2.0 GHz, 4 MB L2 cache, 4 GB RAM.
 # Software: Ubuntu 7.10 server, 64-bit, gcc 4.3.1, xload -update 1 running.
-###############################################################################
-# Results:                native    native  DRD    DRD     HG    ITC     ITC
-#                         -p1    -p2   -p4  -p4  -p4, f   -p4    -p4    -p4, f
-# .............................................................................
-# Cholesky                0.21  0.14  4.49    4     3       2    239      82
-# FFT - 1                 0.11  0.08  0.07  138    66     380     90      41
-# LU, contiguous          0.56  0.34  0.34   72    68      96    428     128
-# LU, non-contiguous      0.59  0.32  0.35   92   109      60    428     128
-# Ocean, contiguous      14.30  9.54  9.56   61    48      89     90      28
-# Ocean, non-contiguous   0.20  0.12  0.12   45    51      93     90      28
-# Radiosity               2.33  2.32  2.33  175    61      60    485     163
-# Radix                   2.81  1.45  1.46   32    29     153    222      56
-# Raytrace                1.65  1.64  1.64  230    55      89    172      53
-# Water-n2                0.14  0.12  0.12  129    35      55    189      39
-# Water-sp                0.14  0.12  0.12  121    36      54    183      34
-# .............................................................................
+######################################################################################################################
+# Results:                native       native      native     none     none       DRD       DRD      HG       ITC ITC
+#                         -p1          -p2         -p4         -p1      -p4       -p4      -p4+f     -p4     -p4 -p4+f
+# ....................................................................................................................
+# Cholesky                0.21 .....  0.14 .....  4.49 ..... .... .... .... ....    4 ....   3 ....    2 .... 239  82
+# FFT                     0.11 .....  0.08 .....  0.07 ..... .... .... .... ....  138 ....  66 ....  380 ....  90  41
+# LU, contiguous          0.56 .....  0.34 .....  0.34 ..... .... .... .... ....   72 ....  68 ....   96 .... 428 128
+# LU, non-contiguous      0.59 .....  0.32 .....  0.35 ..... .... .... .... ....   92 .... 109 ....   60 .... 428 128
+# Ocean, contiguous      14.30 .....  9.54 .....  9.56 ..... .... .... .... ....   61 ....  48 ....   89 ....  90  28
+# Ocean, non-contiguous   0.20 .....  0.12 .....  0.12 ..... .... .... .... ....   45 ....  51 ....   93 ....  90  28
+# Radiosity               2.33 .....  2.32 .....  2.33 ..... .... .... .... ....  175 ....  61 ....   60 .... 485 163
+# Radix                   2.81 .....  1.45 .....  1.46 ..... .... .... .... ....   32 ....  29 ....  153 .... 222  56
+# Raytrace                1.65 .....  1.64 .....  1.64 ..... .... .... .... ....  230 ....  55 ....   89 .... 172  53
+# Water-n2                0.14 .....  0.12 .....  0.12 ..... .... .... .... ....  129 ....  35 ....   55 .... 189  39
+# Water-sp                0.14 .....  0.12 .....  0.12 ..... .... .... .... ....  121 ....  36 ....   54 .... 183  34
+# ....................................................................................................................
 # Hardware: dual-core Intel Core2 Duo E6750, 2.66 GHz, 4 MB L2 cache, 2 GB RAM.
 # Software: openSUSE 10.3, 64-bit, gcc 4.3.1, runlevel 5, X screensaver: blank
-###############################################################################
+######################################################################################################################
 
 cache_size=$(get_cache_size)
 log2_cache_size=$(log2 ${cache_size})