aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/zpios-profile/zpios-profile-pre.sh
blob: a2a885798d2dab0b109d3e82f3b2c7a35001e15a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash

PROG=zpios-profile-pre.sh

PROFILE_RDY=0
trap "PROFILE_RDY=1" SIGHUP

RUN_PRE=${0}
RUN_PHASE=${1}
RUN_DIR=${2}
RUN_ID=${3}
RUN_POOL=${4}
RUN_CHUNK_SIZE=${5}
RUN_REGION_SIZE=${6}
RUN_THRD_COUNT=${7}
RUN_REGION_COUNT=${8}
RUN_OFFSET=${9}
RUN_REGION_NOISE=${10}
RUN_CHUNK_NOISE=${11}
RUN_THRD_DELAY=${12}
RUN_FLAGS=${13}
RUN_RESULT=${14}

zpios_profile_pre_run_cfg() {
cat > ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh << EOF
#
# Zpios Profiling Configuration for Run ${RUN_ID}
#

PROFILE_RUN_DIR=${RUN_DIR}/${RUN_ID}

PROFILE_RUN_CR_DIR=${RUN_DIR}/${RUN_ID}/create
PROFILE_RUN_CR_PID=${RUN_DIR}/${RUN_ID}/create/profile.pid
PROFILE_RUN_CR_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/create/oprofile.txt
PROFILE_RUN_CR_PIDS_LOG=${RUN_DIR}/${RUN_ID}/create/pids.txt
PROFILE_RUN_CR_PIDS_CSV=${RUN_DIR}/${RUN_ID}/create/pids.csv
PROFILE_RUN_CR_DISK_LOG=${RUN_DIR}/${RUN_ID}/create/disk.txt
PROFILE_RUN_CR_DISK_CSV=${RUN_DIR}/${RUN_ID}/create/disk.csv

PROFILE_RUN_WR_DIR=${RUN_DIR}/${RUN_ID}/write
PROFILE_RUN_WR_PID=${RUN_DIR}/${RUN_ID}/write/profile.pid
PROFILE_RUN_WR_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/write/oprofile.txt
PROFILE_RUN_WR_PIDS_LOG=${RUN_DIR}/${RUN_ID}/write/pids.txt
PROFILE_RUN_WR_PIDS_CSV=${RUN_DIR}/${RUN_ID}/write/pids.csv
PROFILE_RUN_WR_DISK_LOG=${RUN_DIR}/${RUN_ID}/write/disk.txt
PROFILE_RUN_WR_DISK_CSV=${RUN_DIR}/${RUN_ID}/write/disk.csv

PROFILE_RUN_RD_DIR=${RUN_DIR}/${RUN_ID}/read
PROFILE_RUN_RD_PID=${RUN_DIR}/${RUN_ID}/read/profile.pid
PROFILE_RUN_RD_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/read/oprofile.txt
PROFILE_RUN_RD_PIDS_LOG=${RUN_DIR}/${RUN_ID}/read/pids.txt
PROFILE_RUN_RD_PIDS_CSV=${RUN_DIR}/${RUN_ID}/read/pids.csv
PROFILE_RUN_RD_DISK_LOG=${RUN_DIR}/${RUN_ID}/read/disk.txt
PROFILE_RUN_RD_DISK_CSV=${RUN_DIR}/${RUN_ID}/read/disk.csv

PROFILE_RUN_RM_DIR=${RUN_DIR}/${RUN_ID}/remove
PROFILE_RUN_RM_PID=${RUN_DIR}/${RUN_ID}/remove/profile.pid
PROFILE_RUN_RM_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/remove/oprofile.txt
PROFILE_RUN_RM_PIDS_LOG=${RUN_DIR}/${RUN_ID}/remove/pids.txt
PROFILE_RUN_RM_PIDS_CSV=${RUN_DIR}/${RUN_ID}/remove/pids.csv
PROFILE_RUN_RM_DISK_LOG=${RUN_DIR}/${RUN_ID}/remove/disk.txt
PROFILE_RUN_RM_DISK_CSV=${RUN_DIR}/${RUN_ID}/remove/disk.csv

# PROFILE_PIDS_LOG=${RUN_DIR}/${RUN_ID}/pids-summary.csv
# PROFILE_DISK_LOG=${RUN_DIR}/${RUN_ID}/disk-summary.csv
EOF
}

zpios_profile_pre_run_args() {
cat > ${RUN_DIR}/${RUN_ID}/zpios-args.txt << EOF
#
# Zpios Arguments for Run ${RUN_ID}
#

DIR=${RUN_DIR}
ID=${RUN_ID}
POOL=${RUN_POOL}
CHUNK_SIZE=${RUN_CHUNK_SIZE}
REGION_SIZE=${RUN_REGION_SIZE}
THRD_COUNT=${RUN_THRD_COUNT}
REGION_COUNT=${RUN_REGION_COUNT}
OFFSET=${RUN_OFFSET}
REGION_NOISE=${RUN_REGION_NOISE}
CHUNK_NOISE=${RUN_CHUNK_NOISE}
THRD_DELAY=${RUN_THRD_DELAY}
FLAGS=${RUN_FLAGS}
RESULT=${RUN_RESULT}
EOF
}

# Spawn a user defined profiling script to gather additional data
zpios_profile_pre_start() {
	local PROFILE_PID=$1

	${PROFILE_USER} ${RUN_PHASE} ${RUN_DIR} ${RUN_ID} &
	echo "$!" >${PROFILE_PID}

	# Sleep waiting for profile script to be ready, it will
	# signal us via SIGHUP when it is ready to start profiling.
	while [ ${PROFILE_RDY} -eq 0 ]; do
		sleep 0.01
	done
}

zpios_profile_post_proc_start() { 

        if [ -f ${PROFILE_ARC_PROC} ]; then
                echo 0 >${PROFILE_ARC_PROC}
        fi

        if [ -f ${PROFILE_VDEV_CACHE_PROC} ]; then
                echo 0 >${PROFILE_VDEV_CACHE_PROC}
        fi
}

zpios_profile_pre_oprofile_start() {
	local OPROFILE_LOG=$1

	/usr/bin/opcontrol --reset >>${OPROFILE_LOG} 2>&1
	/usr/bin/opcontrol --start >>${OPROFILE_LOG} 2>&1
}

zpios_profile_pre_create() {
	mkdir ${PROFILE_RUN_CR_DIR}
	zpios_profile_pre_start ${PROFILE_RUN_CR_PID}
	zpios_profile_post_proc_start
	zpios_profile_pre_oprofile_start ${PROFILE_RUN_CR_OPROFILE_LOG}
}

zpios_profile_pre_write() {
	mkdir ${PROFILE_RUN_WR_DIR}
	zpios_profile_pre_start ${PROFILE_RUN_WR_PID}
	zpios_profile_post_proc_start
	zpios_profile_pre_oprofile_start ${PROFILE_RUN_WR_OPROFILE_LOG}
}

zpios_profile_pre_read() {
	mkdir ${PROFILE_RUN_RD_DIR}
	zpios_profile_pre_start ${PROFILE_RUN_RD_PID}
	zpios_profile_post_proc_start
	zpios_profile_pre_oprofile_start ${PROFILE_RUN_CR_RD_LOG}
}

zpios_profile_pre_remove() {
	mkdir ${PROFILE_RUN_RM_DIR}
	zpios_profile_pre_start ${PROFILE_RUN_RM_PID}
	zpios_profile_post_proc_start
	zpios_profile_pre_oprofile_start ${PROFILE_RUN_RM_OPROFILE_LOG}
}

# Source global zpios test configuration
if [ -f ${RUN_DIR}/zpios-config.sh ]; then
	. ${RUN_DIR}/zpios-config.sh
fi

# Source global per-run test configuration
if [ -f ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh ]; then
	. ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh
fi

case "${RUN_PHASE}" in
	pre-run)
		mkdir -p ${RUN_DIR}/${RUN_ID}/
		zpios_profile_pre_run_cfg
		zpios_profile_pre_run_args
		;;
	pre-create)
		zpios_profile_pre_create
		;;
	pre-write)
		zpios_profile_pre_write
		;;
	pre-read)
		zpios_profile_pre_read
		;;
	pre-remove)
		zpios_profile_pre_remove
		;;
	*)
		echo "Usage: ${PROG} {pre-run|pre-create|pre-write|pre-read|pre-remove}"
		exit 1
esac

exit 0