1235368Sgnn#!/usr/sbin/dtrace -s
2235368Sgnn/*
3235368Sgnn * nfswizard.d - nfs client activity wizard.
4235368Sgnn *               Written using DTrace (Solaris 10 3/05).
5235368Sgnn *
6235368Sgnn * This examines activity caused by NFS client processes on the same server
7235368Sgnn * that you are running this script on. A detailed report is generated
8235368Sgnn * to explain various details of NFS client activity, including response
9235368Sgnn * times and file access.
10235368Sgnn *
11235368Sgnn * $Id: nfswizard.d 3 2007-08-01 10:50:08Z brendan $
12235368Sgnn *
13235368Sgnn * USAGE:     nfswizard.d    # hit Ctrl-C to end sample
14235368Sgnn *
15235368Sgnn * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
16235368Sgnn *
17235368Sgnn * CDDL HEADER START
18235368Sgnn *
19235368Sgnn *  The contents of this file are subject to the terms of the
20235368Sgnn *  Common Development and Distribution License, Version 1.0 only
21235368Sgnn *  (the "License").  You may not use this file except in compliance
22235368Sgnn *  with the License.
23235368Sgnn *
24235368Sgnn *  You can obtain a copy of the license at Docs/cddl1.txt
25235368Sgnn *  or http://www.opensolaris.org/os/licensing.
26235368Sgnn *  See the License for the specific language governing permissions
27235368Sgnn *  and limitations under the License.
28235368Sgnn *
29235368Sgnn * CDDL HEADER END
30235368Sgnn *
31235368Sgnn * 02-Dec-2005  Brendan Gregg   Created this.
32235368Sgnn * 20-Apr-2006	   "	  "	Last update.
33235368Sgnn */
34235368Sgnn
35235368Sgnn#pragma D option quiet
36235368Sgnn
37235368Sgnndtrace:::BEGIN
38235368Sgnn{
39235368Sgnn	printf("Tracing... Hit Ctrl-C to end.\n");
40235368Sgnn	scriptstart = walltimestamp;
41235368Sgnn	timestart = timestamp;
42235368Sgnn}
43235368Sgnn
44235368Sgnnio:nfs::start
45235368Sgnn{
46235368Sgnn	/* tally file sizes */
47235368Sgnn	@file[args[2]->fi_pathname] = sum(args[0]->b_bcount);
48235368Sgnn
49235368Sgnn	/* time response */
50235368Sgnn	start[args[0]->b_addr] = timestamp;
51235368Sgnn
52235368Sgnn	/* overall stats */
53235368Sgnn	@rbytes = sum(args[0]->b_flags & B_READ ? args[0]->b_bcount : 0);
54235368Sgnn	@wbytes = sum(args[0]->b_flags & B_READ ? 0 : args[0]->b_bcount);
55235368Sgnn	@events = count();
56235368Sgnn}
57235368Sgnn
58235368Sgnnio:nfs::done
59235368Sgnn/start[args[0]->b_addr]/
60235368Sgnn{
61235368Sgnn	/* calculate and save response time stats */
62235368Sgnn	this->elapsed = timestamp - start[args[0]->b_addr];
63235368Sgnn	@maxtime = max(this->elapsed);
64235368Sgnn	@avgtime = avg(this->elapsed);
65235368Sgnn	@qnztime = quantize(this->elapsed / 1000);
66235368Sgnn}
67235368Sgnn
68235368Sgnndtrace:::END
69235368Sgnn{
70235368Sgnn	/* print header */
71235368Sgnn	printf("NFS Client Wizard. %Y -> %Y\n\n", scriptstart, walltimestamp);
72235368Sgnn
73235368Sgnn	/* print read/write stats */
74235368Sgnn	printa("Read:  %@d bytes ", @rbytes);
75235368Sgnn	normalize(@rbytes, 1000000);
76235368Sgnn	printa("(%@d Mb)\n", @rbytes);
77235368Sgnn	printa("Write: %@d bytes ", @wbytes);
78235368Sgnn	normalize(@wbytes, 1000000);
79235368Sgnn	printa("(%@d Mb)\n\n", @wbytes);
80235368Sgnn
81235368Sgnn	/* print throughput stats */
82235368Sgnn	denormalize(@rbytes);
83235368Sgnn	normalize(@rbytes, (timestamp - timestart) / 1000000);
84235368Sgnn	printa("Read:  %@d Kb/sec\n", @rbytes);
85235368Sgnn	denormalize(@wbytes);
86235368Sgnn	normalize(@wbytes, (timestamp - timestart) / 1000000);
87235368Sgnn	printa("Write: %@d Kb/sec\n\n", @wbytes);
88235368Sgnn
89235368Sgnn	/* print time stats */
90235368Sgnn	printa("NFS I/O events:    %@d\n", @events);
91235368Sgnn	normalize(@avgtime, 1000000);
92235368Sgnn	printa("Avg response time: %@d ms\n", @avgtime);
93235368Sgnn	normalize(@maxtime, 1000000);
94235368Sgnn	printa("Max response time: %@d ms\n\n", @maxtime);
95235368Sgnn	printa("Response times (us):%@d\n", @qnztime);
96235368Sgnn
97235368Sgnn	/* print file stats */
98235368Sgnn	printf("Top 25 files accessed (bytes):\n");
99235368Sgnn	printf("   %-64s %s\n", "PATHNAME", "BYTES");
100235368Sgnn	trunc(@file, 25);
101235368Sgnn	printa("   %-64s %@d\n", @file);
102235368Sgnn}
103