5d691b8a3219ec8c36014c57568b21ff7b5380f3
[zfs.git] / scripts / profile-kpios-disk.sh
1 #!/bin/bash
2 # profile-kpios-disk.sh
3 #
4 # /proc/diskinfo <after skipping major/minor>
5 # Field 1 -- device name
6 # Field 2 -- # of reads issued
7 # Field 3 -- # of reads merged
8 # Field 4 -- # of sectors read
9 # Field 5 -- # of milliseconds spent reading
10 # Field 6 -- # of writes completed
11 # Field 7 -- # of writes merged
12 # Field 8 -- # of sectors written
13 # Field 9 -- # of milliseconds spent writing
14 # Field 10 -- # of I/Os currently in progress
15 # Field 11 -- # of milliseconds spent doing I/Os
16 # Field 12 -- weighted # of milliseconds spent doing I/Os
17
18 RUN_PIDS=${0}
19 RUN_LOG_DIR=${1}
20 RUN_ID=${2}
21
22 create_table() {
23         local FIELD=$1
24         local ROW_M=()
25         local ROW_N=()
26         local HEADER=1
27         local STEP=1
28
29         for DISK_FILE in `ls -r --sort=time --time=ctime ${RUN_LOG_DIR}/${RUN_ID}/disk-[0-9]*`; do
30                 ROW_M=( ${ROW_N[@]} )
31                 ROW_N=( `cat ${DISK_FILE} | grep sd | cut -c11- | cut -f${FIELD} -d' ' | tr "\n" "\t"` )
32
33                 if [ $HEADER -eq 1 ]; then
34                         echo -n "step, "
35                         cat ${DISK_FILE} | grep sd | cut -c11- | cut -f1 -d' ' | tr "\n" ", "
36                         echo "total"
37                         HEADER=0
38                 fi
39
40                 if [ ${#ROW_M[@]} -eq 0 ]; then
41                         continue
42                 fi
43
44                 if [ ${#ROW_M[@]} -ne ${#ROW_N[@]} ]; then
45                         echo "Badly formatted profile data in ${DISK_FILE}"
46                         break
47                 fi
48
49                 TOTAL=0
50                 echo -n "${STEP}, "
51                 for (( i=0; i<${#ROW_N[@]}; i++ )); do
52                         DELTA=`echo "${ROW_N[${i}]}-${ROW_M[${i}]}" | bc`
53                         let TOTAL=${TOTAL}+${DELTA}
54                         echo -n "${DELTA}, "
55                 done
56                 echo "${TOTAL}, "
57
58                 let STEP=${STEP}+1
59         done
60 }
61
62 create_table_mbs() {
63         local FIELD=$1
64         local TIME=$2
65         local ROW_M=()
66         local ROW_N=()
67         local HEADER=1
68         local STEP=1
69
70         for DISK_FILE in `ls -r --sort=time --time=ctime ${RUN_LOG_DIR}/${RUN_ID}/disk-[0-9]*`; do
71                 ROW_M=( ${ROW_N[@]} )
72                 ROW_N=( `cat ${DISK_FILE} | grep sd | cut -c11- | cut -f${FIELD} -d' ' | tr "\n" "\t"` )
73
74                 if [ $HEADER -eq 1 ]; then
75                         echo -n "step, "
76                         cat ${DISK_FILE} | grep sd | cut -c11- | cut -f1 -d' ' | tr "\n" ", "
77                         echo "total"
78                         HEADER=0
79                 fi
80
81                 if [ ${#ROW_M[@]} -eq 0 ]; then
82                         continue
83                 fi
84
85                 if [ ${#ROW_M[@]} -ne ${#ROW_N[@]} ]; then
86                         echo "Badly formatted profile data in ${DISK_FILE}"
87                         break
88                 fi
89
90                 TOTAL=0
91                 echo -n "${STEP}, "
92                 for (( i=0; i<${#ROW_N[@]}; i++ )); do
93                         DELTA=`echo "${ROW_N[${i}]}-${ROW_M[${i}]}" | bc`
94                         MBS=`echo "scale=2; ((${DELTA}*512)/${TIME})/(1024*1024)" | bc`
95                         TOTAL=`echo "scale=2; ${TOTAL}+${MBS}" | bc`
96                         echo -n "${MBS}, "
97                 done
98                 echo "${TOTAL}, "
99
100                 let STEP=${STEP}+1
101         done
102 }
103
104 echo
105 echo "Reads issued per device"
106 create_table 2
107 echo
108 echo "Reads merged per device"
109 create_table 3
110 echo
111 echo "Sectors read per device"
112 create_table 4
113 echo "MB/s per device"
114 create_table_mbs 4 3
115
116 echo
117 echo "Writes issued per device"
118 create_table 6
119 echo
120 echo "Writes merged per device"
121 create_table 7
122 echo
123 echo "Sectors written per device"
124 create_table 8
125 echo "MB/s per device"
126 create_table_mbs 8 3
127
128 exit 0