1# -*- tab-width: 4 -*- ;; Emacs
2# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
3############################################################ IDENT(1)
4#
5# $Title: dwatch(8) module for dtrace_io(4) $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7# $FreeBSD: stable/11/cddl/usr.sbin/dwatch/libexec/io 333617 2018-05-15 00:00:44Z dteske $
8#
9############################################################ DESCRIPTION
10#
11# Display activity related to disk I/O
12#
13############################################################ PROBE
14
15case "$PROFILE" in
16io) : ${PROBE:=io:::start, io:::done} ;;
17 *) : ${PROBE:=io:::${PROFILE#io-}}
18esac
19
20############################################################ EVENT ACTION
21
22[ "$CUSTOM_TEST" ] || EVENT_TEST='this->devinfo.dev_name != ""'
23
24############################################################ ACTIONS
25
26exec 9<<EOF
27this bufinfo_t	bufinfo;
28this devinfo_t	devinfo;
29this int	b_flags;
30this long	bio_length;
31this string	bio_cmd;
32this string	bio_flags;
33this string	device_entry;
34this string	device_if;
35this string	device_type;
36this string	flow;
37
38inline string append_bio_flag[int flags, int flag] = this->bio_flags =
39	strjoin(this->bio_flags,
40	strjoin(this->bio_flags == "" ? "" : (flags & flag) == flag ? "|" : "",
41		bio_flag_string[flags & flag]));
42
43$PROBE /(struct bio *)args[0] != NULL/ /* probe ID $ID */
44{${TRACE:+
45	printf("<$ID>");
46}
47	/*
48	 * dtrace_io(4)
49	 */
50	this->flow = probefunc == "done" ? "<-" : "->";
51
52	/*
53	 * struct bio *
54	 */
55	this->bufinfo = xlate <bufinfo_t> ((struct bio *)args[0]);
56	this->bio_cmd = bio_cmd_string[(int)this->bufinfo.b_cmd];
57	this->b_flags = (int)this->bufinfo.b_flags;
58	this->bio_flags = bio_flag_string[this->b_flags & BIO_ERROR];
59	this->bio_flags = strjoin(this->bio_flags, this->bufinfo.b_error ?
60		strjoin(this->bio_flags == "" ?
61			bio_flag_string[BIO_ERROR] : "",
62			strjoin("#", lltostr(this->bufinfo.b_error))) :
63		"");
64	append_bio_flag[this->b_flags, BIO_DONE];
65	append_bio_flag[this->b_flags, BIO_ONQUEUE];
66	append_bio_flag[this->b_flags, BIO_ORDERED];
67	append_bio_flag[this->b_flags, BIO_UNMAPPED];
68	append_bio_flag[this->b_flags, BIO_TRANSIENT_MAPPING];
69	append_bio_flag[this->b_flags, BIO_VLIST];
70	this->bio_flags = this->bio_flags == "" ? "-" : this->bio_flags;
71	this->bio_length = (long)this->bufinfo.b_bcount;
72
73	/*
74	 * struct devstat *
75	 */
76	this->devinfo = xlate <devinfo_t> ((struct devstat *)args[1]);
77	this->device_type = device_type[(int)this->devinfo.dev_type];
78	this->device_if = device_if[(int)this->devinfo.dev_type];
79	this->device_entry = strjoin(this->devinfo.dev_name,
80		lltostr(this->devinfo.dev_minor));
81}
82EOF
83ACTIONS=$( cat <&9 )
84ID=$(( $ID + 1 ))
85
86############################################################ EVENT DETAILS
87
88if [ ! "$CUSTOM_DETAILS" ]; then
89exec 9<<EOF
90	/*
91	 * Print disk I/O details
92	 */
93	printf("%s %s %s %s %s %s %d byte%s",
94		this->flow,
95		this->device_type,
96		this->device_if,
97		this->device_entry,
98		this->bio_cmd,
99		this->bio_flags,
100		this->bio_length,
101		this->bio_length == 1 ? "" : "s");
102EOF
103EVENT_DETAILS=$( cat <&9 )
104fi
105
106################################################################################
107# END
108################################################################################
109