xref: /freebsd/usr.bin/nfsstat/nfsstat.c (revision bc96366c864c07ef352edb92017357917c75b36c)
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  * 4. 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 #ifndef lint
34 static const char copyright[] =
35 "@(#) Copyright (c) 1983, 1989, 1993\n\
36 	The Regents of the University of California.  All rights reserved.\n";
37 #endif /* not lint */
38 
39 #ifndef lint
40 #if 0
41 static char sccsid[] = "@(#)nfsstat.c	8.2 (Berkeley) 3/31/95";
42 #endif
43 static const char rcsid[] =
44   "$FreeBSD$";
45 #endif /* not lint */
46 
47 #include <sys/param.h>
48 #include <sys/module.h>
49 #include <sys/mount.h>
50 #include <sys/time.h>
51 #include <sys/sysctl.h>
52 #include <nfs/nfsproto.h>
53 #include <nfsclient/nfs.h>
54 #include <nfsserver/nfs.h>
55 #include <nfs/nfssvc.h>
56 
57 #include <fs/nfs/nfsport.h>
58 
59 #include <signal.h>
60 #include <fcntl.h>
61 #include <ctype.h>
62 #include <errno.h>
63 #include <kvm.h>
64 #include <limits.h>
65 #include <nlist.h>
66 #include <unistd.h>
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <string.h>
70 #include <paths.h>
71 #include <err.h>
72 
73 struct nlist nl[] = {
74 #define	N_NFSSTAT	0
75 	{ .n_name = "nfsstats" },
76 #define	N_NFSRVSTAT	1
77 	{ .n_name = "nfsrvstats" },
78 	{ .n_name = NULL },
79 };
80 kvm_t *kd;
81 
82 static int deadkernel = 0;
83 static int widemode = 0;
84 static int zflag = 0;
85 static int run_v4 = 1;
86 static int printtitle = 1;
87 static struct ext_nfsstats ext_nfsstats;
88 static int extra_output = 0;
89 
90 void intpr(int, int);
91 void printhdr(int, int);
92 void sidewaysintpr(u_int, int, int);
93 void usage(void);
94 char *sperc1(int, int);
95 char *sperc2(int, int);
96 void exp_intpr(int, int);
97 void exp_sidewaysintpr(u_int, int, int);
98 
99 #define DELTA(field)	(nfsstats.field - lastst.field)
100 
101 int
102 main(int argc, char **argv)
103 {
104 	u_int interval;
105 	int clientOnly = -1;
106 	int serverOnly = -1;
107 	int ch;
108 	char *memf, *nlistf;
109 	char errbuf[_POSIX2_LINE_MAX];
110 	int mntlen, i;
111 	char buf[1024];
112 	struct statfs *mntbuf;
113 	struct nfscl_dumpmntopts dumpmntopts;
114 
115 	interval = 0;
116 	memf = nlistf = NULL;
117 	while ((ch = getopt(argc, argv, "cesWM:mN:ow:z")) != -1)
118 		switch(ch) {
119 		case 'M':
120 			memf = optarg;
121 			break;
122 		case 'm':
123 			/* Display mount options for NFS mount points. */
124 			mntlen = getmntinfo(&mntbuf, MNT_NOWAIT);
125 			for (i = 0; i < mntlen; i++) {
126 				if (strcmp(mntbuf->f_fstypename, "nfs") == 0) {
127 					dumpmntopts.ndmnt_fname =
128 					    mntbuf->f_mntonname;
129 					dumpmntopts.ndmnt_buf = buf;
130 					dumpmntopts.ndmnt_blen = sizeof(buf);
131 					if (nfssvc(NFSSVC_DUMPMNTOPTS,
132 					    &dumpmntopts) >= 0)
133 						printf("%s on %s\n%s\n",
134 						    mntbuf->f_mntfromname,
135 						    mntbuf->f_mntonname, buf);
136 					else if (errno == EPERM)
137 						errx(1, "Only priviledged users"
138 						    " can use the -m option");
139 				}
140 				mntbuf++;
141 			}
142 			exit(0);
143 		case 'N':
144 			nlistf = optarg;
145 			break;
146 		case 'W':
147 			widemode = 1;
148 			break;
149 		case 'w':
150 			interval = atoi(optarg);
151 			break;
152 		case 'c':
153 			clientOnly = 1;
154 			if (serverOnly < 0)
155 				serverOnly = 0;
156 			break;
157 		case 's':
158 			serverOnly = 1;
159 			if (clientOnly < 0)
160 				clientOnly = 0;
161 			break;
162 		case 'z':
163 			zflag = 1;
164 			break;
165 		case 'o':
166 			if (extra_output != 0)
167 				err(1, "-o incompatible with -e");
168 			run_v4 = 0;
169 			break;
170 		case 'e':
171 			if (run_v4 == 0)
172 				err(1, "-e incompatible with -o");
173 			extra_output = 1;
174 			break;
175 		case '?':
176 		default:
177 			usage();
178 		}
179 	argc -= optind;
180 	argv += optind;
181 
182 #define	BACKWARD_COMPATIBILITY
183 #ifdef	BACKWARD_COMPATIBILITY
184 	if (*argv) {
185 		interval = atoi(*argv);
186 		if (*++argv) {
187 			nlistf = *argv;
188 			if (*++argv)
189 				memf = *argv;
190 		}
191 	}
192 #endif
193 	if (run_v4 != 0 && modfind("nfscommon") < 0)
194 		errx(1, "new client/server not loaded");
195 
196 	if (run_v4 == 0 && (nlistf != NULL || memf != NULL)) {
197 		deadkernel = 1;
198 
199 		if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
200 					errbuf)) == 0) {
201 			errx(1, "kvm_openfiles: %s", errbuf);
202 		}
203 		if (kvm_nlist(kd, nl) != 0) {
204 			errx(1, "kvm_nlist: can't get names");
205 		}
206 	}
207 
208 	if (interval) {
209 		if (run_v4 > 0)
210 			exp_sidewaysintpr(interval, clientOnly, serverOnly);
211 		else
212 			sidewaysintpr(interval, clientOnly, serverOnly);
213 	} else {
214 		if (extra_output != 0)
215 			exp_intpr(clientOnly, serverOnly);
216 		else
217 			intpr(clientOnly, serverOnly);
218 	}
219 	exit(0);
220 }
221 
222 /*
223  * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
224  * for dead ones.
225  */
226 static void
227 readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
228 {
229 	union {
230 		struct nfsstats client;
231 		struct nfsrvstats server;
232 	} zerostat;
233 	size_t buflen;
234 
235 	if (deadkernel) {
236 		if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
237 		    *stp, sizeof(struct nfsstats)) < 0) {
238 			*stp = NULL;
239 		}
240 		if (*srvstp != NULL && kvm_read(kd,
241 		    (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
242 		    sizeof(struct nfsrvstats)) < 0) {
243 			*srvstp = NULL;
244 		}
245 	} else {
246 		if (zero)
247 			bzero(&zerostat, sizeof(zerostat));
248 		buflen = sizeof(struct nfsstats);
249 		if (*stp != NULL && sysctlbyname("vfs.oldnfs.nfsstats", *stp,
250 		    &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
251 			if (errno != ENOENT)
252 				err(1, "sysctl: vfs.oldnfs.nfsstats");
253 			*stp = NULL;
254 		}
255 		buflen = sizeof(struct nfsrvstats);
256 		if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
257 		    *srvstp, &buflen, zero ? &zerostat : NULL,
258 		    zero ? buflen : 0) < 0) {
259 			if (errno != ENOENT)
260 				err(1, "sysctl: vfs.nfsrv.nfsrvstats");
261 			*srvstp = NULL;
262 		}
263 	}
264 }
265 
266 /*
267  * Print a description of the nfs stats.
268  */
269 void
270 intpr(int clientOnly, int serverOnly)
271 {
272 	struct nfsstats nfsstats, *nfsstatsp;
273 	struct nfsrvstats nfsrvstats, *nfsrvstatsp;
274 	int nfssvc_flag;
275 
276 	if (run_v4 == 0) {
277 		/*
278 		 * Only read the stats we are going to display to avoid zeroing
279 		 * stats the user didn't request.
280 		 */
281 		if (clientOnly)
282 			nfsstatsp = &nfsstats;
283 		else
284 			nfsstatsp = NULL;
285 		if (serverOnly)
286 			nfsrvstatsp = &nfsrvstats;
287 		else
288 			nfsrvstatsp = NULL;
289 
290 		readstats(&nfsstatsp, &nfsrvstatsp, zflag);
291 
292 		if (clientOnly && !nfsstatsp) {
293 			printf("Client not present!\n");
294 			clientOnly = 0;
295 		}
296 	} else {
297 		nfssvc_flag = NFSSVC_GETSTATS;
298 		if (zflag != 0) {
299 			if (clientOnly != 0)
300 				nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
301 			if (serverOnly != 0)
302 				nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
303 		}
304 		if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
305 			err(1, "Can't get stats");
306 	}
307 	if (clientOnly) {
308 		printf("Client Info:\n");
309 		printf("Rpc Counts:\n");
310 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
311 			"Getattr", "Setattr", "Lookup", "Readlink", "Read",
312 			"Write", "Create", "Remove");
313 		if (run_v4 == 0)
314 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
315 				nfsstats.rpccnt[NFSPROC_GETATTR],
316 				nfsstats.rpccnt[NFSPROC_SETATTR],
317 				nfsstats.rpccnt[NFSPROC_LOOKUP],
318 				nfsstats.rpccnt[NFSPROC_READLINK],
319 				nfsstats.rpccnt[NFSPROC_READ],
320 				nfsstats.rpccnt[NFSPROC_WRITE],
321 				nfsstats.rpccnt[NFSPROC_CREATE],
322 				nfsstats.rpccnt[NFSPROC_REMOVE]);
323 		else
324 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
325 				ext_nfsstats.rpccnt[NFSPROC_GETATTR],
326 				ext_nfsstats.rpccnt[NFSPROC_SETATTR],
327 				ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
328 				ext_nfsstats.rpccnt[NFSPROC_READLINK],
329 				ext_nfsstats.rpccnt[NFSPROC_READ],
330 				ext_nfsstats.rpccnt[NFSPROC_WRITE],
331 				ext_nfsstats.rpccnt[NFSPROC_CREATE],
332 				ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
333 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
334 			"Rename", "Link", "Symlink", "Mkdir", "Rmdir",
335 			"Readdir", "RdirPlus", "Access");
336 		if (run_v4 == 0)
337 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
338 				nfsstats.rpccnt[NFSPROC_RENAME],
339 				nfsstats.rpccnt[NFSPROC_LINK],
340 				nfsstats.rpccnt[NFSPROC_SYMLINK],
341 				nfsstats.rpccnt[NFSPROC_MKDIR],
342 				nfsstats.rpccnt[NFSPROC_RMDIR],
343 				nfsstats.rpccnt[NFSPROC_READDIR],
344 				nfsstats.rpccnt[NFSPROC_READDIRPLUS],
345 				nfsstats.rpccnt[NFSPROC_ACCESS]);
346 		else
347 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
348 				ext_nfsstats.rpccnt[NFSPROC_RENAME],
349 				ext_nfsstats.rpccnt[NFSPROC_LINK],
350 				ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
351 				ext_nfsstats.rpccnt[NFSPROC_MKDIR],
352 				ext_nfsstats.rpccnt[NFSPROC_RMDIR],
353 				ext_nfsstats.rpccnt[NFSPROC_READDIR],
354 				ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
355 				ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
356 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
357 			"Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
358 		if (run_v4 == 0)
359 			printf("%9d %9d %9d %9d %9d\n",
360 				nfsstats.rpccnt[NFSPROC_MKNOD],
361 				nfsstats.rpccnt[NFSPROC_FSSTAT],
362 				nfsstats.rpccnt[NFSPROC_FSINFO],
363 				nfsstats.rpccnt[NFSPROC_PATHCONF],
364 				nfsstats.rpccnt[NFSPROC_COMMIT]);
365 		else
366 			printf("%9d %9d %9d %9d %9d\n",
367 				ext_nfsstats.rpccnt[NFSPROC_MKNOD],
368 				ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
369 				ext_nfsstats.rpccnt[NFSPROC_FSINFO],
370 				ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
371 				ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
372 		printf("Rpc Info:\n");
373 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
374 			"TimedOut", "Invalid", "X Replies", "Retries",
375 			"Requests");
376 		if (run_v4 == 0)
377 			printf("%9d %9d %9d %9d %9d\n",
378 				nfsstats.rpctimeouts,
379 				nfsstats.rpcinvalid,
380 				nfsstats.rpcunexpected,
381 				nfsstats.rpcretries,
382 				nfsstats.rpcrequests);
383 		else
384 			printf("%9d %9d %9d %9d %9d\n",
385 				ext_nfsstats.rpctimeouts,
386 				ext_nfsstats.rpcinvalid,
387 				ext_nfsstats.rpcunexpected,
388 				ext_nfsstats.rpcretries,
389 				ext_nfsstats.rpcrequests);
390 		printf("Cache Info:\n");
391 		printf("%9.9s %9.9s %9.9s %9.9s",
392 			"Attr Hits", "Misses", "Lkup Hits", "Misses");
393 		printf(" %9.9s %9.9s %9.9s %9.9s\n",
394 			"BioR Hits", "Misses", "BioW Hits", "Misses");
395 		if (run_v4 == 0) {
396 			printf("%9d %9d %9d %9d",
397 				nfsstats.attrcache_hits,
398 				nfsstats.attrcache_misses,
399 				nfsstats.lookupcache_hits,
400 				nfsstats.lookupcache_misses);
401 			printf(" %9d %9d %9d %9d\n",
402 				nfsstats.biocache_reads-nfsstats.read_bios,
403 				nfsstats.read_bios,
404 				nfsstats.biocache_writes-nfsstats.write_bios,
405 				nfsstats.write_bios);
406 		} else {
407 			printf("%9d %9d %9d %9d",
408 				ext_nfsstats.attrcache_hits,
409 				ext_nfsstats.attrcache_misses,
410 				ext_nfsstats.lookupcache_hits,
411 				ext_nfsstats.lookupcache_misses);
412 			printf(" %9d %9d %9d %9d\n",
413 				ext_nfsstats.biocache_reads -
414 				ext_nfsstats.read_bios,
415 				ext_nfsstats.read_bios,
416 				ext_nfsstats.biocache_writes -
417 				ext_nfsstats.write_bios,
418 				ext_nfsstats.write_bios);
419 		}
420 		printf("%9.9s %9.9s %9.9s %9.9s",
421 			"BioRLHits", "Misses", "BioD Hits", "Misses");
422 		printf(" %9.9s %9.9s %9.9s %9.9s\n", "DirE Hits", "Misses", "Accs Hits", "Misses");
423 		if (run_v4 == 0) {
424 			printf("%9d %9d %9d %9d",
425 				nfsstats.biocache_readlinks -
426 				nfsstats.readlink_bios,
427 				nfsstats.readlink_bios,
428 				nfsstats.biocache_readdirs -
429 				nfsstats.readdir_bios,
430 				nfsstats.readdir_bios);
431 			printf(" %9d %9d %9d %9d\n",
432 				nfsstats.direofcache_hits,
433 				nfsstats.direofcache_misses,
434 				nfsstats.accesscache_hits,
435 				nfsstats.accesscache_misses);
436 		} else {
437 			printf("%9d %9d %9d %9d",
438 				ext_nfsstats.biocache_readlinks -
439 				ext_nfsstats.readlink_bios,
440 				ext_nfsstats.readlink_bios,
441 				ext_nfsstats.biocache_readdirs -
442 				ext_nfsstats.readdir_bios,
443 				ext_nfsstats.readdir_bios);
444 			printf(" %9d %9d %9d %9d\n",
445 				ext_nfsstats.direofcache_hits,
446 				ext_nfsstats.direofcache_misses,
447 				ext_nfsstats.accesscache_hits,
448 				ext_nfsstats.accesscache_misses);
449 		}
450 	}
451 	if (run_v4 == 0 && serverOnly && !nfsrvstatsp) {
452 		printf("Server not present!\n");
453 		serverOnly = 0;
454 	}
455 	if (serverOnly) {
456 		printf("\nServer Info:\n");
457 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
458 			"Getattr", "Setattr", "Lookup", "Readlink", "Read",
459 			"Write", "Create", "Remove");
460 		if (run_v4 == 0)
461 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
462 				nfsrvstats.srvrpccnt[NFSPROC_GETATTR],
463 				nfsrvstats.srvrpccnt[NFSPROC_SETATTR],
464 				nfsrvstats.srvrpccnt[NFSPROC_LOOKUP],
465 				nfsrvstats.srvrpccnt[NFSPROC_READLINK],
466 				nfsrvstats.srvrpccnt[NFSPROC_READ],
467 				nfsrvstats.srvrpccnt[NFSPROC_WRITE],
468 				nfsrvstats.srvrpccnt[NFSPROC_CREATE],
469 				nfsrvstats.srvrpccnt[NFSPROC_REMOVE]);
470 		else
471 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
472 				ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
473 				ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
474 				ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
475 				ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
476 				ext_nfsstats.srvrpccnt[NFSV4OP_READ],
477 				ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
478 				ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
479 				ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
480 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
481 			"Rename", "Link", "Symlink", "Mkdir", "Rmdir",
482 			"Readdir", "RdirPlus", "Access");
483 		if (run_v4 == 0)
484 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
485 				nfsrvstats.srvrpccnt[NFSPROC_RENAME],
486 				nfsrvstats.srvrpccnt[NFSPROC_LINK],
487 				nfsrvstats.srvrpccnt[NFSPROC_SYMLINK],
488 				nfsrvstats.srvrpccnt[NFSPROC_MKDIR],
489 				nfsrvstats.srvrpccnt[NFSPROC_RMDIR],
490 				nfsrvstats.srvrpccnt[NFSPROC_READDIR],
491 				nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS],
492 				nfsrvstats.srvrpccnt[NFSPROC_ACCESS]);
493 		else
494 			printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
495 				ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
496 				ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
497 				ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
498 				ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
499 				ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
500 				ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
501 				ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
502 				ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
503 		printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
504 			"Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
505 		if (run_v4 == 0)
506 			printf("%9d %9d %9d %9d %9d\n",
507 				nfsrvstats.srvrpccnt[NFSPROC_MKNOD],
508 				nfsrvstats.srvrpccnt[NFSPROC_FSSTAT],
509 				nfsrvstats.srvrpccnt[NFSPROC_FSINFO],
510 				nfsrvstats.srvrpccnt[NFSPROC_PATHCONF],
511 				nfsrvstats.srvrpccnt[NFSPROC_COMMIT]);
512 		else
513 			printf("%9d %9d %9d %9d %9d\n",
514 				ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
515 				ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
516 				ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
517 				ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
518 				ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
519 		printf("Server Ret-Failed\n");
520 		if (run_v4 == 0)
521 			printf("%17d\n", nfsrvstats.srvrpc_errs);
522 		else
523 			printf("%17d\n", ext_nfsstats.srvrpc_errs);
524 		printf("Server Faults\n");
525 		if (run_v4 == 0)
526 			printf("%13d\n", nfsrvstats.srv_errs);
527 		else
528 			printf("%13d\n", ext_nfsstats.srv_errs);
529 		printf("Server Cache Stats:\n");
530 		printf("%9.9s %9.9s %9.9s %9.9s\n",
531 			"Inprog", "Idem", "Non-idem", "Misses");
532 		if (run_v4 == 0)
533 			printf("%9d %9d %9d %9d\n",
534 				nfsrvstats.srvcache_inproghits,
535 				nfsrvstats.srvcache_idemdonehits,
536 				nfsrvstats.srvcache_nonidemdonehits,
537 				nfsrvstats.srvcache_misses);
538 		else
539 			printf("%9d %9d %9d %9d\n",
540 				ext_nfsstats.srvcache_inproghits,
541 				ext_nfsstats.srvcache_idemdonehits,
542 				ext_nfsstats.srvcache_nonidemdonehits,
543 				ext_nfsstats.srvcache_misses);
544 		printf("Server Write Gathering:\n");
545 		printf("%9.9s %9.9s %9.9s\n",
546 			"WriteOps", "WriteRPC", "Opsaved");
547 		if (run_v4 == 0)
548 			printf("%9d %9d %9d\n",
549 				nfsrvstats.srvvop_writes,
550 				nfsrvstats.srvrpccnt[NFSPROC_WRITE],
551 				nfsrvstats.srvrpccnt[NFSPROC_WRITE] -
552 				    nfsrvstats.srvvop_writes);
553 		else
554 			/*
555 			 * The new client doesn't do write gathering. It was
556 			 * only useful for NFSv2.
557 			 */
558 			printf("%9d %9d %9d\n",
559 				ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
560 				ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
561 	}
562 }
563 
564 u_char	signalled;			/* set if alarm goes off "early" */
565 
566 /*
567  * Print a running summary of nfs statistics.
568  * Repeat display every interval seconds, showing statistics
569  * collected over that interval.  Assumes that interval is non-zero.
570  * First line printed at top of screen is always cumulative.
571  */
572 void
573 sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
574 {
575 	struct nfsstats nfsstats, lastst, *nfsstatsp;
576 	struct nfsrvstats nfsrvstats, lastsrvst, *nfsrvstatsp;
577 	int hdrcnt = 1;
578 
579 	nfsstatsp = &lastst;
580 	nfsrvstatsp = &lastsrvst;
581 	readstats(&nfsstatsp, &nfsrvstatsp, 0);
582 	if (clientOnly && !nfsstatsp) {
583 		printf("Client not present!\n");
584 		clientOnly = 0;
585 	}
586 	if (serverOnly && !nfsrvstatsp) {
587 		printf("Server not present!\n");
588 		serverOnly = 0;
589 	}
590 	sleep(interval);
591 
592 	for (;;) {
593 		nfsstatsp = &nfsstats;
594 		nfsrvstatsp = &nfsrvstats;
595 		readstats(&nfsstatsp, &nfsrvstatsp, 0);
596 
597 		if (--hdrcnt == 0) {
598 			printhdr(clientOnly, serverOnly);
599 			if (clientOnly && serverOnly)
600 				hdrcnt = 10;
601 			else
602 				hdrcnt = 20;
603 		}
604 		if (clientOnly) {
605 		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
606 			((clientOnly && serverOnly) ? "Client:" : ""),
607 			DELTA(rpccnt[NFSPROC_GETATTR]),
608 			DELTA(rpccnt[NFSPROC_LOOKUP]),
609 			DELTA(rpccnt[NFSPROC_READLINK]),
610 			DELTA(rpccnt[NFSPROC_READ]),
611 			DELTA(rpccnt[NFSPROC_WRITE]),
612 			DELTA(rpccnt[NFSPROC_RENAME]),
613 			DELTA(rpccnt[NFSPROC_ACCESS]),
614 			DELTA(rpccnt[NFSPROC_READDIR]) +
615 			DELTA(rpccnt[NFSPROC_READDIRPLUS])
616 		    );
617 		    if (widemode) {
618 			    printf(" %s %s %s %s %s %s",
619 				sperc1(DELTA(attrcache_hits),
620 				    DELTA(attrcache_misses)),
621 				sperc1(DELTA(lookupcache_hits),
622 				    DELTA(lookupcache_misses)),
623 				sperc2(DELTA(biocache_reads),
624 				    DELTA(read_bios)),
625 				sperc2(DELTA(biocache_writes),
626 				    DELTA(write_bios)),
627 				sperc1(DELTA(accesscache_hits),
628 				    DELTA(accesscache_misses)),
629 				sperc2(DELTA(biocache_readdirs),
630 				    DELTA(readdir_bios))
631 			    );
632 		    }
633 		    printf("\n");
634 		    lastst = nfsstats;
635 		}
636 		if (serverOnly) {
637 		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
638 			((clientOnly && serverOnly) ? "Server:" : ""),
639 			nfsrvstats.srvrpccnt[NFSPROC_GETATTR]-lastsrvst.srvrpccnt[NFSPROC_GETATTR],
640 			nfsrvstats.srvrpccnt[NFSPROC_LOOKUP]-lastsrvst.srvrpccnt[NFSPROC_LOOKUP],
641 			nfsrvstats.srvrpccnt[NFSPROC_READLINK]-lastsrvst.srvrpccnt[NFSPROC_READLINK],
642 			nfsrvstats.srvrpccnt[NFSPROC_READ]-lastsrvst.srvrpccnt[NFSPROC_READ],
643 			nfsrvstats.srvrpccnt[NFSPROC_WRITE]-lastsrvst.srvrpccnt[NFSPROC_WRITE],
644 			nfsrvstats.srvrpccnt[NFSPROC_RENAME]-lastsrvst.srvrpccnt[NFSPROC_RENAME],
645 			nfsrvstats.srvrpccnt[NFSPROC_ACCESS]-lastsrvst.srvrpccnt[NFSPROC_ACCESS],
646 			(nfsrvstats.srvrpccnt[NFSPROC_READDIR]-lastsrvst.srvrpccnt[NFSPROC_READDIR])
647 			+(nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS]-lastsrvst.srvrpccnt[NFSPROC_READDIRPLUS]));
648 		    printf("\n");
649 		    lastsrvst = nfsrvstats;
650 		}
651 		fflush(stdout);
652 		sleep(interval);
653 	}
654 	/*NOTREACHED*/
655 }
656 
657 void
658 printhdr(int clientOnly, int serverOnly)
659 {
660 	printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
661 	    ((serverOnly && clientOnly) ? "        " : " "),
662 	    "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename",
663 	    "Access", "Rddir");
664 	if (widemode && clientOnly) {
665 		printf(" Attr Lkup BioR BioW Accs BioD");
666 	}
667 	printf("\n");
668 	fflush(stdout);
669 }
670 
671 void
672 usage(void)
673 {
674 	(void)fprintf(stderr,
675 	    "usage: nfsstat [-cemoszW] [-M core] [-N system] [-w wait]\n");
676 	exit(1);
677 }
678 
679 static char SPBuf[64][8];
680 static int SPIndex;
681 
682 char *
683 sperc1(int hits, int misses)
684 {
685 	char *p = SPBuf[SPIndex];
686 
687 	if (hits + misses) {
688 		sprintf(p, "%3d%%",
689 		    (int)(char)((quad_t)hits * 100 / (hits + misses)));
690 	} else {
691 		sprintf(p, "   -");
692 	}
693 	SPIndex = (SPIndex + 1) & 63;
694 	return(p);
695 }
696 
697 char *
698 sperc2(int ttl, int misses)
699 {
700 	char *p = SPBuf[SPIndex];
701 
702 	if (ttl) {
703 		sprintf(p, "%3d%%",
704 		    (int)(char)((quad_t)(ttl - misses) * 100 / ttl));
705 	} else {
706 		sprintf(p, "   -");
707 	}
708 	SPIndex = (SPIndex + 1) & 63;
709 	return(p);
710 }
711 
712 /*
713  * Print a description of the nfs stats for the experimental client/server.
714  */
715 void
716 exp_intpr(int clientOnly, int serverOnly)
717 {
718 	int nfssvc_flag;
719 
720 	nfssvc_flag = NFSSVC_GETSTATS;
721 	if (zflag != 0) {
722 		if (clientOnly != 0)
723 			nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
724 		if (serverOnly != 0)
725 			nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
726 	}
727 	if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
728 		err(1, "Can't get stats");
729 	if (clientOnly != 0) {
730 		if (printtitle) {
731 			printf("Client Info:\n");
732 			printf("Rpc Counts:\n");
733 			printf(
734 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
735 			    , "Getattr", "Setattr", "Lookup", "Readlink",
736 			    "Read", "Write", "Create", "Remove");
737 		}
738 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
739 		    ext_nfsstats.rpccnt[NFSPROC_GETATTR],
740 		    ext_nfsstats.rpccnt[NFSPROC_SETATTR],
741 		    ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
742 		    ext_nfsstats.rpccnt[NFSPROC_READLINK],
743 		    ext_nfsstats.rpccnt[NFSPROC_READ],
744 		    ext_nfsstats.rpccnt[NFSPROC_WRITE],
745 		    ext_nfsstats.rpccnt[NFSPROC_CREATE],
746 		    ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
747 		if (printtitle)
748 			printf(
749 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
750 			    , "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
751 			    "Readdir", "RdirPlus", "Access");
752 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
753 		    ext_nfsstats.rpccnt[NFSPROC_RENAME],
754 		    ext_nfsstats.rpccnt[NFSPROC_LINK],
755 		    ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
756 		    ext_nfsstats.rpccnt[NFSPROC_MKDIR],
757 		    ext_nfsstats.rpccnt[NFSPROC_RMDIR],
758 		    ext_nfsstats.rpccnt[NFSPROC_READDIR],
759 		    ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
760 		    ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
761 		if (printtitle)
762 			printf(
763 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
764 			    , "Mknod", "Fsstat", "Fsinfo", "PathConf",
765 			    "Commit", "SetClId", "SetClIdCf", "Lock");
766 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
767 		    ext_nfsstats.rpccnt[NFSPROC_MKNOD],
768 		    ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
769 		    ext_nfsstats.rpccnt[NFSPROC_FSINFO],
770 		    ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
771 		    ext_nfsstats.rpccnt[NFSPROC_COMMIT],
772 		    ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID],
773 		    ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM],
774 		    ext_nfsstats.rpccnt[NFSPROC_LOCK]);
775 		if (printtitle)
776 			printf("%9.9s %9.9s %9.9s %9.9s\n",
777 			    "LockT", "LockU", "Open", "OpenCfr");
778 		printf("%9d %9d %9d %9d\n",
779 		    ext_nfsstats.rpccnt[NFSPROC_LOCKT],
780 		    ext_nfsstats.rpccnt[NFSPROC_LOCKU],
781 		    ext_nfsstats.rpccnt[NFSPROC_OPEN],
782 		    ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]);
783 		if (printtitle)
784 			printf(
785 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
786 			    , "OpenOwner", "Opens", "LockOwner",
787 			    "Locks", "Delegs", "LocalOwn",
788 			    "LocalOpen", "LocalLOwn");
789 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
790 		    ext_nfsstats.clopenowners,
791 		    ext_nfsstats.clopens,
792 		    ext_nfsstats.cllockowners,
793 		    ext_nfsstats.cllocks,
794 		    ext_nfsstats.cldelegates,
795 		    ext_nfsstats.cllocalopenowners,
796 		    ext_nfsstats.cllocalopens,
797 		    ext_nfsstats.cllocallockowners);
798 		if (printtitle)
799 			printf("%9.9s\n", "LocalLock");
800 		printf("%9d\n", ext_nfsstats.cllocallocks);
801 		if (printtitle) {
802 			printf("Rpc Info:\n");
803 			printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
804 			    "TimedOut", "Invalid", "X Replies", "Retries",
805 			    "Requests");
806 		}
807 		printf("%9d %9d %9d %9d %9d\n",
808 		    ext_nfsstats.rpctimeouts,
809 		    ext_nfsstats.rpcinvalid,
810 		    ext_nfsstats.rpcunexpected,
811 		    ext_nfsstats.rpcretries,
812 		    ext_nfsstats.rpcrequests);
813 		if (printtitle) {
814 			printf("Cache Info:\n");
815 			printf("%9.9s %9.9s %9.9s %9.9s",
816 			    "Attr Hits", "Misses", "Lkup Hits", "Misses");
817 			printf(" %9.9s %9.9s %9.9s %9.9s\n",
818 			    "BioR Hits", "Misses", "BioW Hits", "Misses");
819 		}
820 		printf("%9d %9d %9d %9d",
821 		    ext_nfsstats.attrcache_hits,
822 		    ext_nfsstats.attrcache_misses,
823 		    ext_nfsstats.lookupcache_hits,
824 		    ext_nfsstats.lookupcache_misses);
825 		printf(" %9d %9d %9d %9d\n",
826 		    ext_nfsstats.biocache_reads - ext_nfsstats.read_bios,
827 		    ext_nfsstats.read_bios,
828 		    ext_nfsstats.biocache_writes - ext_nfsstats.write_bios,
829 		    ext_nfsstats.write_bios);
830 		if (printtitle) {
831 			printf("%9.9s %9.9s %9.9s %9.9s",
832 			    "BioRLHits", "Misses", "BioD Hits", "Misses");
833 			printf(" %9.9s %9.9s\n", "DirE Hits", "Misses");
834 		}
835 		printf("%9d %9d %9d %9d",
836 		    ext_nfsstats.biocache_readlinks -
837 		    ext_nfsstats.readlink_bios,
838 		    ext_nfsstats.readlink_bios,
839 		    ext_nfsstats.biocache_readdirs -
840 		    ext_nfsstats.readdir_bios,
841 		    ext_nfsstats.readdir_bios);
842 		printf(" %9d %9d\n",
843 		    ext_nfsstats.direofcache_hits,
844 		    ext_nfsstats.direofcache_misses);
845 	}
846 	if (serverOnly != 0) {
847 		if (printtitle) {
848 			printf("\nServer Info:\n");
849 			printf(
850 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
851 			    , "Getattr", "Setattr", "Lookup", "Readlink",
852 			    "Read", "Write", "Create", "Remove");
853 		}
854 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
855 		    ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
856 		    ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
857 		    ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
858 		    ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
859 		    ext_nfsstats.srvrpccnt[NFSV4OP_READ],
860 		    ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
861 		    ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE],
862 		    ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
863 		if (printtitle)
864 			printf(
865 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
866 			    , "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
867 			    "Readdir", "RdirPlus", "Access");
868 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
869 		    ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
870 		    ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
871 		    ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
872 		    ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
873 		    ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
874 		    ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
875 		    ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
876 		    ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
877 		if (printtitle)
878 			printf(
879 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
880 			    , "Mknod", "Fsstat", "Fsinfo", "PathConf",
881 			    "Commit", "LookupP", "SetClId", "SetClIdCf");
882 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
883 		    ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
884 		    ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
885 		    ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
886 		    ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
887 		    ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT],
888 		    ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP],
889 		    ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID],
890 		    ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]);
891 		if (printtitle)
892 			printf(
893 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
894 			    , "Open", "OpenAttr", "OpenDwnGr", "OpenCfrm",
895 			    "DelePurge", "DeleRet", "GetFH", "Lock");
896 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
897 		    ext_nfsstats.srvrpccnt[NFSV4OP_OPEN],
898 		    ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR],
899 		    ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE],
900 		    ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM],
901 		    ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE],
902 		    ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN],
903 		    ext_nfsstats.srvrpccnt[NFSV4OP_GETFH],
904 		    ext_nfsstats.srvrpccnt[NFSV4OP_LOCK]);
905 		if (printtitle)
906 			printf(
907 			    "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
908 			    , "LockT", "LockU", "Close", "Verify", "NVerify",
909 			    "PutFH", "PutPubFH", "PutRootFH");
910 		printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
911 		    ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT],
912 		    ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU],
913 		    ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE],
914 		    ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY],
915 		    ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY],
916 		    ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH],
917 		    ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH],
918 		    ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH]);
919 		if (printtitle)
920 			printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
921 			    "Renew", "RestoreFH", "SaveFH", "Secinfo",
922 			    "RelLckOwn", "V4Create");
923 		printf("%9d %9d %9d %9d %9d %9d\n",
924 		    ext_nfsstats.srvrpccnt[NFSV4OP_RENEW],
925 		    ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH],
926 		    ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH],
927 		    ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO],
928 		    ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN],
929 		    ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]);
930 		if (printtitle) {
931 			printf("Server:\n");
932 			printf("%9.9s %9.9s %9.9s\n",
933 			    "Retfailed", "Faults", "Clients");
934 		}
935 		printf("%9d %9d %9d\n",
936 		    ext_nfsstats.srv_errs, ext_nfsstats.srvrpc_errs,
937 		    ext_nfsstats.srvclients);
938 		if (printtitle)
939 			printf("%9.9s %9.9s %9.9s %9.9s %9.9s \n",
940 			    "OpenOwner", "Opens", "LockOwner",
941 			    "Locks", "Delegs");
942 		printf("%9d %9d %9d %9d %9d \n",
943 		    ext_nfsstats.srvopenowners,
944 		    ext_nfsstats.srvopens,
945 		    ext_nfsstats.srvlockowners,
946 		    ext_nfsstats.srvlocks,
947 		    ext_nfsstats.srvdelegates);
948 		if (printtitle) {
949 			printf("Server Cache Stats:\n");
950 			printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
951 			    "Inprog", "Idem", "Non-idem", "Misses",
952 			    "CacheSize", "TCPPeak");
953 		}
954 		printf("%9d %9d %9d %9d %9d %9d\n",
955 		    ext_nfsstats.srvcache_inproghits,
956 		    ext_nfsstats.srvcache_idemdonehits,
957 		    ext_nfsstats.srvcache_nonidemdonehits,
958 		    ext_nfsstats.srvcache_misses,
959 		    ext_nfsstats.srvcache_size,
960 		    ext_nfsstats.srvcache_tcppeak);
961 	}
962 }
963 
964 /*
965  * Print a running summary of nfs statistics for the experimental client and/or
966  * server.
967  * Repeat display every interval seconds, showing statistics
968  * collected over that interval.  Assumes that interval is non-zero.
969  * First line printed at top of screen is always cumulative.
970  */
971 void
972 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
973 {
974 	struct ext_nfsstats nfsstats, lastst, *ext_nfsstatsp;
975 	int hdrcnt = 1;
976 
977 	ext_nfsstatsp = &lastst;
978 	if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
979 		err(1, "Can't get stats");
980 	sleep(interval);
981 
982 	for (;;) {
983 		ext_nfsstatsp = &nfsstats;
984 		if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
985 			err(1, "Can't get stats");
986 
987 		if (--hdrcnt == 0) {
988 			printhdr(clientOnly, serverOnly);
989 			if (clientOnly && serverOnly)
990 				hdrcnt = 10;
991 			else
992 				hdrcnt = 20;
993 		}
994 		if (clientOnly) {
995 		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
996 			((clientOnly && serverOnly) ? "Client:" : ""),
997 			DELTA(rpccnt[NFSPROC_GETATTR]),
998 			DELTA(rpccnt[NFSPROC_LOOKUP]),
999 			DELTA(rpccnt[NFSPROC_READLINK]),
1000 			DELTA(rpccnt[NFSPROC_READ]),
1001 			DELTA(rpccnt[NFSPROC_WRITE]),
1002 			DELTA(rpccnt[NFSPROC_RENAME]),
1003 			DELTA(rpccnt[NFSPROC_ACCESS]),
1004 			DELTA(rpccnt[NFSPROC_READDIR]) +
1005 			DELTA(rpccnt[NFSPROC_READDIRPLUS])
1006 		    );
1007 		    if (widemode) {
1008 			    printf(" %s %s %s %s %s %s",
1009 				sperc1(DELTA(attrcache_hits),
1010 				    DELTA(attrcache_misses)),
1011 				sperc1(DELTA(lookupcache_hits),
1012 				    DELTA(lookupcache_misses)),
1013 				sperc2(DELTA(biocache_reads),
1014 				    DELTA(read_bios)),
1015 				sperc2(DELTA(biocache_writes),
1016 				    DELTA(write_bios)),
1017 				sperc1(DELTA(accesscache_hits),
1018 				    DELTA(accesscache_misses)),
1019 				sperc2(DELTA(biocache_readdirs),
1020 				    DELTA(readdir_bios))
1021 			    );
1022 		    }
1023 		    printf("\n");
1024 		}
1025 		if (serverOnly) {
1026 		    printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
1027 			((clientOnly && serverOnly) ? "Server:" : ""),
1028 			DELTA(srvrpccnt[NFSV4OP_GETATTR]),
1029 			DELTA(srvrpccnt[NFSV4OP_LOOKUP]),
1030 			DELTA(srvrpccnt[NFSV4OP_READLINK]),
1031 			DELTA(srvrpccnt[NFSV4OP_READ]),
1032 			DELTA(srvrpccnt[NFSV4OP_WRITE]),
1033 			DELTA(srvrpccnt[NFSV4OP_RENAME]),
1034 			DELTA(srvrpccnt[NFSV4OP_ACCESS]),
1035 			DELTA(srvrpccnt[NFSV4OP_READDIR]) +
1036 			DELTA(srvrpccnt[NFSV4OP_READDIRPLUS]));
1037 		    printf("\n");
1038 		}
1039 		lastst = nfsstats;
1040 		fflush(stdout);
1041 		sleep(interval);
1042 	}
1043 	/*NOTREACHED*/
1044 }
1045 
1046