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