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 * Quanitize the time spent in each NFSv3 andf NFSv4 operation,
20 * optionally for a specified client and share.
21 *
22 * usage: nfs_time.d
23 * usage: nfs_time.d <client ip> <share path>
24 * example: nfs_time.d 192.168.123.1 /mypool/fs1
25 *
26 * It is valid to specify <client ip> or <share path> as "all" to
27 * quantize data for all clients and/or all shares.
28 * example: nfs_time.d 192.168.123.1 all
29 * example: nfs_time.d all /mypool/fs1
30 * example: nfs_time.d all all
31 */
32
33 #pragma D option flowindent
34 #pragma D option defaultargs
35
36 dtrace:::BEGIN
37 {
38 client = ($$1 == NULL) ? "all" : $$1;
39 share = ($$2 == NULL) ? "all" : $$2;
40 printf("%Y - client=%s share=%s\n", walltimestamp, client, share);
41 }
42
43 nfsv3:::op-*-start,
44 nfsv4:::op-*-start
45 / ((client == "all") || (args[0]->ci_remote == client)) &&
46 ((share == "all") || (args[1]->noi_shrpath == share)) /
47 {
48 self->ts[probefunc] = timestamp;
49 }
50
51 nfsv3:::op-*-done,
52 nfsv4:::op-*-done
53 / ((client == "all") || (args[0]->ci_remote == client)) &&
54 ((share == "all") || (args[1]->noi_shrpath == share)) /
55 {
56 elapsed = (timestamp - self->ts[probefunc]);
57 @q[probefunc]=quantize(elapsed);
58 }
59
60 tick-5s
61 {
62 printa(@q);
63 /*
64 * uncomment "clear" to quantize per 5s interval
65 * rather than cumulative for duration of script.
66 * clear(@q);
67 */
68 }
69
70 dtrace:::END
71 {
72 }