]> git.proxmox.com Git - mirror_zfs-debian.git/blame - scripts/zpios-profile/zpios-profile-pre.sh
Merge branch 'upstream'
[mirror_zfs-debian.git] / scripts / zpios-profile / zpios-profile-pre.sh
CommitLineData
302ef151
BB
1#!/bin/bash
2
3PROG=zpios-profile-pre.sh
4
5PROFILE_RDY=0
6trap "PROFILE_RDY=1" SIGHUP
7
8RUN_PRE=${0}
9RUN_PHASE=${1}
10RUN_DIR=${2}
11RUN_ID=${3}
12RUN_POOL=${4}
13RUN_CHUNK_SIZE=${5}
14RUN_REGION_SIZE=${6}
15RUN_THRD_COUNT=${7}
16RUN_REGION_COUNT=${8}
17RUN_OFFSET=${9}
18RUN_REGION_NOISE=${10}
19RUN_CHUNK_NOISE=${11}
20RUN_THRD_DELAY=${12}
21RUN_FLAGS=${13}
22RUN_RESULT=${14}
23
24zpios_profile_pre_run_cfg() {
25cat > ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh << EOF
26#
27# Zpios Profiling Configuration for Run ${RUN_ID}
28#
29
30PROFILE_RUN_DIR=${RUN_DIR}/${RUN_ID}
31
32PROFILE_RUN_CR_DIR=${RUN_DIR}/${RUN_ID}/create
33PROFILE_RUN_CR_PID=${RUN_DIR}/${RUN_ID}/create/profile.pid
34PROFILE_RUN_CR_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/create/oprofile.txt
35PROFILE_RUN_CR_PIDS_LOG=${RUN_DIR}/${RUN_ID}/create/pids.txt
36PROFILE_RUN_CR_PIDS_CSV=${RUN_DIR}/${RUN_ID}/create/pids.csv
37PROFILE_RUN_CR_DISK_LOG=${RUN_DIR}/${RUN_ID}/create/disk.txt
38PROFILE_RUN_CR_DISK_CSV=${RUN_DIR}/${RUN_ID}/create/disk.csv
39
40PROFILE_RUN_WR_DIR=${RUN_DIR}/${RUN_ID}/write
41PROFILE_RUN_WR_PID=${RUN_DIR}/${RUN_ID}/write/profile.pid
42PROFILE_RUN_WR_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/write/oprofile.txt
43PROFILE_RUN_WR_PIDS_LOG=${RUN_DIR}/${RUN_ID}/write/pids.txt
44PROFILE_RUN_WR_PIDS_CSV=${RUN_DIR}/${RUN_ID}/write/pids.csv
45PROFILE_RUN_WR_DISK_LOG=${RUN_DIR}/${RUN_ID}/write/disk.txt
46PROFILE_RUN_WR_DISK_CSV=${RUN_DIR}/${RUN_ID}/write/disk.csv
47
48PROFILE_RUN_RD_DIR=${RUN_DIR}/${RUN_ID}/read
49PROFILE_RUN_RD_PID=${RUN_DIR}/${RUN_ID}/read/profile.pid
50PROFILE_RUN_RD_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/read/oprofile.txt
51PROFILE_RUN_RD_PIDS_LOG=${RUN_DIR}/${RUN_ID}/read/pids.txt
52PROFILE_RUN_RD_PIDS_CSV=${RUN_DIR}/${RUN_ID}/read/pids.csv
53PROFILE_RUN_RD_DISK_LOG=${RUN_DIR}/${RUN_ID}/read/disk.txt
54PROFILE_RUN_RD_DISK_CSV=${RUN_DIR}/${RUN_ID}/read/disk.csv
55
56PROFILE_RUN_RM_DIR=${RUN_DIR}/${RUN_ID}/remove
57PROFILE_RUN_RM_PID=${RUN_DIR}/${RUN_ID}/remove/profile.pid
58PROFILE_RUN_RM_OPROFILE_LOG=${RUN_DIR}/${RUN_ID}/remove/oprofile.txt
59PROFILE_RUN_RM_PIDS_LOG=${RUN_DIR}/${RUN_ID}/remove/pids.txt
60PROFILE_RUN_RM_PIDS_CSV=${RUN_DIR}/${RUN_ID}/remove/pids.csv
61PROFILE_RUN_RM_DISK_LOG=${RUN_DIR}/${RUN_ID}/remove/disk.txt
62PROFILE_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
66EOF
67}
68
69zpios_profile_pre_run_args() {
70cat > ${RUN_DIR}/${RUN_ID}/zpios-args.txt << EOF
71#
72# Zpios Arguments for Run ${RUN_ID}
73#
74
75DIR=${RUN_DIR}
76ID=${RUN_ID}
77POOL=${RUN_POOL}
78CHUNK_SIZE=${RUN_CHUNK_SIZE}
79REGION_SIZE=${RUN_REGION_SIZE}
80THRD_COUNT=${RUN_THRD_COUNT}
81REGION_COUNT=${RUN_REGION_COUNT}
82OFFSET=${RUN_OFFSET}
83REGION_NOISE=${RUN_REGION_NOISE}
84CHUNK_NOISE=${RUN_CHUNK_NOISE}
85THRD_DELAY=${RUN_THRD_DELAY}
86FLAGS=${RUN_FLAGS}
87RESULT=${RUN_RESULT}
88EOF
89}
90
91# Spawn a user defined profiling script to gather additional data
92zpios_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
105zpios_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
116zpios_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
123zpios_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
130zpios_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
137zpios_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
144zpios_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
152if [ -f ${RUN_DIR}/zpios-config.sh ]; then
153 . ${RUN_DIR}/zpios-config.sh
154fi
155
156# Source global per-run test configuration
157if [ -f ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh ]; then
158 . ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh
159fi
160
161case "${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
182esac
183
184exit 0