]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/usr.sbin/dwatch/libexec/io
Merge llvm trunk r338150 (just before the 7.0.0 branch point), and
[FreeBSD/FreeBSD.git] / cddl / usr.sbin / dwatch / libexec / io
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$
8 #
9 ############################################################ DESCRIPTION
10 #
11 # Display activity related to disk I/O
12 #
13 ############################################################ PROBE
14
15 case "$PROFILE" in
16 io) : ${PROBE:=io:::start, io:::done} ;;
17  *) : ${PROBE:=io:::${PROFILE#io-}}
18 esac
19
20 ############################################################ EVENT ACTION
21
22 [ "$CUSTOM_TEST" ] || EVENT_TEST='this->devinfo.dev_name != ""'
23
24 ############################################################ ACTIONS
25
26 exec 9<<EOF
27 this bufinfo_t  bufinfo;
28 this devinfo_t  devinfo;
29 this int        b_flags;
30 this long       bio_length;
31 this string     bio_cmd;
32 this string     bio_flags;
33 this string     device_entry;
34 this string     device_if;
35 this string     device_type;
36 this string     flow;
37
38 inline 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 }
82 EOF
83 ACTIONS=$( cat <&9 )
84 ID=$(( $ID + 1 ))
85
86 ############################################################ EVENT DETAILS
87
88 if [ ! "$CUSTOM_DETAILS" ]; then
89 exec 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");
102 EOF
103 EVENT_DETAILS=$( cat <&9 )
104 fi
105
106 ################################################################################
107 # END
108 ################################################################################