1#!/bin/sh
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) 2016 by Intel, Corp.
16#
17
18#
19# Linux platform placeholder for collecting prefetch I/O stats
20# TBD if we can add additional kstats to achieve the desired results
21#
22
23getstat() {
24	awk -v c="$1" '$1 == c {print $3; exit}' /proc/spl/kstat/zfs/arcstats
25}
26
27get_prefetch_ios() {
28	echo $(( $(getstat prefetch_data_misses) + $(getstat prefetch_metadata_misses) ))
29}
30
31if [ $# -ne 2 ]
32then
33	echo "Usage: ${0##*/} poolname interval" >&2
34	exit 1
35fi
36
37interval=$2
38prefetch_ios=$(get_prefetch_ios)
39prefetched_demand_reads=$(getstat demand_hit_predictive_prefetch)
40async_upgrade_sync=$(getstat async_upgrade_sync)
41
42while true
43do
44	new_prefetch_ios=$(get_prefetch_ios)
45	printf '%u\n%-24s\t%u\n' "$(date +%s)" "prefetch_ios" \
46	    $(( new_prefetch_ios - prefetch_ios ))
47	prefetch_ios=$new_prefetch_ios
48
49	new_prefetched_demand_reads=$(getstat demand_hit_predictive_prefetch)
50	printf '%-24s\t%u\n' "prefetched_demand_reads" \
51	    $(( new_prefetched_demand_reads - prefetched_demand_reads ))
52	prefetched_demand_reads=$new_prefetched_demand_reads
53
54	new_async_upgrade_sync=$(getstat async_upgrade_sync)
55	printf '%-24s\t%u\n' "async_upgrade_sync" \
56	    $(( new_async_upgrade_sync - async_upgrade_sync ))
57	async_upgrade_sync=$new_async_upgrade_sync
58
59	sleep "$interval"
60done
61