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
21command -v fio > /dev/null || log_unsupported "fio missing"
22
23function cleanup
24{
25	# kill fio and iostat
26	pkill fio
27	pkill iostat
28
29	#
30	# We're using many filesystems depending on the number of
31	# threads for each test, and there's no good way to get a list
32	# of all the filesystems that should be destroyed on cleanup
33	# (i.e. the list of filesystems used for the last test ran).
34	# Thus, we simply recreate the pool as a way to destroy all
35	# filesystems and leave a fresh pool behind.
36	#
37	recreate_perf_pool
38}
39
40trap "log_fail \"Measure IO stats during random write load\"" SIGTERM
41log_onexit cleanup
42
43recreate_perf_pool
44
45# Aim to fill the pool to 50% capacity while accounting for a 3x compressratio.
46export TOTAL_SIZE=$(($(get_prop avail $PERFPOOL) * 3 / 2))
47
48# Variables specific to this test for use by fio.
49export PERF_NTHREADS=${PERF_NTHREADS:-'1 16 64'}
50export PERF_NTHREADS_PER_FS=${PERF_NTHREADS_PER_FS:-'0 1'}
51export PERF_IOSIZES=${PERF_IOSIZES:-'8k'}
52export PERF_SYNC_TYPES=${PERF_SYNC_TYPES:-'1'}
53
54# Until the performance tests over NFS can deal with multiple file systems,
55# force the use of only one file system when testing over NFS.
56[[ $NFS -eq 1 ]] && PERF_NTHREADS_PER_FS='0'
57
58lun_list=$(pool_to_lun_list $PERFPOOL)
59log_note "Collecting backend IO stats with lun list $lun_list"
60if is_linux; then
61	typeset perf_record_cmd="perf record -F 99 -a -g -q \
62	    -o /dev/stdout -- sleep ${PERF_RUNTIME}"
63
64	export collect_scripts=(
65	    "zpool iostat -lpvyL $PERFPOOL 1" "zpool.iostat"
66	    "vmstat -t 1" "vmstat"
67	    "mpstat -P ALL 1" "mpstat"
68	    "iostat -tdxyz 1" "iostat"
69	    "$perf_record_cmd" "perf"
70	)
71else
72	export collect_scripts=(
73	    "kstat zfs:0 1" "kstat"
74	    "vmstat -T d 1" "vmstat"
75	    "mpstat -T d 1" "mpstat"
76	    "iostat -T d -xcnz 1" "iostat"
77	    "dtrace -Cs $PERF_SCRIPTS/io.d $PERFPOOL $lun_list 1" "io"
78	    "dtrace  -s $PERF_SCRIPTS/zil.d $PERFPOOL 1" "zil"
79	    "dtrace  -s $PERF_SCRIPTS/profile.d" "profile"
80	    "dtrace  -s $PERF_SCRIPTS/offcpu-profile.d" "offcpu-profile"
81	)
82fi
83log_note \
84    "ZIL specific random write workload with settings: $(print_perf_settings)"
85do_fio_run random_writes.fio true false
86log_pass "Measure IO stats during ZIL specific random write workload"
87