xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Apps/nfswizard.d (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 #!/usr/sbin/dtrace -s
2 /*
3  * nfswizard.d - nfs client activity wizard.
4  *               Written using DTrace (Solaris 10 3/05).
5  *
6  * This examines activity caused by NFS client processes on the same server
7  * that you are running this script on. A detailed report is generated
8  * to explain various details of NFS client activity, including response
9  * times and file access.
10  *
11  * $Id: nfswizard.d,v 1.1.1.1 2015/09/30 22:01:06 christos Exp $
12  *
13  * USAGE:     nfswizard.d    # hit Ctrl-C to end sample
14  *
15  * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
16  *
17  * CDDL HEADER START
18  *
19  *  The contents of this file are subject to the terms of the
20  *  Common Development and Distribution License, Version 1.0 only
21  *  (the "License").  You may not use this file except in compliance
22  *  with the License.
23  *
24  *  You can obtain a copy of the license at Docs/cddl1.txt
25  *  or http://www.opensolaris.org/os/licensing.
26  *  See the License for the specific language governing permissions
27  *  and limitations under the License.
28  *
29  * CDDL HEADER END
30  *
31  * 02-Dec-2005  Brendan Gregg   Created this.
32  * 20-Apr-2006	   "	  "	Last update.
33  */
34 
35 #pragma D option quiet
36 
37 dtrace:::BEGIN
38 {
39 	printf("Tracing... Hit Ctrl-C to end.\n");
40 	scriptstart = walltimestamp;
41 	timestart = timestamp;
42 }
43 
44 io:nfs::start
45 {
46 	/* tally file sizes */
47 	@file[args[2]->fi_pathname] = sum(args[0]->b_bcount);
48 
49 	/* time response */
50 	start[args[0]->b_addr] = timestamp;
51 
52 	/* overall stats */
53 	@rbytes = sum(args[0]->b_flags & B_READ ? args[0]->b_bcount : 0);
54 	@wbytes = sum(args[0]->b_flags & B_READ ? 0 : args[0]->b_bcount);
55 	@events = count();
56 }
57 
58 io:nfs::done
59 /start[args[0]->b_addr]/
60 {
61 	/* calculate and save response time stats */
62 	this->elapsed = timestamp - start[args[0]->b_addr];
63 	@maxtime = max(this->elapsed);
64 	@avgtime = avg(this->elapsed);
65 	@qnztime = quantize(this->elapsed / 1000);
66 }
67 
68 dtrace:::END
69 {
70 	/* print header */
71 	printf("NFS Client Wizard. %Y -> %Y\n\n", scriptstart, walltimestamp);
72 
73 	/* print read/write stats */
74 	printa("Read:  %@d bytes ", @rbytes);
75 	normalize(@rbytes, 1000000);
76 	printa("(%@d Mb)\n", @rbytes);
77 	printa("Write: %@d bytes ", @wbytes);
78 	normalize(@wbytes, 1000000);
79 	printa("(%@d Mb)\n\n", @wbytes);
80 
81 	/* print throughput stats */
82 	denormalize(@rbytes);
83 	normalize(@rbytes, (timestamp - timestart) / 1000000);
84 	printa("Read:  %@d Kb/sec\n", @rbytes);
85 	denormalize(@wbytes);
86 	normalize(@wbytes, (timestamp - timestart) / 1000000);
87 	printa("Write: %@d Kb/sec\n\n", @wbytes);
88 
89 	/* print time stats */
90 	printa("NFS I/O events:    %@d\n", @events);
91 	normalize(@avgtime, 1000000);
92 	printa("Avg response time: %@d ms\n", @avgtime);
93 	normalize(@maxtime, 1000000);
94 	printa("Max response time: %@d ms\n\n", @maxtime);
95 	printa("Response times (us):%@d\n", @qnztime);
96 
97 	/* print file stats */
98 	printf("Top 25 files accessed (bytes):\n");
99 	printf("   %-64s %s\n", "PATHNAME", "BYTES");
100 	trunc(@file, 25);
101 	printa("   %-64s %@d\n", @file);
102 }
103