Add linux zpios support
[zfs.git] / scripts / zpios-profile / zpios-profile-pre.sh
1 #!/bin/bash
2
3 PROG=zpios-profile-pre.sh
4
5 PROFILE_RDY=0
6 trap "PROFILE_RDY=1" SIGHUP
7
8 RUN_PRE=${0}
9 RUN_PHASE=${1}
10 RUN_DIR=${2}
11 RUN_ID=${3}
12 RUN_POOL=${4}
13 RUN_CHUNK_SIZE=${5}
14 RUN_REGION_SIZE=${6}
15 RUN_THRD_COUNT=${7}
16 RUN_REGION_COUNT=${8}
17 RUN_OFFSET=${9}
18 RUN_REGION_NOISE=${10}
19 RUN_CHUNK_NOISE=${11}
20 RUN_THRD_DELAY=${12}
21 RUN_FLAGS=${13}
22 RUN_RESULT=${14}
23
24 zpios_profile_pre_run_cfg() {
25 cat > ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh << EOF
26 #
27 # Zpios Profiling Configuration for Run ${RUN_ID}
28 #
29
30 PROFILE_RUN_DIR=${RUN_DIR}/${RUN_ID}
31
32 PROFILE_RUN_CR_DIR=${RUN_DIR}/${RUN_ID}/create
33 PROFILE_RUN_CR_PID=${RUN_DIR}/${RUN_ID}/create/profile.pid
34 PROFILE_RUN_CR_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/create/oprofile.txt
35 PROFILE_RUN_CR_PIDS_LOG=${RUN_DIR}/${RUN_ID}/create/pids.txt
36 PROFILE_RUN_CR_PIDS_CSV=${RUN_DIR}/${RUN_ID}/create/pids.csv
37 PROFILE_RUN_CR_DISK_LOG=${RUN_DIR}/${RUN_ID}/create/disk.txt
38 PROFILE_RUN_CR_DISK_CSV=${RUN_DIR}/${RUN_ID}/create/disk.csv
39
40 PROFILE_RUN_WR_DIR=${RUN_DIR}/${RUN_ID}/write
41 PROFILE_RUN_WR_PID=${RUN_DIR}/${RUN_ID}/write/profile.pid
42 PROFILE_RUN_WR_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/write/oprofile.txt
43 PROFILE_RUN_WR_PIDS_LOG=${RUN_DIR}/${RUN_ID}/write/pids.txt
44 PROFILE_RUN_WR_PIDS_CSV=${RUN_DIR}/${RUN_ID}/write/pids.csv
45 PROFILE_RUN_WR_DISK_LOG=${RUN_DIR}/${RUN_ID}/write/disk.txt
46 PROFILE_RUN_WR_DISK_CSV=${RUN_DIR}/${RUN_ID}/write/disk.csv
47
48 PROFILE_RUN_RD_DIR=${RUN_DIR}/${RUN_ID}/read
49 PROFILE_RUN_RD_PID=${RUN_DIR}/${RUN_ID}/read/profile.pid
50 PROFILE_RUN_RD_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/read/oprofile.txt
51 PROFILE_RUN_RD_PIDS_LOG=${RUN_DIR}/${RUN_ID}/read/pids.txt
52 PROFILE_RUN_RD_PIDS_CSV=${RUN_DIR}/${RUN_ID}/read/pids.csv
53 PROFILE_RUN_RD_DISK_LOG=${RUN_DIR}/${RUN_ID}/read/disk.txt
54 PROFILE_RUN_RD_DISK_CSV=${RUN_DIR}/${RUN_ID}/read/disk.csv
55
56 PROFILE_RUN_RM_DIR=${RUN_DIR}/${RUN_ID}/remove
57 PROFILE_RUN_RM_PID=${RUN_DIR}/${RUN_ID}/remove/profile.pid
58 PROFILE_RUN_RM_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/remove/oprofile.txt
59 PROFILE_RUN_RM_PIDS_LOG=${RUN_DIR}/${RUN_ID}/remove/pids.txt
60 PROFILE_RUN_RM_PIDS_CSV=${RUN_DIR}/${RUN_ID}/remove/pids.csv
61 PROFILE_RUN_RM_DISK_LOG=${RUN_DIR}/${RUN_ID}/remove/disk.txt
62 PROFILE_RUN_RM_DISK_CSV=${RUN_DIR}/${RUN_ID}/remove/disk.csv
63
64 # PROFILE_PIDS_LOG=${RUN_DIR}/${RUN_ID}/pids-summary.csv
65 # PROFILE_DISK_LOG=${RUN_DIR}/${RUN_ID}/disk-summary.csv
66 EOF
67 }
68
69 zpios_profile_pre_run_args() {
70 cat > ${RUN_DIR}/${RUN_ID}/zpios-args.txt << EOF
71 #
72 # Zpios Arguments for Run ${RUN_ID}
73 #
74
75 DIR=${RUN_DIR}
76 ID=${RUN_ID}
77 POOL=${RUN_POOL}
78 CHUNK_SIZE=${RUN_CHUNK_SIZE}
79 REGION_SIZE=${RUN_REGION_SIZE}
80 THRD_COUNT=${RUN_THRD_COUNT}
81 REGION_COUNT=${RUN_REGION_COUNT}
82 OFFSET=${RUN_OFFSET}
83 REGION_NOISE=${RUN_REGION_NOISE}
84 CHUNK_NOISE=${RUN_CHUNK_NOISE}
85 THRD_DELAY=${RUN_THRD_DELAY}
86 FLAGS=${RUN_FLAGS}
87 RESULT=${RUN_RESULT}
88 EOF
89 }
90
91 # Spawn a user defined profiling script to gather additional data
92 zpios_profile_pre_start() {
93         local PROFILE_PID=$1
94
95         ${PROFILE_USER} ${RUN_PHASE} ${RUN_DIR} ${RUN_ID} &
96         echo "$!" >${PROFILE_PID}
97
98         # Sleep waiting for profile script to be ready, it will
99         # signal us via SIGHUP when it is ready to start profiling.
100         while [ ${PROFILE_RDY} -eq 0 ]; do
101                 sleep 0.01
102         done
103 }
104
105 zpios_profile_post_proc_start() { 
106
107         if [ -f ${PROFILE_ARC_PROC} ]; then
108                 echo 0 >${PROFILE_ARC_PROC}
109         fi
110
111         if [ -f ${PROFILE_VDEV_CACHE_PROC} ]; then
112                 echo 0 >${PROFILE_VDEV_CACHE_PROC}
113         fi
114 }
115
116 zpios_profile_pre_oprofile_start() {
117         local OPROFILE_LOG=$1
118
119         /usr/bin/opcontrol --reset >>${OPROFILE_LOG} 2>&1
120         /usr/bin/opcontrol --start >>${OPROFILE_LOG} 2>&1
121 }
122
123 zpios_profile_pre_create() {
124         mkdir ${PROFILE_RUN_CR_DIR}
125         zpios_profile_pre_start ${PROFILE_RUN_CR_PID}
126         zpios_profile_post_proc_start
127         zpios_profile_pre_oprofile_start ${PROFILE_RUN_CR_OPROFILE_LOG}
128 }
129
130 zpios_profile_pre_write() {
131         mkdir ${PROFILE_RUN_WR_DIR}
132         zpios_profile_pre_start ${PROFILE_RUN_WR_PID}
133         zpios_profile_post_proc_start
134         zpios_profile_pre_oprofile_start ${PROFILE_RUN_WR_OPROFILE_LOG}
135 }
136
137 zpios_profile_pre_read() {
138         mkdir ${PROFILE_RUN_RD_DIR}
139         zpios_profile_pre_start ${PROFILE_RUN_RD_PID}
140         zpios_profile_post_proc_start
141         zpios_profile_pre_oprofile_start ${PROFILE_RUN_CR_RD_LOG}
142 }
143
144 zpios_profile_pre_remove() {
145         mkdir ${PROFILE_RUN_RM_DIR}
146         zpios_profile_pre_start ${PROFILE_RUN_RM_PID}
147         zpios_profile_post_proc_start
148         zpios_profile_pre_oprofile_start ${PROFILE_RUN_RM_OPROFILE_LOG}
149 }
150
151 # Source global zpios test configuration
152 if [ -f ${RUN_DIR}/zpios-config.sh ]; then
153         . ${RUN_DIR}/zpios-config.sh
154 fi
155
156 # Source global per-run test configuration
157 if [ -f ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh ]; then
158         . ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh
159 fi
160
161 case "${RUN_PHASE}" in
162         pre-run)
163                 mkdir -p ${RUN_DIR}/${RUN_ID}/
164                 zpios_profile_pre_run_cfg
165                 zpios_profile_pre_run_args
166                 ;;
167         pre-create)
168                 zpios_profile_pre_create
169                 ;;
170         pre-write)
171                 zpios_profile_pre_write
172                 ;;
173         pre-read)
174                 zpios_profile_pre_read
175                 ;;
176         pre-remove)
177                 zpios_profile_pre_remove
178                 ;;
179         *)
180                 echo "Usage: ${PROG} {pre-run|pre-create|pre-write|pre-read|pre-remove}"
181                 exit 1
182 esac
183
184 exit 0