5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright (c) 2017, Lawrence Livermore National Security, LLC.
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/include/math.shlib
32 # Ensure stats presented in /proc/spl/kstat/zfs/dbufstats are correct
33 # based on /proc/spl/kstat/zfs/dbufs.
36 # 1. Generate a file with random data in it
37 # 2. Store output from dbufs kstat
38 # 3. Store output from dbufstats kstat
39 # 4. Compare stats presented in dbufstats with stat generated using
40 # dbufstat and the dbufs kstat output
43 DBUFSTATS_FILE=$(mktemp $TEST_BASE_DIR/dbufstats.out.XXXXXX)
44 DBUFS_FILE=$(mktemp $TEST_BASE_DIR/dbufs.out.XXXXXX)
48 log_must rm -f $TESTDIR/file $DBUFS_FILE $DBUFSTATS_FILE
51 function testdbufstat # stat_name dbufstat_filter
56 [[ -n "$2" ]] && filter="-F $2"
59 from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" |
62 from_dbufstat=$(awk "/dbufstats\.$name:/ { print \$2 }" \
65 from_dbufs=$(dbufstat -bxn -i "$DBUFS_FILE" "$filter" | wc -l)
67 within_tolerance $from_dbufstat $from_dbufs 15 \
68 || log_fail "Stat $name exceeded tolerance"
71 verify_runnable "both"
73 log_assert "dbufstats produces correct statistics"
77 log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 20 -d R
80 log_must eval "kstat dbufs > $DBUFS_FILE"
81 log_must eval "kstat dbufstats '' > $DBUFSTATS_FILE"
83 for level in {0..11}; do
84 testdbufstat "cache_level_$level" "dbc=1,level=$level"
87 testdbufstat "cache_count" "dbc=1"
88 testdbufstat "hash_elements" ""
90 log_pass "dbufstats produces correct statistics passed"