Add linux zpios support
[zfs.git] / scripts / zpios-profile / zpios-profile-post.sh
1 #!/bin/bash
2
3 PROG=zpios-profile-post.sh
4
5 RUN_POST=${0}
6 RUN_PHASE=${1}
7 RUN_DIR=${2}
8 RUN_ID=${3}
9 RUN_POOL=${4}
10 RUN_CHUNK_SIZE=${5}
11 RUN_REGION_SIZE=${6}
12 RUN_THRD_COUNT=${7}
13 RUN_REGION_COUNT=${8}
14 RUN_OFFSET=${9}
15 RUN_REGION_NOISE=${10}
16 RUN_CHUNK_NOISE=${11}
17 RUN_THRD_DELAY=${12}
18 RUN_FLAGS=${13}
19 RUN_RESULT=${14}
20
21 # Summarize system time per process
22 zpios_profile_post_pids() {
23         ${PROFILE_PIDS} ${PROFILE_RUN_CR_PIDS_LOG} >${PROFILE_RUN_CR_PIDS_CSV}
24         ${PROFILE_PIDS} ${PROFILE_RUN_WR_PIDS_LOG} >${PROFILE_RUN_WR_PIDS_CSV}
25         ${PROFILE_PIDS} ${PROFILE_RUN_RD_PIDS_LOG} >${PROFILE_RUN_RD_PIDS_CSV}
26         ${PROFILE_PIDS} ${PROFILE_RUN_RM_PIDS_LOG} >${PROFILE_RUN_RM_PIDS_CSV}
27 }
28
29 zpios_profile_post_disk() {
30         ${PROFILE_DISK} ${PROFILE_RUN_CR_DISK_LOG} >${PROFILE_RUN_CR_DISK_CSV}
31         ${PROFILE_DISK} ${PROFILE_RUN_WR_DISK_LOG} >${PROFILE_RUN_WR_DISK_CSV}
32         ${PROFILE_DISK} ${PROFILE_RUN_RD_DISK_LOG} >${PROFILE_RUN_RD_DISK_CSV}
33         ${PROFILE_DISK} ${PROFILE_RUN_RM_DISK_LOG} >${PROFILE_RUN_RM_DISK_CSV}
34 }
35
36 # Summarize per device performance
37
38 # Stop a user defined profiling script which is gathering additional data
39 zpios_profile_post_stop() {
40         local PROFILE_PID=$1
41
42         kill -s SIGHUP `cat ${PROFILE_PID}`
43
44
45         # Sleep waiting for profile script to exit
46         while [ -f ${PROFILE_PID} ]; do
47                 sleep 0.01
48         done
49 }
50
51 zpios_profile_post_proc_stop() {
52         local PROC_DIR=$1
53
54         if [ -f ${PROFILE_ARC_PROC} ]; then
55                 cat ${PROFILE_ARC_PROC} >${PROC_DIR}/arcstats.txt
56         fi
57
58         if [ -f ${PROFILE_VDEV_CACHE_PROC} ]; then
59                 cat ${PROFILE_VDEV_CACHE_PROC} >${PROC_DIR}/vdev_cache_stats.txt
60         fi
61 }
62
63 zpios_profile_post_oprofile_stop() {
64         local OPROFILE_LOG=$1
65         local OPROFILE_ARGS="-a -g -l -p ${OPROFILE_KERNEL_DIR},${OPROFILE_SPL_DIR},${OPROFILE_ZFS_DIR}"
66
67         /usr/bin/opcontrol --stop >>${OPROFILE_LOG} 2>&1
68         /usr/bin/opcontrol --dump >>${OPROFILE_LOG} 2>&1
69         /usr/bin/opreport ${OPROFILE_ARGS} >${OPROFILE_LOG} 2>&1
70         /usr/bin/oparchive
71 }
72
73 zpios_profile_post_create() {
74         zpios_profile_post_oprofile_stop ${PROFILE_RUN_CR_OPROFILE_LOG}
75         zpios_profile_post_proc_stop ${PROFILE_RUN_CR_DIR}
76         zpios_profile_post_stop ${PROFILE_RUN_CR_PID}
77 }
78
79 zpios_profile_post_write() {
80         zpios_profile_post_oprofile_stop ${PROFILE_RUN_WR_OPROFILE_LOG}
81         zpios_profile_post_proc_stop ${PROFILE_RUN_WR_DIR}
82         zpios_profile_post_stop ${PROFILE_RUN_WR_PID}
83 }
84
85 zpios_profile_post_read() {
86         zpios_profile_post_oprofile_stop ${PROFILE_RUN_CR_RD_LOG}
87         zpios_profile_post_proc_stop ${PROFILE_RUN_RD_DIR}
88         zpios_profile_post_stop ${PROFILE_RUN_RD_PID}
89 }
90
91 zpios_profile_post_remove() {
92         zpios_profile_post_oprofile_stop ${PROFILE_RUN_RM_OPROFILE_LOG}
93         zpios_profile_post_proc_stop ${PROFILE_RUN_RM_DIR}
94         zpios_profile_post_stop ${PROFILE_RUN_RM_PID}
95 }
96
97 # Source global zpios test configuration
98 if [ -f ${RUN_DIR}/zpios-config.sh ]; then
99         . ${RUN_DIR}/zpios-config.sh
100 fi
101
102 # Source global per-run test configuration
103 if [ -f ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh ]; then
104         . ${RUN_DIR}/${RUN_ID}/zpios-config-run.sh
105 fi
106
107 case "${RUN_PHASE}" in
108         post-run)
109                 zpios_profile_post_pids
110                 zpios_profile_post_disk
111                 ;;
112         post-create)
113                 zpios_profile_post_create
114                 ;;
115         post-write)
116                 zpios_profile_post_write
117                 ;;
118         post-read)
119                 zpios_profile_post_read
120                 ;;
121         post-remove)
122                 zpios_profile_post_remove
123                 ;;
124         *)
125                 echo "Usage: ${PROG} {post-run|post-create|post-write|post-read|post-remove}"
126                 exit 1
127 esac
128
129 exit 0