2 * Copyright (c) 1983, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
34 static const char copyright[] =
35 "@(#) Copyright (c) 1983, 1989, 1993\n\
36 The Regents of the University of California. All rights reserved.\n";
41 static char sccsid[] = "@(#)nfsstat.c 8.2 (Berkeley) 3/31/95";
43 static const char rcsid[] =
47 #include <sys/param.h>
48 #include <sys/module.h>
49 #include <sys/mount.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>
57 #include <fs/nfs/nfsport.h>
75 { .n_name = "nfsstats" },
77 { .n_name = "nfsrvstats" },
82 static int deadkernel = 0;
83 static int widemode = 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;
91 void printhdr(int, int);
92 void sidewaysintpr(u_int, int, int);
94 char *sperc1(int, int);
95 char *sperc2(int, int);
96 void exp_intpr(int, int);
97 void exp_sidewaysintpr(u_int, int, int);
99 #define DELTA(field) (nfsstats.field - lastst.field)
102 main(int argc, char **argv)
109 char errbuf[_POSIX2_LINE_MAX];
112 struct statfs *mntbuf;
113 struct nfscl_dumpmntopts dumpmntopts;
116 memf = nlistf = NULL;
117 while ((ch = getopt(argc, argv, "cesWM:mN:ow:z")) != -1)
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 =
129 dumpmntopts.ndmnt_buf = buf;
130 dumpmntopts.ndmnt_blen = sizeof(buf);
131 if (nfssvc(NFSSVC_DUMPMNTOPTS,
133 printf("%s on %s\n%s\n",
134 mntbuf->f_mntfromname,
135 mntbuf->f_mntonname, buf);
147 interval = atoi(optarg);
163 if (extra_output != 0)
164 err(1, "-o incompatible with -e");
169 err(1, "-e incompatible with -o");
179 #define BACKWARD_COMPATIBILITY
180 #ifdef BACKWARD_COMPATIBILITY
182 interval = atoi(*argv);
190 if (run_v4 != 0 && modfind("nfscommon") < 0)
191 errx(1, "new client/server not loaded");
193 if (run_v4 == 0 && (nlistf != NULL || memf != NULL)) {
196 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
198 errx(1, "kvm_openfiles: %s", errbuf);
200 if (kvm_nlist(kd, nl) != 0) {
201 errx(1, "kvm_nlist: can't get names");
207 exp_sidewaysintpr(interval, clientOnly, serverOnly);
209 sidewaysintpr(interval, clientOnly, serverOnly);
211 if (extra_output != 0)
212 exp_intpr(clientOnly, serverOnly);
214 intpr(clientOnly, serverOnly);
220 * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
224 readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
227 struct nfsstats client;
228 struct nfsrvstats server;
233 if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
234 *stp, sizeof(struct nfsstats)) < 0) {
237 if (*srvstp != NULL && kvm_read(kd,
238 (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
239 sizeof(struct nfsrvstats)) < 0) {
244 bzero(&zerostat, sizeof(zerostat));
245 buflen = sizeof(struct nfsstats);
246 if (*stp != NULL && sysctlbyname("vfs.oldnfs.nfsstats", *stp,
247 &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
249 err(1, "sysctl: vfs.oldnfs.nfsstats");
252 buflen = sizeof(struct nfsrvstats);
253 if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
254 *srvstp, &buflen, zero ? &zerostat : NULL,
255 zero ? buflen : 0) < 0) {
257 err(1, "sysctl: vfs.nfsrv.nfsrvstats");
264 * Print a description of the nfs stats.
267 intpr(int clientOnly, int serverOnly)
269 struct nfsstats nfsstats, *nfsstatsp;
270 struct nfsrvstats nfsrvstats, *nfsrvstatsp;
275 * Only read the stats we are going to display to avoid zeroing
276 * stats the user didn't request.
279 nfsstatsp = &nfsstats;
283 nfsrvstatsp = &nfsrvstats;
287 readstats(&nfsstatsp, &nfsrvstatsp, zflag);
289 if (clientOnly && !nfsstatsp) {
290 printf("Client not present!\n");
294 nfssvc_flag = NFSSVC_GETSTATS;
297 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
299 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
301 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
302 err(1, "Can't get stats");
305 printf("Client Info:\n");
306 printf("Rpc Counts:\n");
307 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
308 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
309 "Write", "Create", "Remove");
311 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
312 nfsstats.rpccnt[NFSPROC_GETATTR],
313 nfsstats.rpccnt[NFSPROC_SETATTR],
314 nfsstats.rpccnt[NFSPROC_LOOKUP],
315 nfsstats.rpccnt[NFSPROC_READLINK],
316 nfsstats.rpccnt[NFSPROC_READ],
317 nfsstats.rpccnt[NFSPROC_WRITE],
318 nfsstats.rpccnt[NFSPROC_CREATE],
319 nfsstats.rpccnt[NFSPROC_REMOVE]);
321 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
322 ext_nfsstats.rpccnt[NFSPROC_GETATTR],
323 ext_nfsstats.rpccnt[NFSPROC_SETATTR],
324 ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
325 ext_nfsstats.rpccnt[NFSPROC_READLINK],
326 ext_nfsstats.rpccnt[NFSPROC_READ],
327 ext_nfsstats.rpccnt[NFSPROC_WRITE],
328 ext_nfsstats.rpccnt[NFSPROC_CREATE],
329 ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
330 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
331 "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
332 "Readdir", "RdirPlus", "Access");
334 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
335 nfsstats.rpccnt[NFSPROC_RENAME],
336 nfsstats.rpccnt[NFSPROC_LINK],
337 nfsstats.rpccnt[NFSPROC_SYMLINK],
338 nfsstats.rpccnt[NFSPROC_MKDIR],
339 nfsstats.rpccnt[NFSPROC_RMDIR],
340 nfsstats.rpccnt[NFSPROC_READDIR],
341 nfsstats.rpccnt[NFSPROC_READDIRPLUS],
342 nfsstats.rpccnt[NFSPROC_ACCESS]);
344 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
345 ext_nfsstats.rpccnt[NFSPROC_RENAME],
346 ext_nfsstats.rpccnt[NFSPROC_LINK],
347 ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
348 ext_nfsstats.rpccnt[NFSPROC_MKDIR],
349 ext_nfsstats.rpccnt[NFSPROC_RMDIR],
350 ext_nfsstats.rpccnt[NFSPROC_READDIR],
351 ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
352 ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
353 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
354 "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
356 printf("%9d %9d %9d %9d %9d\n",
357 nfsstats.rpccnt[NFSPROC_MKNOD],
358 nfsstats.rpccnt[NFSPROC_FSSTAT],
359 nfsstats.rpccnt[NFSPROC_FSINFO],
360 nfsstats.rpccnt[NFSPROC_PATHCONF],
361 nfsstats.rpccnt[NFSPROC_COMMIT]);
363 printf("%9d %9d %9d %9d %9d\n",
364 ext_nfsstats.rpccnt[NFSPROC_MKNOD],
365 ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
366 ext_nfsstats.rpccnt[NFSPROC_FSINFO],
367 ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
368 ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
369 printf("Rpc Info:\n");
370 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
371 "TimedOut", "Invalid", "X Replies", "Retries",
374 printf("%9d %9d %9d %9d %9d\n",
375 nfsstats.rpctimeouts,
377 nfsstats.rpcunexpected,
379 nfsstats.rpcrequests);
381 printf("%9d %9d %9d %9d %9d\n",
382 ext_nfsstats.rpctimeouts,
383 ext_nfsstats.rpcinvalid,
384 ext_nfsstats.rpcunexpected,
385 ext_nfsstats.rpcretries,
386 ext_nfsstats.rpcrequests);
387 printf("Cache Info:\n");
388 printf("%9.9s %9.9s %9.9s %9.9s",
389 "Attr Hits", "Misses", "Lkup Hits", "Misses");
390 printf(" %9.9s %9.9s %9.9s %9.9s\n",
391 "BioR Hits", "Misses", "BioW Hits", "Misses");
393 printf("%9d %9d %9d %9d",
394 nfsstats.attrcache_hits,
395 nfsstats.attrcache_misses,
396 nfsstats.lookupcache_hits,
397 nfsstats.lookupcache_misses);
398 printf(" %9d %9d %9d %9d\n",
399 nfsstats.biocache_reads-nfsstats.read_bios,
401 nfsstats.biocache_writes-nfsstats.write_bios,
402 nfsstats.write_bios);
404 printf("%9d %9d %9d %9d",
405 ext_nfsstats.attrcache_hits,
406 ext_nfsstats.attrcache_misses,
407 ext_nfsstats.lookupcache_hits,
408 ext_nfsstats.lookupcache_misses);
409 printf(" %9d %9d %9d %9d\n",
410 ext_nfsstats.biocache_reads -
411 ext_nfsstats.read_bios,
412 ext_nfsstats.read_bios,
413 ext_nfsstats.biocache_writes -
414 ext_nfsstats.write_bios,
415 ext_nfsstats.write_bios);
417 printf("%9.9s %9.9s %9.9s %9.9s",
418 "BioRLHits", "Misses", "BioD Hits", "Misses");
419 printf(" %9.9s %9.9s %9.9s %9.9s\n", "DirE Hits", "Misses", "Accs Hits", "Misses");
421 printf("%9d %9d %9d %9d",
422 nfsstats.biocache_readlinks -
423 nfsstats.readlink_bios,
424 nfsstats.readlink_bios,
425 nfsstats.biocache_readdirs -
426 nfsstats.readdir_bios,
427 nfsstats.readdir_bios);
428 printf(" %9d %9d %9d %9d\n",
429 nfsstats.direofcache_hits,
430 nfsstats.direofcache_misses,
431 nfsstats.accesscache_hits,
432 nfsstats.accesscache_misses);
434 printf("%9d %9d %9d %9d",
435 ext_nfsstats.biocache_readlinks -
436 ext_nfsstats.readlink_bios,
437 ext_nfsstats.readlink_bios,
438 ext_nfsstats.biocache_readdirs -
439 ext_nfsstats.readdir_bios,
440 ext_nfsstats.readdir_bios);
441 printf(" %9d %9d %9d %9d\n",
442 ext_nfsstats.direofcache_hits,
443 ext_nfsstats.direofcache_misses,
444 ext_nfsstats.accesscache_hits,
445 ext_nfsstats.accesscache_misses);
448 if (run_v4 == 0 && serverOnly && !nfsrvstatsp) {
449 printf("Server not present!\n");
453 printf("\nServer Info:\n");
454 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
455 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
456 "Write", "Create", "Remove");
458 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
459 nfsrvstats.srvrpccnt[NFSPROC_GETATTR],
460 nfsrvstats.srvrpccnt[NFSPROC_SETATTR],
461 nfsrvstats.srvrpccnt[NFSPROC_LOOKUP],
462 nfsrvstats.srvrpccnt[NFSPROC_READLINK],
463 nfsrvstats.srvrpccnt[NFSPROC_READ],
464 nfsrvstats.srvrpccnt[NFSPROC_WRITE],
465 nfsrvstats.srvrpccnt[NFSPROC_CREATE],
466 nfsrvstats.srvrpccnt[NFSPROC_REMOVE]);
468 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
469 ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
470 ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
471 ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
472 ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
473 ext_nfsstats.srvrpccnt[NFSV4OP_READ],
474 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
475 ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
476 ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
477 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
478 "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
479 "Readdir", "RdirPlus", "Access");
481 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
482 nfsrvstats.srvrpccnt[NFSPROC_RENAME],
483 nfsrvstats.srvrpccnt[NFSPROC_LINK],
484 nfsrvstats.srvrpccnt[NFSPROC_SYMLINK],
485 nfsrvstats.srvrpccnt[NFSPROC_MKDIR],
486 nfsrvstats.srvrpccnt[NFSPROC_RMDIR],
487 nfsrvstats.srvrpccnt[NFSPROC_READDIR],
488 nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS],
489 nfsrvstats.srvrpccnt[NFSPROC_ACCESS]);
491 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
492 ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
493 ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
494 ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
495 ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
496 ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
497 ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
498 ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
499 ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
500 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
501 "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
503 printf("%9d %9d %9d %9d %9d\n",
504 nfsrvstats.srvrpccnt[NFSPROC_MKNOD],
505 nfsrvstats.srvrpccnt[NFSPROC_FSSTAT],
506 nfsrvstats.srvrpccnt[NFSPROC_FSINFO],
507 nfsrvstats.srvrpccnt[NFSPROC_PATHCONF],
508 nfsrvstats.srvrpccnt[NFSPROC_COMMIT]);
510 printf("%9d %9d %9d %9d %9d\n",
511 ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
512 ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
513 ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
514 ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
515 ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
516 printf("Server Ret-Failed\n");
518 printf("%17d\n", nfsrvstats.srvrpc_errs);
520 printf("%17d\n", ext_nfsstats.srvrpc_errs);
521 printf("Server Faults\n");
523 printf("%13d\n", nfsrvstats.srv_errs);
525 printf("%13d\n", ext_nfsstats.srv_errs);
526 printf("Server Cache Stats:\n");
527 printf("%9.9s %9.9s %9.9s %9.9s\n",
528 "Inprog", "Idem", "Non-idem", "Misses");
530 printf("%9d %9d %9d %9d\n",
531 nfsrvstats.srvcache_inproghits,
532 nfsrvstats.srvcache_idemdonehits,
533 nfsrvstats.srvcache_nonidemdonehits,
534 nfsrvstats.srvcache_misses);
536 printf("%9d %9d %9d %9d\n",
537 ext_nfsstats.srvcache_inproghits,
538 ext_nfsstats.srvcache_idemdonehits,
539 ext_nfsstats.srvcache_nonidemdonehits,
540 ext_nfsstats.srvcache_misses);
541 printf("Server Write Gathering:\n");
542 printf("%9.9s %9.9s %9.9s\n",
543 "WriteOps", "WriteRPC", "Opsaved");
545 printf("%9d %9d %9d\n",
546 nfsrvstats.srvvop_writes,
547 nfsrvstats.srvrpccnt[NFSPROC_WRITE],
548 nfsrvstats.srvrpccnt[NFSPROC_WRITE] -
549 nfsrvstats.srvvop_writes);
552 * The new client doesn't do write gathering. It was
553 * only useful for NFSv2.
555 printf("%9d %9d %9d\n",
556 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
557 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
561 u_char signalled; /* set if alarm goes off "early" */
564 * Print a running summary of nfs statistics.
565 * Repeat display every interval seconds, showing statistics
566 * collected over that interval. Assumes that interval is non-zero.
567 * First line printed at top of screen is always cumulative.
570 sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
572 struct nfsstats nfsstats, lastst, *nfsstatsp;
573 struct nfsrvstats nfsrvstats, lastsrvst, *nfsrvstatsp;
577 nfsrvstatsp = &lastsrvst;
578 readstats(&nfsstatsp, &nfsrvstatsp, 0);
579 if (clientOnly && !nfsstatsp) {
580 printf("Client not present!\n");
583 if (serverOnly && !nfsrvstatsp) {
584 printf("Server not present!\n");
590 nfsstatsp = &nfsstats;
591 nfsrvstatsp = &nfsrvstats;
592 readstats(&nfsstatsp, &nfsrvstatsp, 0);
595 printhdr(clientOnly, serverOnly);
596 if (clientOnly && serverOnly)
602 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
603 ((clientOnly && serverOnly) ? "Client:" : ""),
604 DELTA(attrcache_hits) + DELTA(attrcache_misses),
605 DELTA(lookupcache_hits) + DELTA(lookupcache_misses),
606 DELTA(biocache_readlinks),
607 DELTA(biocache_reads),
608 DELTA(biocache_writes),
609 nfsstats.rpccnt[NFSPROC_RENAME]-lastst.rpccnt[NFSPROC_RENAME],
610 DELTA(accesscache_hits) + DELTA(accesscache_misses),
611 DELTA(biocache_readdirs)
614 printf(" %s %s %s %s %s %s",
615 sperc1(DELTA(attrcache_hits),
616 DELTA(attrcache_misses)),
617 sperc1(DELTA(lookupcache_hits),
618 DELTA(lookupcache_misses)),
619 sperc2(DELTA(biocache_reads),
621 sperc2(DELTA(biocache_writes),
623 sperc1(DELTA(accesscache_hits),
624 DELTA(accesscache_misses)),
625 sperc2(DELTA(biocache_readdirs),
633 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
634 ((clientOnly && serverOnly) ? "Server:" : ""),
635 nfsrvstats.srvrpccnt[NFSPROC_GETATTR]-lastsrvst.srvrpccnt[NFSPROC_GETATTR],
636 nfsrvstats.srvrpccnt[NFSPROC_LOOKUP]-lastsrvst.srvrpccnt[NFSPROC_LOOKUP],
637 nfsrvstats.srvrpccnt[NFSPROC_READLINK]-lastsrvst.srvrpccnt[NFSPROC_READLINK],
638 nfsrvstats.srvrpccnt[NFSPROC_READ]-lastsrvst.srvrpccnt[NFSPROC_READ],
639 nfsrvstats.srvrpccnt[NFSPROC_WRITE]-lastsrvst.srvrpccnt[NFSPROC_WRITE],
640 nfsrvstats.srvrpccnt[NFSPROC_RENAME]-lastsrvst.srvrpccnt[NFSPROC_RENAME],
641 nfsrvstats.srvrpccnt[NFSPROC_ACCESS]-lastsrvst.srvrpccnt[NFSPROC_ACCESS],
642 (nfsrvstats.srvrpccnt[NFSPROC_READDIR]-lastsrvst.srvrpccnt[NFSPROC_READDIR])
643 +(nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS]-lastsrvst.srvrpccnt[NFSPROC_READDIRPLUS]));
645 lastsrvst = nfsrvstats;
654 printhdr(int clientOnly, int serverOnly)
656 printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
657 ((serverOnly && clientOnly) ? " " : " "),
658 "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename",
660 if (widemode && clientOnly) {
661 printf(" Attr Lkup BioR BioW Accs BioD");
670 (void)fprintf(stderr,
671 "usage: nfsstat [-cemoszW] [-M core] [-N system] [-w wait]\n");
675 static char SPBuf[64][8];
679 sperc1(int hits, int misses)
681 char *p = SPBuf[SPIndex];
685 (int)(char)((quad_t)hits * 100 / (hits + misses)));
689 SPIndex = (SPIndex + 1) & 63;
694 sperc2(int ttl, int misses)
696 char *p = SPBuf[SPIndex];
700 (int)(char)((quad_t)(ttl - misses) * 100 / ttl));
704 SPIndex = (SPIndex + 1) & 63;
709 * Print a description of the nfs stats for the experimental client/server.
712 exp_intpr(int clientOnly, int serverOnly)
716 nfssvc_flag = NFSSVC_GETSTATS;
719 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
721 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
723 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
724 err(1, "Can't get stats");
725 if (clientOnly != 0) {
727 printf("Client Info:\n");
728 printf("Rpc Counts:\n");
730 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
731 , "Getattr", "Setattr", "Lookup", "Readlink",
732 "Read", "Write", "Create", "Remove");
734 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
735 ext_nfsstats.rpccnt[NFSPROC_GETATTR],
736 ext_nfsstats.rpccnt[NFSPROC_SETATTR],
737 ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
738 ext_nfsstats.rpccnt[NFSPROC_READLINK],
739 ext_nfsstats.rpccnt[NFSPROC_READ],
740 ext_nfsstats.rpccnt[NFSPROC_WRITE],
741 ext_nfsstats.rpccnt[NFSPROC_CREATE],
742 ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
745 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
746 , "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
747 "Readdir", "RdirPlus", "Access");
748 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
749 ext_nfsstats.rpccnt[NFSPROC_RENAME],
750 ext_nfsstats.rpccnt[NFSPROC_LINK],
751 ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
752 ext_nfsstats.rpccnt[NFSPROC_MKDIR],
753 ext_nfsstats.rpccnt[NFSPROC_RMDIR],
754 ext_nfsstats.rpccnt[NFSPROC_READDIR],
755 ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
756 ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
759 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
760 , "Mknod", "Fsstat", "Fsinfo", "PathConf",
761 "Commit", "SetClId", "SetClIdCf", "Lock");
762 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
763 ext_nfsstats.rpccnt[NFSPROC_MKNOD],
764 ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
765 ext_nfsstats.rpccnt[NFSPROC_FSINFO],
766 ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
767 ext_nfsstats.rpccnt[NFSPROC_COMMIT],
768 ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID],
769 ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM],
770 ext_nfsstats.rpccnt[NFSPROC_LOCK]);
772 printf("%9.9s %9.9s %9.9s %9.9s\n",
773 "LockT", "LockU", "Open", "OpenCfr");
774 printf("%9d %9d %9d %9d\n",
775 ext_nfsstats.rpccnt[NFSPROC_LOCKT],
776 ext_nfsstats.rpccnt[NFSPROC_LOCKU],
777 ext_nfsstats.rpccnt[NFSPROC_OPEN],
778 ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]);
781 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
782 , "OpenOwner", "Opens", "LockOwner",
783 "Locks", "Delegs", "LocalOwn",
784 "LocalOpen", "LocalLOwn");
785 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
786 ext_nfsstats.clopenowners,
787 ext_nfsstats.clopens,
788 ext_nfsstats.cllockowners,
789 ext_nfsstats.cllocks,
790 ext_nfsstats.cldelegates,
791 ext_nfsstats.cllocalopenowners,
792 ext_nfsstats.cllocalopens,
793 ext_nfsstats.cllocallockowners);
795 printf("%9.9s\n", "LocalLock");
796 printf("%9d\n", ext_nfsstats.cllocallocks);
798 printf("Rpc Info:\n");
799 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
800 "TimedOut", "Invalid", "X Replies", "Retries",
803 printf("%9d %9d %9d %9d %9d\n",
804 ext_nfsstats.rpctimeouts,
805 ext_nfsstats.rpcinvalid,
806 ext_nfsstats.rpcunexpected,
807 ext_nfsstats.rpcretries,
808 ext_nfsstats.rpcrequests);
810 printf("Cache Info:\n");
811 printf("%9.9s %9.9s %9.9s %9.9s",
812 "Attr Hits", "Misses", "Lkup Hits", "Misses");
813 printf(" %9.9s %9.9s %9.9s %9.9s\n",
814 "BioR Hits", "Misses", "BioW Hits", "Misses");
816 printf("%9d %9d %9d %9d",
817 ext_nfsstats.attrcache_hits,
818 ext_nfsstats.attrcache_misses,
819 ext_nfsstats.lookupcache_hits,
820 ext_nfsstats.lookupcache_misses);
821 printf(" %9d %9d %9d %9d\n",
822 ext_nfsstats.biocache_reads - ext_nfsstats.read_bios,
823 ext_nfsstats.read_bios,
824 ext_nfsstats.biocache_writes - ext_nfsstats.write_bios,
825 ext_nfsstats.write_bios);
827 printf("%9.9s %9.9s %9.9s %9.9s",
828 "BioRLHits", "Misses", "BioD Hits", "Misses");
829 printf(" %9.9s %9.9s\n", "DirE Hits", "Misses");
831 printf("%9d %9d %9d %9d",
832 ext_nfsstats.biocache_readlinks -
833 ext_nfsstats.readlink_bios,
834 ext_nfsstats.readlink_bios,
835 ext_nfsstats.biocache_readdirs -
836 ext_nfsstats.readdir_bios,
837 ext_nfsstats.readdir_bios);
839 ext_nfsstats.direofcache_hits,
840 ext_nfsstats.direofcache_misses);
842 if (serverOnly != 0) {
844 printf("\nServer Info:\n");
846 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
847 , "Getattr", "Setattr", "Lookup", "Readlink",
848 "Read", "Write", "Create", "Remove");
850 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
851 ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
852 ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
853 ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
854 ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
855 ext_nfsstats.srvrpccnt[NFSV4OP_READ],
856 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
857 ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE],
858 ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
861 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
862 , "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
863 "Readdir", "RdirPlus", "Access");
864 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
865 ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
866 ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
867 ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
868 ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
869 ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
870 ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
871 ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
872 ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
875 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
876 , "Mknod", "Fsstat", "Fsinfo", "PathConf",
877 "Commit", "LookupP", "SetClId", "SetClIdCf");
878 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
879 ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
880 ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
881 ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
882 ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
883 ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT],
884 ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP],
885 ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID],
886 ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]);
889 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
890 , "Open", "OpenAttr", "OpenDwnGr", "OpenCfrm",
891 "DelePurge", "DeleRet", "GetFH", "Lock");
892 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
893 ext_nfsstats.srvrpccnt[NFSV4OP_OPEN],
894 ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR],
895 ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE],
896 ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM],
897 ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE],
898 ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN],
899 ext_nfsstats.srvrpccnt[NFSV4OP_GETFH],
900 ext_nfsstats.srvrpccnt[NFSV4OP_LOCK]);
903 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
904 , "LockT", "LockU", "Close", "Verify", "NVerify",
905 "PutFH", "PutPubFH", "PutRootFH");
906 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
907 ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT],
908 ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU],
909 ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE],
910 ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY],
911 ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY],
912 ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH],
913 ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH],
914 ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH]);
916 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
917 "Renew", "RestoreFH", "SaveFH", "Secinfo",
918 "RelLckOwn", "V4Create");
919 printf("%9d %9d %9d %9d %9d %9d\n",
920 ext_nfsstats.srvrpccnt[NFSV4OP_RENEW],
921 ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH],
922 ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH],
923 ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO],
924 ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN],
925 ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]);
928 printf("%9.9s %9.9s %9.9s\n",
929 "Retfailed", "Faults", "Clients");
931 printf("%9d %9d %9d\n",
932 ext_nfsstats.srv_errs, ext_nfsstats.srvrpc_errs,
933 ext_nfsstats.srvclients);
935 printf("%9.9s %9.9s %9.9s %9.9s %9.9s \n",
936 "OpenOwner", "Opens", "LockOwner",
938 printf("%9d %9d %9d %9d %9d \n",
939 ext_nfsstats.srvopenowners,
940 ext_nfsstats.srvopens,
941 ext_nfsstats.srvlockowners,
942 ext_nfsstats.srvlocks,
943 ext_nfsstats.srvdelegates);
945 printf("Server Cache Stats:\n");
946 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
947 "Inprog", "Idem", "Non-idem", "Misses",
948 "CacheSize", "TCPPeak");
950 printf("%9d %9d %9d %9d %9d %9d\n",
951 ext_nfsstats.srvcache_inproghits,
952 ext_nfsstats.srvcache_idemdonehits,
953 ext_nfsstats.srvcache_nonidemdonehits,
954 ext_nfsstats.srvcache_misses,
955 ext_nfsstats.srvcache_size,
956 ext_nfsstats.srvcache_tcppeak);
961 * Print a running summary of nfs statistics for the experimental client and/or
963 * Repeat display every interval seconds, showing statistics
964 * collected over that interval. Assumes that interval is non-zero.
965 * First line printed at top of screen is always cumulative.
968 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
970 struct ext_nfsstats nfsstats, lastst, *ext_nfsstatsp;
973 ext_nfsstatsp = &lastst;
974 if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
975 err(1, "Can't get stats");
979 ext_nfsstatsp = &nfsstats;
980 if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
981 err(1, "Can't get stats");
984 printhdr(clientOnly, serverOnly);
985 if (clientOnly && serverOnly)
991 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
992 ((clientOnly && serverOnly) ? "Client:" : ""),
993 DELTA(attrcache_hits) + DELTA(attrcache_misses),
994 DELTA(lookupcache_hits) + DELTA(lookupcache_misses),
995 DELTA(biocache_readlinks),
996 DELTA(biocache_reads),
997 DELTA(biocache_writes),
998 nfsstats.rpccnt[NFSPROC_RENAME] -
999 lastst.rpccnt[NFSPROC_RENAME],
1000 DELTA(accesscache_hits) + DELTA(accesscache_misses),
1001 DELTA(biocache_readdirs)
1004 printf(" %s %s %s %s %s %s",
1005 sperc1(DELTA(attrcache_hits),
1006 DELTA(attrcache_misses)),
1007 sperc1(DELTA(lookupcache_hits),
1008 DELTA(lookupcache_misses)),
1009 sperc2(DELTA(biocache_reads),
1011 sperc2(DELTA(biocache_writes),
1013 sperc1(DELTA(accesscache_hits),
1014 DELTA(accesscache_misses)),
1015 sperc2(DELTA(biocache_readdirs),
1016 DELTA(readdir_bios))
1023 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
1024 ((clientOnly && serverOnly) ? "Server:" : ""),
1025 nfsstats.srvrpccnt[NFSV4OP_GETATTR] -
1026 lastst.srvrpccnt[NFSV4OP_GETATTR],
1027 nfsstats.srvrpccnt[NFSV4OP_LOOKUP] -
1028 lastst.srvrpccnt[NFSV4OP_LOOKUP],
1029 nfsstats.srvrpccnt[NFSV4OP_READLINK] -
1030 lastst.srvrpccnt[NFSV4OP_READLINK],
1031 nfsstats.srvrpccnt[NFSV4OP_READ] -
1032 lastst.srvrpccnt[NFSV4OP_READ],
1033 nfsstats.srvrpccnt[NFSV4OP_WRITE] -
1034 lastst.srvrpccnt[NFSV4OP_WRITE],
1035 nfsstats.srvrpccnt[NFSV4OP_RENAME] -
1036 lastst.srvrpccnt[NFSV4OP_RENAME],
1037 nfsstats.srvrpccnt[NFSV4OP_ACCESS] -
1038 lastst.srvrpccnt[NFSV4OP_ACCESS],
1039 (nfsstats.srvrpccnt[NFSV4OP_READDIR] -
1040 lastst.srvrpccnt[NFSV4OP_READDIR]) +
1041 (nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS] -
1042 lastst.srvrpccnt[NFSV4OP_READDIRPLUS]));