1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2015, 2021 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19. $STF_SUITE/tests/perf/perf.shlib
20
21function cleanup
22{
23	# kill fio and iostat
24	pkill fio
25	pkill iostat
26
27	#
28	# We're using many filesystems depending on the number of
29	# threads for each test, and there's no good way to get a list
30	# of all the filesystems that should be destroyed on cleanup
31	# (i.e. the list of filesystems used for the last test ran).
32	# Thus, we simply recreate the pool as a way to destroy all
33	# filesystems and leave a fresh pool behind.
34	#
35	recreate_perf_pool
36}
37
38trap "log_fail \"Measure IO stats during random write load\"" SIGTERM
39log_onexit cleanup
40
41recreate_perf_pool
42
43# Aim to fill the pool to 50% capacity while accounting for a 3x compressratio.
44export TOTAL_SIZE=$(($(get_prop avail $PERFPOOL) * 3 / 2))
45
46# Variables specific to this test for use by fio.
47export PERF_NTHREADS=${PERF_NTHREADS:-'1 4 16 64'}
48export PERF_NTHREADS_PER_FS=${PERF_NTHREADS_PER_FS:-'0 1'}
49export PERF_IOSIZES=${PERF_IOSIZES:-'8k'}
50
51# Until the performance tests over NFS can deal with multiple file systems,
52# force the use of only one file system when testing over NFS.
53[[ $NFS -eq 1 ]] && PERF_NTHREADS_PER_FS='0'
54
55lun_list=$(pool_to_lun_list $PERFPOOL)
56log_note "Collecting backend IO stats with lun list $lun_list"
57if is_linux; then
58	typeset perf_record_cmd="perf record -F 99 -a -g -q \
59	    -o /dev/stdout -- sleep ${PERF_RUNTIME}"
60
61	export collect_scripts=(
62	    "zpool iostat -lpvyL $PERFPOOL 1" "zpool.iostat"
63	    "vmstat -t 1" "vmstat"
64	    "mpstat -P ALL 1" "mpstat"
65	    "iostat -tdxyz 1" "iostat"
66	    "$perf_record_cmd" "perf"
67	)
68else
69	export collect_scripts=(
70	    "kstat zfs:0 1" "kstat"
71	    "vmstat -T d 1" "vmstat"
72	    "mpstat -T d 1" "mpstat"
73	    "iostat -T d -xcnz 1" "iostat"
74	    "dtrace -Cs $PERF_SCRIPTS/io.d $PERFPOOL $lun_list 1" "io"
75	    "dtrace  -s $PERF_SCRIPTS/zil.d $PERFPOOL 1" "zil"
76	    "dtrace  -s $PERF_SCRIPTS/profile.d" "profile"
77	    "dtrace  -s $PERF_SCRIPTS/offcpu-profile.d" "offcpu-profile"
78	)
79fi
80log_note \
81    "ZIL specific random write workload with settings: $(print_perf_settings)"
82do_fio_run random_writes.fio true false
83log_pass "Measure IO stats during ZIL specific random write workload"
84