1#!/bin/tcsh -f 2 3@global_parse `basename $0` "$*" ; if ($status) exit 0 4 5set stat = 0 6set pname = `basename $0` 7set mcname = `hostname -s` 8set log = TDIO.log.$mcname 9set niter = 1 10 11goto PARSE 12RET_PARSE: 13 14CHECK: 15 if ( ! -d $testdir ) then 16 echo "Cannot find directory $testdir" 17 goto BEND 18 endif 19 20 touch $testdir/$tfile 21 if ($status == 1) then 22 echo "Cannot create tempfile under $testdir" 23 goto BEND 24 endif 25 26 if ( -f $testdir/$tfile ) \rm -f $testdir/$tfile 27 28LOG: 29 echo "Testing write/read speed to $testdir with $pname" | tee $log 30 echo "`date` `uname` `hostname -s` `whoami` $PWD" | tee -a $log 31 echo "" | tee -a $log 32 33TEST_WRITE: 34 set btot = 0 35 set stot = 0 36 set cnt = 0 37 while ($cnt < $niter) 38 @ cnt ++ 39 echo "Testing write speed, iteration $cnt/$niter" 40 sync 41 dd if=/dev/zero of=$testdir/$tfile bs=1m count=1024 \ 42 |& tee $testdir/___write 43 sync 44 cat $testdir/___write >> $log 45 set bs = `tail -n 1 $testdir/___write | cut -d ' ' -f 1,5` 46 set mbps = `ccalc -i $bs[1]/$bs[2]/1000000` 47 set btot = `ccalc $btot + $bs[1]` 48 set stot = `ccalc $stot + $bs[2]` 49 echo " # Write speed $mbps MB/sec" |& tee -a $log 50 end 51 set mbps = `ccalc -i $btot/$stot/1000000` 52 echo "" |& tee -a $log 53 echo " ## Write speed of $cnt iterations $mbps MB/sec" \ 54 |& tee -a $log 55 echo "" |& tee -a $log 56 57TEST_READ: 58 set btot = 0 59 set stot = 0 60 set cnt = 0 61 while ($cnt < $niter) 62 @ cnt ++ 63 echo "Testing read speed, iteration $cnt/$niter" 64 #This next command for clearing cache is not valid on mac 65 #sudo /sbin/sysctl -w vm.drop_caches=3 vm.drop_caches=3 66 dd if=$testdir/$tfile of=/dev/null bs=1m count=1024 |& tee $testdir/___read 67 cat $testdir/___read >> $log 68 set bs = `tail -n 1 $testdir/___read | cut -d ' ' -f 1,5` 69 set mbps = `ccalc -i $bs[1]/$bs[2]/1000000` 70 set btot = `ccalc $btot + $bs[1]` 71 set stot = `ccalc $stot + $bs[2]` 72 echo " # Read speed $mbps MB/sec" |& tee -a $log 73 end 74 set mbps = `ccalc -i $btot/$stot/1000000` 75 echo "" |& tee -a $log 76 echo " ## Read speed of $cnt iterations $mbps MB/sec" \ 77 |& tee -a $log 78 echo "" |& tee -a $log 79 80goto END 81 82PARSE: 83 set testdir = '' 84 set tfile = ___Tdio 85 set Narg = $# 86 set quiet = 0 87 set cnt = 1 88 set HelpOpt = '' 89 echo "$1" | \grep -w -E \ 90 '\-h_txt|\-h_spx|\-h_aspx|\-h_raw|\-help|\-h' >& /dev/null 91 if ($status == 0) then 92 set HelpOpt = "$1" 93 goto HELP 94 endif 95 while ($cnt <= $Narg) 96 set donext = 1; 97 if ($donext && "$argv[$cnt]" == "-echo") then 98 set echo 99 set donext = 0; goto NEXT 100 endif 101 102 if ($donext && ("$argv[$cnt]" == "-h" || "$argv[$cnt]" == "-help")) then 103 goto HELP 104 set HelpOpt = "$argv[$cnt]" 105 set donext = 0; goto NEXT 106 endif 107 108 if ($donext && "$argv[$cnt]" == "-quiet") then 109 set quiet = 1 110 set donext = 0; goto NEXT 111 endif 112 113 if ($donext && "$argv[$cnt]" == "-tdir") then 114 if ($cnt == $Narg) then 115 echo "Option -tdir needs an existing directory name" 116 goto BEND 117 endif 118 @ cnt ++ 119 set testdir = $argv[$cnt] 120 set donext = 0; goto NEXT 121 endif 122 123 if ($donext && "$argv[$cnt]" == "-niter") then 124 if ($cnt == $Narg) then 125 echo "Option -niter needs an integer number of iterations" 126 goto BEND 127 endif 128 @ cnt ++ 129 set niter = $argv[$cnt] 130 set donext = 0; goto NEXT 131 endif 132 133 if ($donext && "$argv[$cnt]" == "-log") then 134 if ($cnt == $Narg) then 135 echo "Option -log needs a file name" 136 goto BEND 137 endif 138 @ cnt ++ 139 set log = ${argv[$cnt]}.$mcname 140 if ( ! -f $log ) then 141 touch $log 142 if ( $status ) then 143 echo "Cannot write to file $log" 144 goto BEND 145 endif 146 \rm -f $log 147 endif 148 set donext = 0; goto NEXT 149 endif 150 151 152 if ($donext == 1) then 153 echo "Error: Option or parameter '$argv[$cnt]' not understood" 154 apsearch -popt `basename $0` -word $argv[$cnt] 155 goto END 156 endif 157 158 NEXT: 159 @ cnt ++ 160 end 161 162 if ("$testdir" == '') then 163 echo "Must specify -tdir option" 164 goto BEND 165 endif 166 167 goto RET_PARSE 168 169HELP: 170 if ("$HelpOpt" == "-h_raw") then 171 goto HRAW 172else if ("$HelpOpt" == "-h") then 173 `basename $0` -h_raw | apsearch -hdoc_2_txt `basename $0` - 174else if ("$HelpOpt" == "-help") then 175 `basename $0` -h_raw | apsearch -hdoc_2_txt `basename $0` - 176else if ("$HelpOpt" == "-h_txt") then 177 `basename $0` -h_raw | apsearch -hdoc_2_txt `basename $0` - 178else if ("$HelpOpt" == "-h_spx") then 179 `basename $0` -h_raw | apsearch -hdoc_2_spx `basename $0` - 180else if ("$HelpOpt" == "-h_aspx") then 181 `basename $0` -h_raw | apsearch -hdoc_2_aspx `basename $0` - 182endif 183goto END 184 185HRAW: 186cat << EOF 187Usage: $pname <-tdir DIRNAME> 188 189A program to test read write speeds from disks." 190dd command credit to http://www.shellhacks.com" 191 192Options: 193 -tdir TARGET_DIR: Directory where read/write is to be tested 194 -log LOG_PREFIX: Logfile prefix wich will get extended by the 195 machine name. Default logfile is $log 196 -niter N: Numbe or timing iterations. $niter by default. 197 198`@global_parse -gopts_help_formats` 199 200 Ziad S. Saad, saadz@mail.nih.gov 201EOF 202 203 goto END 204 205BEND: 206 set stat = 1 207 goto END 208 209 210END: 211 if ( -f $testdir/$tfile ) \rm -f $testdir/$tfile 212 if ( -f $testdir/___read) \rm -f $testdir/___read 213 if ( -f $testdir/___write) \rm -f $testdir/___write 214 215 exit $stat 216 217 218