xref: /illumos-gate/usr/src/cmd/fs.d/nfs/dtrace/nfs-time.d (revision 31aa620247ae407b2bee2dccd71693d1938f54d6)
1 #!/usr/sbin/dtrace -s
2 
3 /*
4  * This file and its contents are supplied under the terms of the
5  * Common Development and Distribution License ("CDDL"), version 1.0.
6  * You may only use this file in accordance with the terms of version
7  * 1.0 of the CDDL.
8  *
9  * A full copy of the text of the CDDL should have accompanied this
10  * source.  A copy of the CDDL is also available via the Internet at
11  * http://www.illumos.org/license/CDDL.
12  */
13 
14 /*
15  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
16  */
17 
18 /*
19  * Quantize the time spent in each NFSv3 andf NFSv4 operation,
20  * optionally for a specified client, share and zone.
21  *
22  * Usage: nfs-time.d [<client ip>|all [<share path>|all] [<zone id>]]]
23  *
24  * example: nfs_time.d 192.168.123.1 /mypool/fs1  0
25  *
26  * It is valid to specify <client ip> or <share path> as "all"
27  * to quantize data for all clients and/or all shares.
28  * Omitting <zone id> will quantize data for all zones.
29  */
30 
31 #pragma D option flowindent
32 #pragma D option defaultargs
33 
34 dtrace:::BEGIN
35 {
36 	all_clients = (($$1 == NULL) || ($$1 == "all")) ? 1 : 0;
37 	all_shares = (($$2 == NULL) || ($$2 == "all")) ? 1 : 0;
38 	all_zones = ($$3 == NULL) ? 1 : 0;
39 
40 	client = $$1;
41 	share = $$2;
42 	zoneid = $3;
43 
44 	printf("%Y - client=%s share=%s zone=%s)\n", walltimestamp,
45 	    (all_clients) ? "all" : client,
46 	    (all_shares) ? "all" : share,
47 	    (all_zones) ? "all" : $$3);
48 }
49 
50 nfsv3:::op-*-start,
51 nfsv4:::op-*-start
52 {
53 	self->ts[probefunc] = timestamp;
54 }
55 
56 nfsv3:::op-*-done,
57 nfsv4:::op-*-done
58 / ((all_clients) || (args[0]->ci_remote == client)) &&
59    ((all_shares) || (args[1]->noi_shrpath == share)) &&
60    ((all_zones) || (args[1]->noi_zoneid == zoneid)) /
61 {
62 	elapsed = (timestamp - self->ts[probefunc]);
63 	@q[probefunc]=quantize(elapsed);
64 }
65 
66 tick-5s
67 {
68 	printa(@q);
69 	/*
70 	 * uncomment "clear" to quantize per 5s interval
71 	 * rather than cumulative for duration of script.
72 	 * clear(@q);
73 	 */
74 }
75 
76 dtrace:::END
77 {
78 }
79