1
|
#!/usr/sbin/dtrace -s
|
2
|
/*
|
3
|
* This file and its contents are supplied under the terms of the
|
4
|
* Common Development and Distribution License ("CDDL"), version 1.0.
|
5
|
* You may only use this file in accordance with the terms of version
|
6
|
* 1.0 of the CDDL.
|
7
|
*
|
8
|
* A full copy of the text of the CDDL should have accompanied this
|
9
|
* source. A copy of the CDDL is also available via the Internet at
|
10
|
* http://www.illumos.org/license/CDDL.
|
11
|
*/
|
12
|
|
13
|
/*
|
14
|
* Copyright 2018 Nexenta Systems, Inc. All rights reserved.
|
15
|
*/
|
16
|
|
17
|
/*
|
18
|
* Example using the "smb2" dtrace provider.
|
19
|
* Traces all SMB commands.
|
20
|
*
|
21
|
* All these probes provide:
|
22
|
* args[0] conninfo_t
|
23
|
* args[1] smb2opinfo_t
|
24
|
* Some also provide one of: (not used here)
|
25
|
* args[2] smb_open_args_t
|
26
|
* args[2] smb_rw_args_t
|
27
|
*
|
28
|
* Usage: smb2-trace.d [<client ip>|all [<share path>|all] [<zone id>]]]
|
29
|
*
|
30
|
* example: smb2_trace.d 192.168.012.001 mypool_fs1 0
|
31
|
*
|
32
|
* It is valid to specify <client ip> or <share path> as "all" to
|
33
|
* print data for all clients and/or all shares.
|
34
|
* Omitting <zone id> will print data for all zones.
|
35
|
*/
|
36
|
|
37
|
#pragma D option defaultargs
|
38
|
|
39
|
dtrace:::BEGIN
|
40
|
{
|
41
|
all_clients = (($$1 == NULL) || ($$1 == "all")) ? 1 : 0;
|
42
|
all_shares = (($$2 == NULL) || ($$2 == "all")) ? 1 : 0;
|
43
|
all_zones = ($$3 == NULL) ? 1 : 0;
|
44
|
|
45
|
client = $$1;
|
46
|
share = $$2;
|
47
|
zoneid = $3;
|
48
|
|
49
|
printf("%Y - client=%s share=%s zone=%s)\n", walltimestamp,
|
50
|
(all_clients) ? "all" : client,
|
51
|
(all_shares) ? "all" : share,
|
52
|
(all_zones) ? "all" : $$3);
|
53
|
}
|
54
|
|
55
|
smb2:::op-*-start
|
56
|
/ ((all_clients == 1) || (args[0]->ci_remote == client)) &&
|
57
|
((all_shares == 1) || (args[1]->soi_share == share)) &&
|
58
|
((all_zones == 1) || (args[1]->soi_zoneid == zoneid)) /
|
59
|
{
|
60
|
/* printf("clnt=%s mid=0x%x uid=0x%x tid=0x%x\n",
|
61
|
args[0]->ci_remote,
|
62
|
args[1]->soi_mid,
|
63
|
args[1]->soi_uid,
|
64
|
args[1]->soi_tid);
|
65
|
*/
|
66
|
self->s = timestamp;
|
67
|
}
|
68
|
|
69
|
smb2:::op-*-done
|
70
|
/ ((all_clients == 1) || (args[0]->ci_remote == client)) &&
|
71
|
((all_shares == 1) || (args[1]->soi_share == share)) &&
|
72
|
((all_zones == 1) || (args[1]->soi_zoneid == zoneid)) &&
|
73
|
(self->s) /
|
74
|
{
|
75
|
/* printf("clnt=%s mid=0x%x status=0x%x\n",
|
76
|
args[0]->ci_remote,
|
77
|
args[1]->soi_mid,
|
78
|
args[1]->soi_status);
|
79
|
*/
|
80
|
duration=timestamp - self->s;
|
81
|
self->s = 0;
|
82
|
@avg[probefunc] = avg(duration);
|
83
|
@max[probefunc] = max(duration);
|
84
|
@min[probefunc] = min(duration);
|
85
|
@sum[probefunc] = sum(duration);
|
86
|
@count[probefunc] = count();
|
87
|
}
|
88
|
|
89
|
dtrace:::END
|
90
|
{
|
91
|
printf("\nAvg:");
|
92
|
printa(@avg);
|
93
|
|
94
|
printf("\nMax:");
|
95
|
printa(@max);
|
96
|
|
97
|
printf("\nMin:");
|
98
|
printa(@min);
|
99
|
|
100
|
printf("\nSum:");
|
101
|
printa(@sum);
|
102
|
|
103
|
printf("\nCount:");
|
104
|
printa(@count);
|
105
|
}
|