Whamcloud - gitweb
* Cleaned up sgpdd-survey
[fs/lustre-release.git] / lustre-iokit / sgpdd-survey / sgpdd-survey
1 #!/bin/bash
2
3 ######################################################################
4 # customize per survey
5
6 # the SG device to measure
7 dev=/dev/sg6
8
9 # result file prefix
10 # NB ensure the path exists if it includes subdirs
11 rslt=/tmp/sg_dd_rslt
12
13 # what to do (read or write)
14 action=write
15
16 # total size (MBytes)
17 # NB bigger than device cache is good
18 size=8192
19
20 # record size (KBytes)
21 rszlo=1024
22 rszhi=1024
23
24 # Concurrent regions
25 crglo=1
26 crghi=4
27
28 # total numbers of threads to share between concurrent regions
29 # NB survey skips over #thr < #regions
30 thrlo=1
31 thrhi=1024
32
33 #####################################################################
34
35 # disk block size (Bytes)
36 bs=512
37
38 if [ $action = read ]; then
39     f1="if=$dev"
40     f2="of=/dev/null"
41     skip=skip
42 else
43     f1="if=/dev/zero"
44     f2="of=$dev"
45     skip=seek
46 fi
47
48 start=`date +%F@%R`
49 rsltf=${rslt}_${start}.summary
50 echo -n > $rsltf
51 workf=${rslt}_${start}.detail
52 echo -n > $workf
53
54 print_summary () {
55     if [ "$1" = "-n" ]; then
56         minusn=$1; shift
57     else
58         minusn=""
59     fi
60     echo $minusn "$*" >> $rsltf
61     echo $minusn "$*"
62 }
63
64 for ((rsz=$rszlo;rsz<=$rszhi;rsz*=2)); do
65     for ((crg=$crglo;crg<=$crghi;crg*=2)); do 
66         for ((thr=$thrlo;thr<=$thrhi;thr*=2)); do
67             if ((thr < crg)); then
68                 continue
69             fi
70             # compute parameters
71             bpt=$((rsz*1024/bs))
72             blocks=$((size*((1024*1024)/bs)/crg))
73             count=$blocks
74             # show computed parameters
75             actual_rsz=$((bpt*bs/1024))
76             actual_size=$((bs*count*crg/1024))
77             str=`printf 'total_size %8dK rsz %4d thr %5d crg %3d ' \
78                          $actual_size $actual_rsz $thr $crg`
79             echo "==============> $str" >> $workf
80             print_summary -n "$str"
81             freemem=`awk < /proc/meminfo '/^MemTotal:/ {printf "%d\n", $2}'`
82             if (((actual_rsz * thr /crg + 64) * crg > freemem)); then
83                 print_summary "ENOMEM"
84                 continue
85             fi
86             # start test
87             t0=`date +%s.%N`
88             for ((i=0;i<crg;i++)); do 
89                 sgp_dd 2> ${rslt}_tmp${i} \
90                     $f1 $f2 ${skip}=$((1024+i*blocks)) \
91                     thr=$((thr/crg)) count=$count bs=$bs bpt=$bpt time=1&
92             done 
93             wait
94             t1=`date +%s.%N`
95             # collect all results in 1 file
96             rfile=${rslt}_thr${thr}_crg${crg}_rsz${rsz}
97             echo > $rfile
98             ok=0
99             for ((i=0;i<crg;i++)); do
100                 rtmp=${rslt}_tmp${i}
101                 if grep 'time to transfer data' $rtmp > /dev/null 2>&1; then
102                     ok=$((ok + 1))
103                 fi
104                 cat ${rslt}_tmp${i} >> $rfile
105                 cat ${rslt}_tmp${i} >> $workf
106                 rm ${rslt}_tmp${i}
107             done
108             if [ $ok -ne $crg ]; then
109                 print_summary `printf "failed %d" $((crg - ok))`
110             else
111                 # compute MB/sec from elapsed
112                 bw=`awk "BEGIN {printf \"%6.2f MB/s\", $actual_size / (( $t1 - $t0 ) * 1024); exit}"`
113                 # compute MB/sec from nregions*slowest
114                 check=`awk < $rfile \
115                            '/time to transfer data/ {mb=$8/1.048576; if (n == 0 || mb < min) min = mb; n++}\
116                             END {printf "%3d x %6.2f = %6.2f MB/s", n, min, min * n}'`
117                 print_summary "$bw $check"
118             fi
119             rm $rfile
120         done
121     done
122 done