read-test format directly for gnuplot
[ardour.git] / tools / run-readtest.sh
1 #!/bin/sh
2
3 dir=/tmp
4 filesize=100 # megabytes
5 numfiles=128
6 nocache=
7 interleave=
8 needfiles=1
9 write_blocksize=262144
10
11 if uname -a | grep --silent arwin ; then
12     ddmega=m
13 else
14     ddmega=M
15 fi
16
17 while [ $# -gt 1 ] ; do
18     case $1 in
19         -d) dir=$2; shift; shift ;;
20         -f) filesize=$2; shift; shift ;;
21         -n) numfiles=$2; shift; shift ;;
22         -N) nocache="-s"; shift;;
23         *) break ;;
24     esac
25 done
26
27 if [ -d $dir -a -f $dir/testfile_1 ] ; then
28     # dir exists and has a testfile within it - reuse to avoid
29     # recreating files
30     echo "# Re-using files in $dir"
31     needfiles=
32 else
33     dir=$dir/readtest_$$
34     mkdir $dir
35     
36     if [ $? != 0 ] ; then
37         echo "Cannot create testfile directory $dir"
38         exit 1
39     fi
40 fi
41
42 if [ x$needfiles != x ] ; then
43     echo "# Building files for test..."
44     if [ x$interleave = x ] ; then
45         
46         #
47         # Create all files sequentially
48         #
49         
50         for i in `seq 1 $numfiles` ; do
51             dd of=$dir/testfile_$i if=/dev/zero bs=1$ddmega count=$filesize >/dev/null 2>&1
52         done
53     else
54         
55         #
56         # Create files interleaved, adding $write_blocksize to each
57         # file in turn.
58         #
59         
60         size=0
61         limit=`expr $filesize * 1048576`
62         while [ $size -lt $limit ] ; do
63             for i in `seq 1 $numfiles` ; do
64                 dd if=/dev/zero bs=$write_blocksize count=1 >> $dir/testfile_$i 2>/dev/null
65             done
66             size=`expr $size + $write_blocksize`
67         done
68     fi
69 fi
70
71 for bs in $@ ; do
72
73     if uname -a | grep --silent arwin ; then
74         # clears cache on OS X
75         sudo purge
76     elif [ -f /proc/sys/vm/drop_caches ] ; then
77         # Linux cache clearing
78         echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null
79     else       
80         # need an alternative for other operating systems
81         :
82     fi
83     
84     echo "# Blocksize $bs"
85     ./readtest $nocache -b $bs -q $dir/testfile_%d
86 done