xref: /freebsd/usr.bin/nfsstat/nfsstat.c (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
1 /*
2  * Copyright (c) 1983, 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 /*-
33  * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp.
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions, and the following disclaimer,
41  *    without modification.
42  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
43  *    substantially similar to the "NO WARRANTY" disclaimer below
44  *    ("Disclaimer") and any redistribution must be conditioned upon
45  *    including a substantially similar Disclaimer requirement for further
46  *    binary redistribution.
47  *
48  * NO WARRANTY
49  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
52  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
57  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
58  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59  * POSSIBILITY OF SUCH DAMAGES.
60  */
61 
62 
63 #ifndef lint
64 static const char copyright[] =
65 "@(#) Copyright (c) 1983, 1989, 1993\n\
66 	The Regents of the University of California.  All rights reserved.\n";
67 #endif /* not lint */
68 
69 #ifndef lint
70 #if 0
71 static char sccsid[] = "@(#)nfsstat.c	8.2 (Berkeley) 3/31/95";
72 #endif
73 static const char rcsid[] =
74   "$FreeBSD$";
75 #endif /* not lint */
76 
77 #include <sys/param.h>
78 #include <sys/module.h>
79 #include <sys/mount.h>
80 #include <sys/time.h>
81 #include <sys/sysctl.h>
82 #include <nfs/nfssvc.h>
83 
84 #include <fs/nfs/nfsproto.h>
85 #include <fs/nfs/nfsport.h>
86 
87 #include <signal.h>
88 #include <fcntl.h>
89 #include <ctype.h>
90 #include <errno.h>
91 #include <limits.h>
92 #include <nlist.h>
93 #include <unistd.h>
94 #include <stdio.h>
95 #include <stdint.h>
96 #include <stdlib.h>
97 #include <string.h>
98 #include <paths.h>
99 #include <devstat.h>
100 #include <err.h>
101 
102 #include <libxo/xo.h>
103 
104 static int widemode = 0;
105 static int zflag = 0;
106 static int printtitle = 1;
107 static struct nfsstatsv1 ext_nfsstats;
108 static int extra_output = 0;
109 
110 static void intpr(int, int);
111 static void printhdr(int, int, int);
112 static void usage(void);
113 static char *sperc1(int, int);
114 static char *sperc2(int, int);
115 static void exp_intpr(int, int, int);
116 static void exp_sidewaysintpr(u_int, int, int, int);
117 static void compute_new_stats(struct nfsstatsv1 *cur_stats,
118     struct nfsstatsv1 *prev_stats, int curop, long double etime,
119     long double *mbsec, long double *kb_per_transfer,
120     long double *transfers_per_second, long double *ms_per_transfer,
121     uint64_t *queue_len, long double *busy_pct);
122 
123 #define DELTA(field)	(nfsstats.field - lastst.field)
124 
125 #define	STAT_TYPE_READ		0
126 #define	STAT_TYPE_WRITE		1
127 #define	STAT_TYPE_COMMIT	2
128 #define	NUM_STAT_TYPES		3
129 
130 struct stattypes {
131 	int stat_type;
132 	int nfs_type;
133 };
134 static struct stattypes statstruct[] = {
135 	{STAT_TYPE_READ, NFSV4OP_READ},
136 	{STAT_TYPE_WRITE, NFSV4OP_WRITE},
137 	{STAT_TYPE_COMMIT, NFSV4OP_COMMIT}
138 };
139 
140 #define	STAT_TYPE_TO_NFS(stat_type)	statstruct[stat_type].nfs_type
141 
142 #define	NFSSTAT_XO_VERSION	"1"
143 
144 int
145 main(int argc, char **argv)
146 {
147 	u_int interval;
148 	int clientOnly = -1;
149 	int serverOnly = -1;
150 	int newStats = 0;
151 	int ch;
152 	int mntlen, i;
153 	char buf[1024];
154 	struct statfs *mntbuf;
155 	struct nfscl_dumpmntopts dumpmntopts;
156 
157 	interval = 0;
158 
159 	argc = xo_parse_args(argc, argv);
160 	if (argc < 0)
161 		exit(1);
162 
163 	xo_set_version(NFSSTAT_XO_VERSION);
164 
165 	while ((ch = getopt(argc, argv, "cdEesWM:mN:w:zq")) != -1)
166 		switch(ch) {
167 		case 'M':
168 			printf("*** -M option deprecated, ignored\n\n");
169 			break;
170 		case 'm':
171 			/* Display mount options for NFS mount points. */
172 			mntlen = getmntinfo(&mntbuf, MNT_NOWAIT);
173 			for (i = 0; i < mntlen; i++) {
174 				if (strcmp(mntbuf->f_fstypename, "nfs") == 0) {
175 					dumpmntopts.ndmnt_fname =
176 					    mntbuf->f_mntonname;
177 					dumpmntopts.ndmnt_buf = buf;
178 					dumpmntopts.ndmnt_blen = sizeof(buf);
179 					if (nfssvc(NFSSVC_DUMPMNTOPTS,
180 					    &dumpmntopts) >= 0)
181 						printf("%s on %s\n%s\n",
182 						    mntbuf->f_mntfromname,
183 						    mntbuf->f_mntonname, buf);
184 					else if (errno == EPERM)
185 						errx(1, "Only priviledged users"
186 						    " can use the -m option");
187 				}
188 				mntbuf++;
189 			}
190 			exit(0);
191 		case 'N':
192 			printf("*** -N option deprecated, ignored\n\n");
193 			break;
194 		case 'W':
195 			widemode = 1;
196 			break;
197 		case 'w':
198 			interval = atoi(optarg);
199 			break;
200 		case 'c':
201 			clientOnly = 1;
202 			if (serverOnly < 0)
203 				serverOnly = 0;
204 			break;
205 		case 'd':
206 			newStats = 1;
207 			if (interval == 0)
208 				interval = 1;
209 			break;
210 		case 's':
211 			serverOnly = 1;
212 			if (clientOnly < 0)
213 				clientOnly = 0;
214 			break;
215 		case 'z':
216 			zflag = 1;
217 			break;
218 		case 'E':
219 			if (extra_output != 0)
220 				xo_err(1, "-e and -E are mutually exclusive");
221 			extra_output = 2;
222 			break;
223 		case 'e':
224 			if (extra_output != 0)
225 				xo_err(1, "-e and -E are mutually exclusive");
226 			extra_output = 1;
227 			break;
228 		case 'q':
229 			printtitle = 0;
230 			break;
231 		case '?':
232 		default:
233 			usage();
234 		}
235 	argc -= optind;
236 	argv += optind;
237 
238 #define	BACKWARD_COMPATIBILITY
239 #ifdef	BACKWARD_COMPATIBILITY
240 	if (*argv)
241 		interval = atoi(*argv);
242 #endif
243 	if (modfind("nfscommon") < 0)
244 		xo_err(1, "NFS client/server not loaded");
245 
246 	if (interval) {
247 		exp_sidewaysintpr(interval, clientOnly, serverOnly,
248 		    newStats);
249 	} else {
250 		xo_open_container("nfsstat");
251 		if (extra_output != 0)
252 			exp_intpr(clientOnly, serverOnly, extra_output - 1);
253 		else
254 			intpr(clientOnly, serverOnly);
255 		xo_close_container("nfsstat");
256 	}
257 
258 	xo_finish();
259 	exit(0);
260 }
261 
262 /*
263  * Print a description of the nfs stats.
264  */
265 static void
266 intpr(int clientOnly, int serverOnly)
267 {
268 	int nfssvc_flag;
269 
270 	nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT;
271 	if (zflag != 0) {
272 		if (clientOnly != 0)
273 			nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
274 		if (serverOnly != 0)
275 			nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
276 	}
277 	ext_nfsstats.vers = NFSSTATS_V1;
278 	if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
279 		xo_err(1, "Can't get stats");
280 	if (clientOnly) {
281 		xo_open_container("clientstats");
282 
283 		if (printtitle)
284 			xo_emit("{T:Client Info:\n");
285 
286 		xo_open_container("operations");
287 		xo_emit("{T:Rpc Counts:}\n");
288 
289 		xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
290 		    "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
291 		    "{T:Read/%13.13s}{T:Write/%13.13s}"
292 		  "{T:Create/%13.13s}{T:Remove/%13.13s}\n");
293 		xo_emit("{:getattr/%13ju}{:setattr/%13ju}"
294 		    "{:lookup/%13ju}{:readlink/%13ju}"
295 		    "{:read/%13ju}{:write/%13ju}"
296 		    "{:create/%13ju}{:remove/%13ju}\n",
297 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR],
298 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR],
299 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
300 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK],
301 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ],
302 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE],
303 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE],
304 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
305 
306 		xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}"
307 		    "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}"
308 		    "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
309 		  "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n");
310 		xo_emit("{:rename/%13ju}{:link/%13ju}"
311 		    "{:symlink/%13ju}{:mkdir/%13ju}"
312 		    "{:rmdir/%13ju}{:readdir/%13ju}"
313 		    "{:rdirplus/%13ju}{:access/%13ju}\n",
314 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME],
315 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK],
316 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
317 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR],
318 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR],
319 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR],
320 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
321 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
322 
323 		xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}"
324 		    "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}"
325 		    "{T:Commit/%13.13s}\n");
326 		xo_emit("{:mknod/%13ju}{:fsstat/%13ju}"
327 		    "{:fsinfo/%13ju}{:pathconf/%13ju}"
328 		    "{:commit/%13ju}\n",
329 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD],
330 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
331 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO],
332 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
333 			(uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
334 
335 		xo_close_container("operations");
336 
337 		xo_open_container("rpcs");
338 		xo_emit("{T:Rpc Info:}\n");
339 
340 		xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}"
341 		    "{T:X Replies/%13.13s}{T:Retries/%13.13s}"
342 		    "{T:Requests/%13.13s}\n");
343 		xo_emit("{:timedout/%13ju}{:invalid/%13ju}"
344 		    "{:xreplies/%13ju}{:retries/%13ju}"
345 		    "{:requests/%13ju}\n",
346 			(uintmax_t)ext_nfsstats.rpctimeouts,
347 			(uintmax_t)ext_nfsstats.rpcinvalid,
348 			(uintmax_t)ext_nfsstats.rpcunexpected,
349 			(uintmax_t)ext_nfsstats.rpcretries,
350 			(uintmax_t)ext_nfsstats.rpcrequests);
351 		xo_close_container("rpcs");
352 
353 		xo_open_container("cache");
354 		xo_emit("{T:Cache Info:}\n");
355 
356 		xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}"
357 		    "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}"
358 		    "{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}"
359 		    "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n");
360 		xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}"
361 		    "{:lkuphits/%13ju}{:lkupmisses/%13ju}"
362 		    "{:biorhits/%13ju}{:biormisses/%13ju}"
363 		    "{:biowhits/%13ju}{:biowmisses/%13ju}\n",
364 		    (uintmax_t)ext_nfsstats.attrcache_hits,
365 		    (uintmax_t)ext_nfsstats.attrcache_misses,
366 		    (uintmax_t)ext_nfsstats.lookupcache_hits,
367 		    (uintmax_t)ext_nfsstats.lookupcache_misses,
368 		    (uintmax_t)(ext_nfsstats.biocache_reads -
369 		    ext_nfsstats.read_bios),
370 		    (uintmax_t)ext_nfsstats.read_bios,
371 		    (uintmax_t)(ext_nfsstats.biocache_writes -
372 		    ext_nfsstats.write_bios),
373 		    (uintmax_t)ext_nfsstats.write_bios);
374 
375 		xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}"
376 		    "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}"
377 		    "{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}"
378 		    "{T:Accs Hits/%13.13s}{T:Accs Misses/%13.13s}\n");
379 		xo_emit("{:biosrlhits/%13ju}{:biorlmisses/%13ju}"
380 		    "{:biodhits/%13ju}{:biodmisses/%13ju}"
381 		    "{:direhits/%13ju}{:diremisses/%13ju}"
382 		    "{:accshits/%13ju}{:accsmisses/%13ju}\n",
383 		    (uintmax_t)(ext_nfsstats.biocache_readlinks -
384 		    ext_nfsstats.readlink_bios),
385 		    (uintmax_t)ext_nfsstats.readlink_bios,
386 		    (uintmax_t)(ext_nfsstats.biocache_readdirs -
387 		    ext_nfsstats.readdir_bios),
388 		    (uintmax_t)ext_nfsstats.readdir_bios,
389 		    (uintmax_t)ext_nfsstats.direofcache_hits,
390 		    (uintmax_t)ext_nfsstats.direofcache_misses,
391 		    (uintmax_t)ext_nfsstats.accesscache_hits,
392 		    (uintmax_t)ext_nfsstats.accesscache_misses);
393 
394 		xo_close_container("cache");
395 
396 		xo_close_container("clientstats");
397 	}
398 	if (serverOnly) {
399 		xo_open_container("serverstats");
400 
401 		xo_emit("{T:Server Info:}\n");
402 		xo_open_container("operations");
403 
404 		xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
405 		    "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
406 		    "{T:Read/%13.13s}{T:Write/%13.13s}"
407 		    "{T:Create/%13.13s}{T:Remove/%13.13s}\n");
408 		xo_emit("{:getattr/%13ju}{:setattr/%13ju}"
409 		    "{:lookup/%13ju}{:readlink/%13ju}"
410 		    "{:read/%13ju}{:write/%13ju}"
411 		    "{:create/%13ju}{:remove/%13ju}\n",
412 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
413 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
414 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
415 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
416 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ],
417 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
418 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
419 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
420 
421 		xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}"
422 		    "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}"
423 		    "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
424 		    "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n");
425 		xo_emit("{:rename/%13ju}{:link/%13ju}"
426 		    "{:symlink/%13ju}{:mkdir/%13ju}"
427 		    "{:rmdir/%13ju}{:readdir/%13ju}"
428 		    "{:rdirplus/%13ju}{:access/%13ju}\n",
429 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
430 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
431 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
432 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
433 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
434 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
435 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
436 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
437 
438 		xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}"
439 		    "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}"
440 		    "{T:Commit/%13.13s}\n");
441 		xo_emit("{:mknod/%13ju}{:fsstat/%13ju}"
442 		    "{:fsinfo/%13ju}{:pathconf/%13ju}"
443 		    "{:commit/%13ju}\n",
444 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
445 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
446 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
447 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
448 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
449 
450 		xo_close_container("operations");
451 
452 		xo_open_container("server");
453 		xo_emit("{T:Server Re-Failed}\n");
454 		xo_emit("{:retfailed/%16ju}\n", (uintmax_t)ext_nfsstats.srvrpc_errs);
455 
456 		xo_emit("{T:Server Faults}\n");
457 		xo_emit("{:faults/%13ju}\n", (uintmax_t)ext_nfsstats.srv_errs);
458 
459 		xo_emit("{T:Server Write Gathering:/%13.13s}\n");
460 
461 		xo_emit("{T:WriteOps/%13.13s}{T:WriteRPC/%13.13s}"
462 		    "{T:Opsaved/%13.13s}\n");
463 		xo_emit("{:writeops/%13ju}{:writerpc/%13ju}"
464 		    "{:opsaved/%13ju}\n",
465 		/*
466 		 * The new client doesn't do write gathering. It was
467 		 * only useful for NFSv2.
468 		 */
469 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
470 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
471 
472 		xo_close_container("server");
473 
474 		xo_open_container("cache");
475 		xo_emit("{T:Server Cache Stats:/%13.13s}\n");
476 		xo_emit("{T:Inprog/%13.13s}{T:Idem/%13.13s}"
477 		    "{T:Non-Idem/%13.13s}{T:Misses/%13.13s}\n");
478 		xo_emit("{:inprog/%13ju}{:idem/%13ju}"
479 		    "{:nonidem/%13ju}{:misses/%13ju}\n",
480 			(uintmax_t)ext_nfsstats.srvcache_inproghits,
481 			(uintmax_t)ext_nfsstats.srvcache_idemdonehits,
482 			(uintmax_t)ext_nfsstats.srvcache_nonidemdonehits,
483 			(uintmax_t)ext_nfsstats.srvcache_misses);
484 		xo_close_container("cache");
485 
486 		xo_close_container("serverstats");
487 	}
488 }
489 
490 static void
491 printhdr(int clientOnly, int serverOnly, int newStats)
492 {
493 
494 	if (newStats) {
495 		printf(" [%s Read %s]  [%s Write %s]  "
496 		    "%s[=========== Total ============]\n"
497 		    " KB/t   tps    MB/s%s  KB/t   tps    MB/s%s  "
498 		    "%sKB/t   tps    MB/s    ms  ql  %%b",
499 		    widemode ? "========" : "=====",
500 		    widemode ? "========" : "=====",
501 		    widemode ? "========" : "=====",
502 		    widemode ? "======="  : "====",
503 		    widemode ? "[Commit ]  " : "",
504 		    widemode ? "    ms" : "",
505 		    widemode ? "    ms" : "",
506 		    widemode ? "tps    ms  " : "");
507 	} else {
508 		printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
509 		    ((serverOnly && clientOnly) ? "        " : " "),
510 		    "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename",
511 		    "Access", "Rddir");
512 		if (widemode && clientOnly) {
513 			printf(" Attr Lkup BioR BioW Accs BioD");
514 		}
515 	}
516 	printf("\n");
517 	fflush(stdout);
518 }
519 
520 static void
521 usage(void)
522 {
523 	(void)fprintf(stderr,
524 	    "usage: nfsstat [-cdemszW] [-w wait]\n");
525 	exit(1);
526 }
527 
528 static char SPBuf[64][8];
529 static int SPIndex;
530 
531 static char *
532 sperc1(int hits, int misses)
533 {
534 	char *p = SPBuf[SPIndex];
535 
536 	if (hits + misses) {
537 		sprintf(p, "%3d%%",
538 		    (int)(char)((quad_t)hits * 100 / (hits + misses)));
539 	} else {
540 		sprintf(p, "   -");
541 	}
542 	SPIndex = (SPIndex + 1) & 63;
543 	return(p);
544 }
545 
546 static char *
547 sperc2(int ttl, int misses)
548 {
549 	char *p = SPBuf[SPIndex];
550 
551 	if (ttl) {
552 		sprintf(p, "%3d%%",
553 		    (int)(char)((quad_t)(ttl - misses) * 100 / ttl));
554 	} else {
555 		sprintf(p, "   -");
556 	}
557 	SPIndex = (SPIndex + 1) & 63;
558 	return(p);
559 }
560 
561 #define DELTA_T(field)					\
562 	devstat_compute_etime(&cur_stats->field,	\
563 	(prev_stats ? &prev_stats->field : NULL))
564 
565 /*
566  * XXX KDM mostly copied from ctlstat.  We should commonize the code (and
567  * the devstat code) somehow.
568  */
569 static void
570 compute_new_stats(struct nfsstatsv1 *cur_stats,
571 		  struct nfsstatsv1 *prev_stats, int curop,
572 		  long double etime, long double *mbsec,
573 		  long double *kb_per_transfer,
574 		  long double *transfers_per_second,
575 		  long double *ms_per_transfer, uint64_t *queue_len,
576 		  long double *busy_pct)
577 {
578 	uint64_t total_bytes = 0, total_operations = 0;
579 	struct bintime total_time_bt;
580 	struct timespec total_time_ts;
581 
582 	bzero(&total_time_bt, sizeof(total_time_bt));
583 	bzero(&total_time_ts, sizeof(total_time_ts));
584 
585 	total_bytes = cur_stats->srvbytes[curop];
586 	total_operations = cur_stats->srvops[curop];
587 	if (prev_stats != NULL) {
588 		total_bytes -= prev_stats->srvbytes[curop];
589 		total_operations -= prev_stats->srvops[curop];
590 	}
591 
592 	*mbsec = total_bytes;
593 	*mbsec /= 1024 * 1024;
594 	if (etime > 0.0) {
595 		*busy_pct = DELTA_T(busytime);
596 		if (*busy_pct < 0)
597 			*busy_pct = 0;
598 		*busy_pct /= etime;
599 		*busy_pct *= 100;
600 		if (*busy_pct < 0)
601 			*busy_pct = 0;
602 		*mbsec /= etime;
603 	} else {
604 		*busy_pct = 0;
605 		*mbsec = 0;
606 	}
607 	*kb_per_transfer = total_bytes;
608 	*kb_per_transfer /= 1024;
609 	if (total_operations > 0)
610 		*kb_per_transfer /= total_operations;
611 	else
612 		*kb_per_transfer = 0;
613 	if (etime > 0.0) {
614 		*transfers_per_second = total_operations;
615 		*transfers_per_second /= etime;
616 	} else {
617 		*transfers_per_second = 0.0;
618 	}
619 
620 	if (total_operations > 0) {
621 		*ms_per_transfer = DELTA_T(srvduration[curop]);
622 		*ms_per_transfer /= total_operations;
623 		*ms_per_transfer *= 1000;
624 	} else
625 		*ms_per_transfer = 0.0;
626 
627 	*queue_len = cur_stats->srvstartcnt - cur_stats->srvdonecnt;
628 }
629 
630 /*
631  * Print a description of the nfs stats for the client/server,
632  * including NFSv4.1.
633  */
634 static void
635 exp_intpr(int clientOnly, int serverOnly, int nfs41)
636 {
637 	int nfssvc_flag;
638 
639 	xo_open_container("nfsv4");
640 
641 	nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT;
642 	if (zflag != 0) {
643 		if (clientOnly != 0)
644 			nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
645 		if (serverOnly != 0)
646 			nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
647 	}
648 	ext_nfsstats.vers = NFSSTATS_V1;
649 	if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
650 		xo_err(1, "Can't get stats");
651 	if (clientOnly != 0) {
652 		xo_open_container("clientstats");
653 
654 		xo_open_container("operations");
655 		if (printtitle) {
656 			xo_emit("{T:Client Info:}\n");
657 			xo_emit("{T:RPC Counts:}\n");
658 		}
659 		xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
660 		    "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
661 		    "{T:Read/%13.13s}{T:Write/%13.13s}\n");
662 		xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}"
663 		    "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n",
664 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR],
665 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR],
666 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
667 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK],
668 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ],
669 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE]);
670 		xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}"
671 		    "{T:Rename/%13.13s}{T:Link/%13.13s}"
672 		    "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n");
673 		xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}"
674 		  "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n",
675 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE],
676 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE],
677 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME],
678 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK],
679 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
680 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR]);
681 		xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
682 		    "{T:RdirPlus/%13.13s}{T:Access/%13.13s}"
683 		    "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n");
684 		xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}"
685 		    "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n",
686 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR],
687 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR],
688 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
689 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS],
690 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD],
691 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT]);
692 		xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}"
693 		    "{T:Commit/%13.13s}{T:SetClId/%13.13s}"
694 		    "{T:SetClIdCf/%13.13s}{T:Lock/%13.13s}\n");
695 		xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}"
696 		    "{:setclientid/%13ju}{:setclientidcf/%13ju}{:lock/%13ju}\n",
697 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO],
698 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
699 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT],
700 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID],
701 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM],
702 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCK]);
703 		xo_emit("{T:LockT/%13.13s}{T:LockU/%13.13s}"
704 		    "{T:Open/%13.13s}{T:OpenCfr/%13.13s}\n");
705 		xo_emit("{:lockt/%13ju}{:locku/%13ju}"
706 		    "{:open/%13ju}{:opencfr/%13ju}\n",
707 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKT],
708 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKU],
709 		    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPEN],
710 		  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]);
711 
712 		if (nfs41) {
713 			xo_open_container("nfsv41");
714 
715 			xo_emit("{T:OpenDownGr/%13.13s}{T:Close/%13.13s}\n");
716 			xo_emit("{:opendowngr/%13ju}{:close/%13ju}\n",
717 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENDOWNGRADE],
718 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CLOSE]);
719 
720 			xo_emit("{T:RelLckOwn/%13.13s}{T:FreeStateID/%13.13s}"
721 			    "{T:PutRootFH/%13.13s}{T:DelegRet/%13.13s}"
722 			    "{T:GetAcl/%13.13s}{T:SetAcl/%13.13s}\n");
723 			xo_emit("{:rellckown/%13ju}{:freestateid/%13ju}"
724 			    "{:getacl/%13ju}{:delegret/%13ju}"
725 			    "{:getacl/%13ju}{:setacl/%13ju}\n",
726 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RELEASELCKOWN],
727 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FREESTATEID],
728 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PUTROOTFH],
729 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DELEGRETURN],
730 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETACL],
731 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETACL]);
732 
733 			xo_emit("{T:ExchangeId/%13.13s}{T:CreateSess/%13.13s}"
734 			    "{T:DestroySess/%13.13s}{T:DestroyClId/%13.13s}"
735 			    "{T:LayoutGet/%13.13s}{T:GetDevInfo/%13.13s}\n");
736 			xo_emit("{:exchangeid/%13ju}{:createsess/%13ju}"
737 			    "{:destroysess/%13ju}{:destroyclid/%13ju}"
738 			    "{:layoutget/%13ju}{:getdevinfo/%13ju}\n",
739 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_EXCHANGEID],
740 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATESESSION],
741 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYSESSION],
742 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYCLIENT],
743 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTGET],
744 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETDEVICEINFO]);
745 
746 			xo_emit("{T:LayoutCommit/%13.13s}{T:LayoutReturn/%13.13s}"
747 			    "{T:ReclaimCompl/%13.13s}{T:ReadDataS/%13.13s}"
748 			    "{T:WriteDataS/%13.13s}{T:CommitDataS/%13.13s}\n");
749 			xo_emit("{:layoutcomit/%13ju}{:layoutreturn/%13ju}"
750 			    "{:reclaimcompl/%13ju}{:readdatas/%13ju}"
751 			    "{:writedatas/%13ju}{:commitdatas/%13ju}\n",
752 			  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTCOMMIT],
753 			  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTRETURN],
754 			  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RECLAIMCOMPL],
755 			  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDS],
756 			  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITEDS],
757 			  (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMITDS]);
758 
759 			xo_emit("{T:OpenLayout/%13.13s}{T:CreateLayout/%13.13s}\n");
760 			xo_emit("{:openlayout/%13ju}{:createlayout/%13ju}\n",
761 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENLAYGET],
762 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATELAYGET]);
763 
764 			xo_close_container("nfsv41");
765 
766 			xo_open_container("nfsv42");
767 
768 			xo_emit("{T:IOAdvise/%13.13s}{T:Allocate/%13.13s}"
769 			    "{T:Copy/%13.13s}{T:Seek/%13.13s}"
770 			    "{T:SeekDataS/%13.13s}{T:GetExtattr/%13.13s}\n");
771 			xo_emit("{:ioadvise/%13ju}{:allocate/%13ju}"
772 			    "{:copy/%13ju}{:seek/%13ju}"
773 			    "{:seekdatas/%13ju}{:getextattr/%13ju}\n",
774 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_IOADVISE],
775 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ALLOCATE],
776 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COPY],
777 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEK],
778 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SEEKDS],
779 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETEXTATTR]);
780 
781 			xo_emit("{T:SetExtattr/%13.13s}{T:RmExtattr/%13.13s}"
782 			    "{T:ListExtattr/%13.13s}\n");
783 			xo_emit("{:setextattr/%13ju}{:rmextattr/%13ju}"
784 			    "{:listextattr/%13ju}\n",
785 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETEXTATTR],
786 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMEXTATTR],
787 			    (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LISTEXTATTR]);
788 
789 			xo_close_container("nfsv42");
790 		}
791 		xo_close_container("operations");
792 
793 		xo_open_container("client");
794 		xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}"
795 		    "{T:LockOwner/%13.13s}{T:Locks/%13.13s}"
796 		    "{T:Delegs/%13.13s}{T:LocalOwn/%13.13s}\n");
797 		xo_emit("{:openowner/%13ju}{:opens/%13ju}"
798 		    "{:lockowner/%13ju}{:locks/%13ju}"
799 		    "{:delegs/%13ju}{:localown/%13ju}\n",
800 		    (uintmax_t)ext_nfsstats.clopenowners,
801 		    (uintmax_t)ext_nfsstats.clopens,
802 		    (uintmax_t)ext_nfsstats.cllockowners,
803 		    (uintmax_t)ext_nfsstats.cllocks,
804 		    (uintmax_t)ext_nfsstats.cldelegates,
805 		    (uintmax_t)ext_nfsstats.cllocalopenowners);
806 
807 		xo_emit("{T:LocalOpen/%13.13s}{T:LocalLown/%13.13s}"
808 		    "{T:LocalLock/%13.13s}\n");
809 		xo_emit("{:localopen/%13ju}{:locallown/%13ju}"
810 		    "{:locallock/%13ju}\n",
811 		    (uintmax_t)ext_nfsstats.cllocalopens,
812 		    (uintmax_t)ext_nfsstats.cllocallockowners,
813 		    (uintmax_t)ext_nfsstats.cllocallocks);
814 		xo_close_container("client");
815 
816 		xo_open_container("rpc");
817 		if (printtitle)
818 			xo_emit("{T:Rpc Info:}\n");
819 		xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}"
820 		    "{T:X Replies/%13.13s}{T:Retries/%13.13s}"
821 		    "{T:Requests/%13.13s}\n");
822 		xo_emit("{:timedout/%13ju}{:invalid/%13ju}"
823 		    "{:xreplies/%13ju}{:retries/%13ju}"
824 		    "{:requests/%13ju}\n",
825 		    (uintmax_t)ext_nfsstats.rpctimeouts,
826 		    (uintmax_t)ext_nfsstats.rpcinvalid,
827 		    (uintmax_t)ext_nfsstats.rpcunexpected,
828 		    (uintmax_t)ext_nfsstats.rpcretries,
829 		    (uintmax_t)ext_nfsstats.rpcrequests);
830 		xo_close_container("rpc");
831 
832 		xo_open_container("cache");
833 		if (printtitle)
834 			xo_emit("{T:Cache Info:}\n");
835 		xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}"
836 		    "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}\n");
837 		xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}"
838 		    "{:lkuphits/%13ju}{:lkupmisses/%13ju}\n",
839 		    (uintmax_t)ext_nfsstats.attrcache_hits,
840 		    (uintmax_t)ext_nfsstats.attrcache_misses,
841 		    (uintmax_t)ext_nfsstats.lookupcache_hits,
842 		    (uintmax_t)ext_nfsstats.lookupcache_misses);
843 
844 		xo_emit("{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}"
845 		    "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n");
846 		xo_emit("{:biorhits/%13ju}{:biormisses/%13ju}"
847 		    "{:biowhits/%13ju}{:biowmisses/%13ju}\n",
848 		    (uintmax_t)(ext_nfsstats.biocache_reads -
849 		    ext_nfsstats.read_bios),
850 		    (uintmax_t)ext_nfsstats.read_bios,
851 		    (uintmax_t)(ext_nfsstats.biocache_writes -
852 		    ext_nfsstats.write_bios),
853 		    (uintmax_t)ext_nfsstats.write_bios);
854 
855 		xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}"
856 		    "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}\n");
857 		xo_emit("{:biorlhits/%13ju}{:biorlmisses/%13ju}"
858 		    "{:biodhits/%13ju}{:biodmisses/%13ju}\n",
859 		    (uintmax_t)(ext_nfsstats.biocache_readlinks -
860 		    ext_nfsstats.readlink_bios),
861 		    (uintmax_t)ext_nfsstats.readlink_bios,
862 		    (uintmax_t)(ext_nfsstats.biocache_readdirs -
863 		    ext_nfsstats.readdir_bios),
864 		    (uintmax_t)ext_nfsstats.readdir_bios);
865 
866 		xo_emit("{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}\n");
867 		xo_emit("{:direhits/%13ju}{:diremisses/%13ju}\n",
868 		    (uintmax_t)ext_nfsstats.direofcache_hits,
869 		    (uintmax_t)ext_nfsstats.direofcache_misses);
870 		xo_open_container("cache");
871 
872 		xo_close_container("clientstats");
873 	}
874 	if (serverOnly != 0) {
875 		xo_open_container("serverstats");
876 
877 		xo_open_container("operations");
878 		if (printtitle)
879 			xo_emit("{T:Server Info:}\n");
880 		xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}"
881 		    "{T:Lookup/%13.13s}{T:Readlink/%13.13s}"
882 		    "{T:Read/%13.13s}{T:Write/%13.13s}\n");
883 		xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}"
884 		    "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n",
885 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
886 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
887 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
888 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
889 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ],
890 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE]);
891 		xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}"
892 		    "{T:Rename/%13.13s}{T:Link/%13.13s}"
893 		    "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n");
894 		xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}"
895 		    "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n",
896 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE],
897 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE],
898 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
899 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
900 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
901 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR]);
902 		xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}"
903 		    "{T:RdirPlus/%13.13s}{T:Access/%13.13s}"
904 		    "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n");
905 		xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}"
906 		    "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n",
907 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
908 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
909 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
910 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS],
911 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
912 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT]);
913 		xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}"
914 		    "{T:Commit/%13.13s}{T:LookupP/%13.13s}"
915 		    "{T:SetClId/%13.13s}{T:SetClIdCf/%13.13s}\n");
916 		xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}"
917 		    "{:lookupp/%13ju}{:setclientid/%13ju}{:setclientidcfrm/%13ju}\n",
918 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
919 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
920 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT],
921 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP],
922 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID],
923 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]);
924 		xo_emit("{T:Open/%13.13s}{T:OpenAttr/%13.13s}"
925 		    "{T:OpenDwnGr/%13.13s}{T:OpenCfrm/%13.13s}"
926 		    "{T:DelePurge/%13.13s}{T:DelRet/%13.13s}\n");
927 		xo_emit("{:open/%13ju}{:openattr/%13ju}{:opendwgr/%13ju}"
928 		    "{:opencfrm/%13ju}{:delepurge/%13ju}{:delreg/%13ju}\n",
929 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPEN],
930 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR],
931 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE],
932 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM],
933 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE],
934 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN]);
935 		xo_emit("{T:GetFH/%13.13s}{T:Lock/%13.13s}"
936 		    "{T:LockT/%13.13s}{T:LockU/%13.13s}"
937 		    "{T:Close/%13.13s}{T:Verify/%13.13s}\n");
938 		xo_emit("{:getfh/%13ju}{:lock/%13ju}{:lockt/%13ju}"
939 		    "{:locku/%13ju}{:close/%13ju}{:verify/%13ju}\n",
940 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETFH],
941 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCK],
942 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT],
943 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU],
944 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE],
945 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY]);
946 		xo_emit("{T:NVerify/%13.13s}{T:PutFH/%13.13s}"
947 		    "{T:PutPubFH/%13.13s}{T:PutRootFH/%13.13s}"
948 		    "{T:Renew/%13.13s}{T:RestoreFH/%13.13s}\n");
949 		xo_emit("{:nverify/%13ju}{:putfh/%13ju}{:putpubfh/%13ju}"
950 		    "{:putrootfh/%13ju}{:renew/%13ju}{:restore/%13ju}\n",
951 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY],
952 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH],
953 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH],
954 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH],
955 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENEW],
956 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH]);
957 		xo_emit("{T:SaveFH/%13.13s}{T:Secinfo/%13.13s}"
958 		    "{T:RelLockOwn/%13.13s}{T:V4Create/%13.13s}\n");
959 		xo_emit("{:savefh/%13ju}{:secinfo/%13ju}{:rellockown/%13ju}"
960 		    "{:v4create/%13ju}\n",
961 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH],
962 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO],
963 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN],
964 		    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]);
965 		if (nfs41) {
966 			xo_open_container("nfsv41");
967 			xo_emit("{T:BackChannelCtrl/%13.13s}{T:BindConnToSess/%13.13s}"
968 			    "{T:ExchangeID/%13.13s}{T:CreateSess/%13.13s}"
969 			    "{T:DestroySess/%13.13s}{T:FreeStateID/%13.13s}\n");
970 			xo_emit("{:backchannelctrl/%13ju}{:bindconntosess/%13ju}"
971 			    "{:exchangeid/%13ju}{:createsess/%13ju}"
972 			    "{:destroysess/%13ju}{:freestateid/%13ju}\n",
973 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BACKCHANNELCTL],
974 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BINDCONNTOSESS],
975 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_EXCHANGEID],
976 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATESESSION],
977 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYSESSION],
978 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FREESTATEID]),
979 
980 			xo_emit("{T:GetDirDeleg/%13.13s}{T:GetDevInfo/%13.13s}"
981 			    "{T:GetDevList/%13.13s}{T:layoutCommit/%13.13s}"
982 			    "{T:LayoutGet/%13.13s}{T:LayoutReturn/%13.13s}\n");
983 			xo_emit("{:getdirdeleg/%13ju}{:getdevinfo/%13ju}"
984 			    "{:getdevlist/%13ju}{:layoutcommit/%13ju}"
985 			    "{:layoutget/%13ju}{:layoutreturn/%13ju}\n",
986 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDIRDELEG],
987 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVINFO],
988 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVLIST],
989 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTCOMMIT],
990 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTGET],
991 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTRETURN]);
992 
993 			xo_emit("{T:SecInfNoName/%13.13s}{T:Sequence/%13.13s}"
994 			    "{T:SetSSV/%13.13s}{T:TestStateID/%13.13s}"
995 			    "{T:WantDeleg/%13.13s}{T:DestroyClId/%13.13s}\n");
996 			xo_emit("{:secinfnoname/%13ju}{:sequence/%13ju}"
997 			    "{:setssv/%13ju}{:teststateid/%13ju}{:wantdeleg/%13ju}"
998 			    "{:destroyclid/%13ju}\n",
999 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFONONAME],
1000 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEQUENCE],
1001 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETSSV],
1002 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_TESTSTATEID],
1003 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WANTDELEG],
1004 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYCLIENTID]);
1005 
1006 			xo_emit("{T:ReclaimCompl/%13.13s}\n");
1007 			xo_emit("{:reclaimcompl/%13ju}\n",
1008 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RECLAIMCOMPL]);
1009 
1010 			xo_close_container("nfsv41");
1011 
1012 			xo_open_container("nfsv42");
1013 
1014 			xo_emit("{T:Allocate/%13.13s}{T:Copy/%13.13s}"
1015 			    "{T:CopyNotify/%13.13s}{T:Deallocate/%13.13s}"
1016 			    "{T:IOAdvise/%13.13s}{T:LayoutError/%13.13s}\n");
1017 			xo_emit("{:allocate/%13ju}{:copy/%13ju}"
1018 			    "{:copynotify/%13ju}{:deallocate/%13ju}"
1019 			    "{:ioadvise/%13ju}{:layouterror/%13ju}\n",
1020 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ALLOCATE],
1021 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPY],
1022 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COPYNOTIFY],
1023 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DEALLOCATE],
1024 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_IOADVISE],
1025 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTERROR]);
1026 
1027 			xo_emit("{T:LayoutStats/%13.13s}{T:OffloadCncl/%13.13s}"
1028 			    "{T:OffloadStat/%13.13s}{T:ReadPlus/%13.13s}"
1029 			    "{T:Seek/%13.13s}{T:WriteSame/%13.13s}\n");
1030 			xo_emit("{:layoutstats/%13ju}{:offloadcncl/%13ju}"
1031 			    "{:offloadstat/%13ju}{:readplus/%13ju}"
1032 			    "{:seek/%13ju}{:writesame/%13ju}\n",
1033 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTSTATS],
1034 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADCANCEL],
1035 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OFFLOADSTATUS],
1036 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READPLUS],
1037 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEEK],
1038 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITESAME]);
1039 
1040 			xo_emit("{T:Clone/%13.13s}{T:GetExtattr/%13.13s}"
1041 			    "{T:SetExtattr/%13.13s}{T:ListExtattr/%13.13s}"
1042 			    "{T:RmExtattr/%13.13s}\n");
1043 			xo_emit("{:clone/%13ju}{:getextattr/%13ju}"
1044 			    "{:setextattr/%13ju}{:listextattr/%13ju}"
1045 			    "{:rmextattr/%13ju}\n",
1046 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLONE],
1047 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETXATTR],
1048 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETXATTR],
1049 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LISTXATTRS],
1050 			    (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVEXATTR]);
1051 
1052 			xo_close_container("nfsv42");
1053 		}
1054 
1055 		xo_close_container("operations");
1056 
1057 		if (printtitle)
1058 			xo_emit("{T:Server:}\n");
1059 		xo_open_container("server");
1060 		xo_emit("{T:Retfailed/%13.13s}{T:Faults/%13.13s}"
1061 		    "{T:Clients/%13.13s}\n");
1062 		xo_emit("{:retfailed/%13ju}{:faults/%13ju}{:clients/%13ju}\n",
1063 		    (uintmax_t)ext_nfsstats.srv_errs,
1064 		    (uintmax_t)ext_nfsstats.srvrpc_errs,
1065 		    (uintmax_t)ext_nfsstats.srvclients);
1066 		xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}"
1067 		    "{T:LockOwner/%13.13s}{T:Locks/%13.13s}"
1068 		    "{T:Delegs/%13.13s}\n");
1069 		xo_emit("{:openowner/%13ju}{:opens/%13ju}{:lockowner/%13ju}"
1070 		  "{:locks/%13ju}{:delegs/%13ju}\n",
1071 		    (uintmax_t)ext_nfsstats.srvopenowners,
1072 		    (uintmax_t)ext_nfsstats.srvopens,
1073 		    (uintmax_t)ext_nfsstats.srvlockowners,
1074 		    (uintmax_t)ext_nfsstats.srvlocks,
1075 		    (uintmax_t)ext_nfsstats.srvdelegates);
1076 		xo_close_container("server");
1077 
1078 		if (printtitle)
1079 			xo_emit("{T:Server Cache Stats:}\n");
1080 		xo_open_container("cache");
1081 		xo_emit("{T:Inprog/%13.13s}{T:Idem/%13.13s}"
1082 		    "{T:Non-idem/%13.13s}{T:Misses/%13.13s}"
1083 		    "{T:CacheSize/%13.13s}{T:TCPPeak/%13.13s}\n");
1084 		xo_emit("{:inprog/%13ju}{:idem/%13ju}{:nonidem/%13ju}"
1085 		    "{:misses/%13ju}{:cachesize/%13ju}{:tcppeak/%13ju}\n",
1086 		    (uintmax_t)ext_nfsstats.srvcache_inproghits,
1087 		    (uintmax_t)ext_nfsstats.srvcache_idemdonehits,
1088 		    (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits,
1089 		    (uintmax_t)ext_nfsstats.srvcache_misses,
1090 		    (uintmax_t)ext_nfsstats.srvcache_size,
1091 		    (uintmax_t)ext_nfsstats.srvcache_tcppeak);
1092 		xo_close_container("cache");
1093 
1094 		xo_close_container("serverstats");
1095 	}
1096 
1097 	xo_close_container("nfsv4");
1098 }
1099 
1100 static void
1101 compute_totals(struct nfsstatsv1 *total_stats, struct nfsstatsv1 *cur_stats)
1102 {
1103 	int i;
1104 
1105 	bzero(total_stats, sizeof(*total_stats));
1106 	for (i = 0; i < (NFSV42_NOPS + NFSV4OP_FAKENOPS); i++) {
1107 		total_stats->srvbytes[0] += cur_stats->srvbytes[i];
1108 		total_stats->srvops[0] += cur_stats->srvops[i];
1109 		bintime_add(&total_stats->srvduration[0],
1110 			    &cur_stats->srvduration[i]);
1111 		total_stats->srvrpccnt[i] = cur_stats->srvrpccnt[i];
1112 	}
1113 	total_stats->srvstartcnt = cur_stats->srvstartcnt;
1114 	total_stats->srvdonecnt = cur_stats->srvdonecnt;
1115 	total_stats->busytime = cur_stats->busytime;
1116 
1117 }
1118 
1119 /*
1120  * Print a running summary of nfs statistics for the experimental client and/or
1121  * server.
1122  * Repeat display every interval seconds, showing statistics
1123  * collected over that interval.  Assumes that interval is non-zero.
1124  * First line printed at top of screen is always cumulative.
1125  */
1126 static void
1127 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly,
1128     int newStats)
1129 {
1130 	struct nfsstatsv1 nfsstats, lastst, *ext_nfsstatsp;
1131 	struct nfsstatsv1 curtotal, lasttotal;
1132 	struct timespec ts, lastts;
1133 	int hdrcnt = 1;
1134 
1135 	ext_nfsstatsp = &lastst;
1136 	ext_nfsstatsp->vers = NFSSTATS_V1;
1137 	if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp) < 0)
1138 		err(1, "Can't get stats");
1139 	clock_gettime(CLOCK_MONOTONIC, &lastts);
1140 	compute_totals(&lasttotal, ext_nfsstatsp);
1141 	sleep(interval);
1142 
1143 	for (;;) {
1144 		ext_nfsstatsp = &nfsstats;
1145 		ext_nfsstatsp->vers = NFSSTATS_V1;
1146 		if (nfssvc(NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT, ext_nfsstatsp)
1147 		    < 0)
1148 			err(1, "Can't get stats");
1149 		clock_gettime(CLOCK_MONOTONIC, &ts);
1150 
1151 		if (--hdrcnt == 0) {
1152 			printhdr(clientOnly, serverOnly, newStats);
1153 			if (newStats)
1154 				hdrcnt = 20;
1155 			else if (clientOnly && serverOnly)
1156 				hdrcnt = 10;
1157 			else
1158 				hdrcnt = 20;
1159 		}
1160 		if (clientOnly && newStats == 0) {
1161 		    printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju",
1162 			((clientOnly && serverOnly) ? "Client:" : ""),
1163 			(uintmax_t)DELTA(rpccnt[NFSPROC_GETATTR]),
1164 			(uintmax_t)DELTA(rpccnt[NFSPROC_LOOKUP]),
1165 			(uintmax_t)DELTA(rpccnt[NFSPROC_READLINK]),
1166 			(uintmax_t)DELTA(rpccnt[NFSPROC_READ]),
1167 			(uintmax_t)DELTA(rpccnt[NFSPROC_WRITE]),
1168 			(uintmax_t)DELTA(rpccnt[NFSPROC_RENAME]),
1169 			(uintmax_t)DELTA(rpccnt[NFSPROC_ACCESS]),
1170 			(uintmax_t)(DELTA(rpccnt[NFSPROC_READDIR]) +
1171 			DELTA(rpccnt[NFSPROC_READDIRPLUS]))
1172 		    );
1173 		    if (widemode) {
1174 			    printf(" %s %s %s %s %s %s",
1175 				sperc1(DELTA(attrcache_hits),
1176 				    DELTA(attrcache_misses)),
1177 				sperc1(DELTA(lookupcache_hits),
1178 				    DELTA(lookupcache_misses)),
1179 				sperc2(DELTA(biocache_reads),
1180 				    DELTA(read_bios)),
1181 				sperc2(DELTA(biocache_writes),
1182 				    DELTA(write_bios)),
1183 				sperc1(DELTA(accesscache_hits),
1184 				    DELTA(accesscache_misses)),
1185 				sperc2(DELTA(biocache_readdirs),
1186 				    DELTA(readdir_bios))
1187 			    );
1188 		    }
1189 		    printf("\n");
1190 		}
1191 
1192 		if (serverOnly && newStats) {
1193 			long double cur_secs, last_secs, etime;
1194 			long double mbsec;
1195 			long double kb_per_transfer;
1196 			long double transfers_per_second;
1197 			long double ms_per_transfer;
1198 			uint64_t queue_len;
1199 			long double busy_pct;
1200 			int i;
1201 
1202 			cur_secs = ts.tv_sec +
1203 			    ((long double)ts.tv_nsec / 1000000000);
1204 			last_secs = lastts.tv_sec +
1205 			    ((long double)lastts.tv_nsec / 1000000000);
1206 			etime = cur_secs - last_secs;
1207 
1208 			compute_totals(&curtotal, &nfsstats);
1209 
1210 			for (i = 0; i < NUM_STAT_TYPES; i++) {
1211 				compute_new_stats(&nfsstats, &lastst,
1212 				    STAT_TYPE_TO_NFS(i), etime, &mbsec,
1213 				    &kb_per_transfer,
1214 				    &transfers_per_second,
1215 				    &ms_per_transfer, &queue_len,
1216 				    &busy_pct);
1217 
1218 				if (i == STAT_TYPE_COMMIT) {
1219 					if (widemode == 0)
1220 						continue;
1221 
1222 					printf("%2.0Lf %7.2Lf ",
1223 					    transfers_per_second,
1224 					    ms_per_transfer);
1225 				} else {
1226 					printf("%5.2Lf %5.0Lf %7.2Lf ",
1227 					    kb_per_transfer,
1228 					    transfers_per_second, mbsec);
1229 					if (widemode)
1230 						printf("%5.2Lf ",
1231 						    ms_per_transfer);
1232 				}
1233 			}
1234 
1235 			compute_new_stats(&curtotal, &lasttotal, 0, etime,
1236 			    &mbsec, &kb_per_transfer, &transfers_per_second,
1237 			    &ms_per_transfer, &queue_len, &busy_pct);
1238 
1239 			printf("%5.2Lf %5.0Lf %7.2Lf %5.2Lf %3ju %3.0Lf\n",
1240 			    kb_per_transfer, transfers_per_second, mbsec,
1241 			    ms_per_transfer, queue_len, busy_pct);
1242 		} else if (serverOnly) {
1243 		    printf("%s %6ju %6ju %6ju %6ju %6ju %6ju %6ju %6ju",
1244 			((clientOnly && serverOnly) ? "Server:" : ""),
1245 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_GETATTR]),
1246 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_LOOKUP]),
1247 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_READLINK]),
1248 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_READ]),
1249 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_WRITE]),
1250 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_RENAME]),
1251 			(uintmax_t)DELTA(srvrpccnt[NFSV4OP_ACCESS]),
1252 			(uintmax_t)(DELTA(srvrpccnt[NFSV4OP_READDIR]) +
1253 			DELTA(srvrpccnt[NFSV4OP_READDIRPLUS])));
1254 		    printf("\n");
1255 		}
1256 		bcopy(&nfsstats, &lastst, sizeof(lastst));
1257 		bcopy(&curtotal, &lasttotal, sizeof(lasttotal));
1258 		lastts = ts;
1259 		fflush(stdout);
1260 		sleep(interval);
1261 	}
1262 	/*NOTREACHED*/
1263 }
1264