3 ######################################################################
6 # CHOOSE EITHER scsidevs or rawdevs
7 # the SCSI devices to measure - WARNING: will be erased.
8 #scsidevs="/dev/sde /dev/sdh"
9 # The raw devices to use
10 #rawdevs="/dev/raw/raw1"
11 #scsidevs=`ls /dev/sd[a-z] /dev/sd[a-z][a-z]` # all devices, if you use udev
13 # result file prefix. date/time+hostname makes unique
14 # NB ensure the path exists if it includes subdirs
15 rslt=${rslt:-"/tmp/sgpdd_survey_`date +%F@%R`_`uname -n`"}
17 # what to do (read or write)
20 # total size per device (MBytes)
21 # NB bigger than device cache is good
24 # record size (KBytes)
28 # Concurrent regions per device
32 # threads to share between concurrent regions per device
33 # NB survey skips over #thr < #regions and #thr/#regions > SG_MAX_QUEUE
37 #####################################################################
38 # leave the rest of this alone unless you know what you're doing...
40 # sgp_dd's idea of disk sector size (Bytes)
42 # and max # threads one instance will spawn
45 # map given device names into SG device names
48 if [ $scsidevs ]; then
49 # we will test for a LUN, the test for a partition
50 # if the partition number is > 9 this will fail
51 for d in $scsidevs; do
52 devs[$i]=`sg_map | awk "{if ($ 2 == \"$d\") print $ 1}"`
53 if [ -z "${devs[i]}" ]; then
54 echo "Can't find SG device for $d, testing for partition"
55 pt=`echo $d | sed 's/[0-9]$//'`
57 devs[$i]=`sg_map | awk "{if ($ 2 == \"$pt\") print $ 1}"`
58 if [ -z "${devs[i]}" ]; then
59 echo "Can't find SG device $pt"
65 elif [ $rawdevs ]; then
72 echo "Raw device $r not set up"
77 echo "Must specify scsidevs or rawdevs"
89 if [ "$1" = "-n" ]; then
94 echo $minusn "$*" >> $rsltf
98 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
99 for ((crg=$crglo;crg<=$crghi;crg*=2)); do
100 for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
101 if ((thr < crg || thr/crg > SG_MAX_QUEUE)); then
106 blocks=$((size*((1024*1024)/bs)/crg))
108 # show computed parameters
109 actual_rsz=$((bpt*bs/1024))
110 actual_size=$((bs*count*crg/1024))
111 str=`printf 'total_size %8dK rsz %4d crg %5d thr %5d ' \
112 $((actual_size*ndevs)) $actual_rsz $((crg*ndevs)) $((thr*ndevs))`
113 echo "==============> $str" >> $workf
114 print_summary -n "$str"
115 freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
116 if (((actual_rsz*thr/crg + 64)*crg*ndevs > freemem)); then
117 print_summary "ENOMEM"
121 for action in $actions; do
122 print_summary -n "$action "
123 echo "=====> $action" >> $workf
127 for ((i=0;i<ndevs;i++)); do
129 if [ $action = read ]; then
138 for ((j=0;j<crg;j++)); do
139 sgp_dd 2> ${tmpf}_${i}_${j} \
140 $inf $outf ${skip}=$((1024+j*blocks)) \
141 thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
146 # collect/check individual stats
149 for ((i=0;i<ndevs;i++)); do
150 for ((j=0;j<crg;j++)); do
151 rtmp=${tmpf}_${i}_${j}
152 if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
156 cat ${rtmp} >> $workf
160 if ((ok != ndevs*crg)); then
161 print_summary -n "$((ndevs*crg - ok)) failed "
163 # compute MB/sec from elapsed
164 bw=`awk "BEGIN {printf \"%7.2f MB/s\", $actual_size * $ndevs / (( $t1 - $t0 ) * 1024); exit}"`
165 # compute MB/sec from nregions*slowest
167 '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
168 END {printf "%5d x %6.2f = %7.2f MB/s", n, min, min * n}'`
169 print_summary -n "$bw $check "