-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjson-io-raw
108 lines (94 loc) · 3.27 KB
/
json-io-raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- tab-width: 4 -*- ;; Emacs
# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
############################################################ IDENT(1)
#
# $Title: dwatch(8) JSON module for dtrace_io(4) $
# $Copyright: 2014-2022 Devin Teske. All rights reserved. $
# $FrauBSD: dwatch-json/json-io-raw 2022-08-22 15:36:11 -0700 freebsdfrau $
# $Version: 1.0 $
#
############################################################ DESCRIPTION
#
# Produce JSON custom log format for disk I/O
#
############################################################ PROBE
: "${PROBE:=io:::start,io:::done}"
############################################################ EVENT ACTION
EVENT_TEST='this->devinfo.dev_name != "" && this->event != ""'
############################################################ ACTIONS
exec 9<<EOF
this bufinfo_t bufinfo;
this devinfo_t devinfo;
this int b_flags;
this long bio_length;
this string bio_cmd;
this string bio_flags;
this string device_entry;
this string device_if;
this string device_type;
this string event;
inline string append_bio_flag[int flags, int flag] = this->bio_flags =
strjoin(this->bio_flags,
strjoin(this->bio_flags == "" ? "" : (flags & flag) == flag ? "|" : "",
bio_flag_string[flags & flag]));
/****************************** I/O ******************************/
$PROBE /(struct bio *)args[0] != NULL/ /* probe ID $ID */
{${TRACE:+
printf("<$ID>");
}
/*
* dtrace_io(4)
*/
this->event = probename;
/*
* struct bio *
*/
this->bufinfo = xlate <bufinfo_t> ((struct bio *)args[0]);
this->bio_cmd = bio_cmd_string[(int)this->bufinfo.b_cmd];
this->b_flags = (int)this->bufinfo.b_flags;
this->bio_flags = bio_flag_string[this->b_flags & BIO_ERROR];
this->bio_flags = strjoin(this->bio_flags, this->bufinfo.b_error ?
strjoin(this->bio_flags == "" ?
bio_flag_string[BIO_ERROR] : "",
strjoin("#", lltostr(this->bufinfo.b_error))) :
"");
append_bio_flag[this->b_flags, BIO_DONE];
append_bio_flag[this->b_flags, BIO_ONQUEUE];
append_bio_flag[this->b_flags, BIO_ORDERED];
append_bio_flag[this->b_flags, BIO_UNMAPPED];
append_bio_flag[this->b_flags, BIO_TRANSIENT_MAPPING];
append_bio_flag[this->b_flags, BIO_VLIST];
this->bio_flags = this->bio_flags == "" ? "-" : this->bio_flags;
this->bio_length = (long)this->bufinfo.b_bcount;
/*
* struct devstat *
*/
this->devinfo = xlate <devinfo_t> ((struct devstat *)args[1]);
this->device_type = device_type[(int)this->devinfo.dev_type];
this->device_if = device_if[(int)this->devinfo.dev_type];
this->device_entry = strjoin(this->devinfo.dev_name,
lltostr(this->devinfo.dev_minor));
}
EOF
ACTIONS=$( cat <&9 )
ID=$(( $ID + 1 ))
############################################################ EVENT DETAILS
exec 9<<EOF
/*
* Print event details
*/
printf("{\"report_type\":\"${PROFILE%-raw}\",\"epoch\":%u,\"io\":\"%s\",\"type\":\"%s\",\"if\":\"%s\",\"device\":\"%s\",\"bio_cmd\":\"%s\",\"bio_flags\":\"%s\",\"length\":%u}",
walltimestamp / 1000000000,
this->event,
this->device_type,
this->device_if,
this->device_entry,
this->bio_cmd,
this->bio_flags,
this->bio_length);
this->event = "";
EOF
EVENT_DETAILS=$( cat <&9 )
################################################################################
# END
################################################################################