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);
136 else if (errno == EPERM)
137 errx(1, "Only priviledged users"
138 " can use the -m option");
150 interval = atoi(optarg);
166 if (extra_output != 0)
167 err(1, "-o incompatible with -e");
172 err(1, "-e incompatible with -o");
182 #define BACKWARD_COMPATIBILITY
183 #ifdef BACKWARD_COMPATIBILITY
185 interval = atoi(*argv);
193 if (run_v4 != 0 && modfind("nfscommon") < 0)
194 errx(1, "new client/server not loaded");
196 if (run_v4 == 0 && (nlistf != NULL || memf != NULL)) {
199 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
201 errx(1, "kvm_openfiles: %s", errbuf);
203 if (kvm_nlist(kd, nl) != 0) {
204 errx(1, "kvm_nlist: can't get names");
210 exp_sidewaysintpr(interval, clientOnly, serverOnly);
212 sidewaysintpr(interval, clientOnly, serverOnly);
214 if (extra_output != 0)
215 exp_intpr(clientOnly, serverOnly);
217 intpr(clientOnly, serverOnly);
223 * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
227 readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
230 struct nfsstats client;
231 struct nfsrvstats server;
236 if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
237 *stp, sizeof(struct nfsstats)) < 0) {
240 if (*srvstp != NULL && kvm_read(kd,
241 (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
242 sizeof(struct nfsrvstats)) < 0) {
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) {
252 err(1, "sysctl: vfs.oldnfs.nfsstats");
255 buflen = sizeof(struct nfsrvstats);
256 if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
257 *srvstp, &buflen, zero ? &zerostat : NULL,
258 zero ? buflen : 0) < 0) {
260 err(1, "sysctl: vfs.nfsrv.nfsrvstats");
267 * Print a description of the nfs stats.
270 intpr(int clientOnly, int serverOnly)
272 struct nfsstats nfsstats, *nfsstatsp;
273 struct nfsrvstats nfsrvstats, *nfsrvstatsp;
278 * Only read the stats we are going to display to avoid zeroing
279 * stats the user didn't request.
282 nfsstatsp = &nfsstats;
286 nfsrvstatsp = &nfsrvstats;
290 readstats(&nfsstatsp, &nfsrvstatsp, zflag);
292 if (clientOnly && !nfsstatsp) {
293 printf("Client not present!\n");
297 nfssvc_flag = NFSSVC_GETSTATS;
300 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
302 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
304 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
305 err(1, "Can't get stats");
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");
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]);
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");
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]);
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");
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]);
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",
377 printf("%9d %9d %9d %9d %9d\n",
378 nfsstats.rpctimeouts,
380 nfsstats.rpcunexpected,
382 nfsstats.rpcrequests);
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");
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,
404 nfsstats.biocache_writes-nfsstats.write_bios,
405 nfsstats.write_bios);
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);
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");
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);
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);
451 if (run_v4 == 0 && serverOnly && !nfsrvstatsp) {
452 printf("Server not present!\n");
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");
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]);
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");
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]);
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");
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]);
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");
521 printf("%17d\n", nfsrvstats.srvrpc_errs);
523 printf("%17d\n", ext_nfsstats.srvrpc_errs);
524 printf("Server Faults\n");
526 printf("%13d\n", nfsrvstats.srv_errs);
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");
533 printf("%9d %9d %9d %9d\n",
534 nfsrvstats.srvcache_inproghits,
535 nfsrvstats.srvcache_idemdonehits,
536 nfsrvstats.srvcache_nonidemdonehits,
537 nfsrvstats.srvcache_misses);
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");
548 printf("%9d %9d %9d\n",
549 nfsrvstats.srvvop_writes,
550 nfsrvstats.srvrpccnt[NFSPROC_WRITE],
551 nfsrvstats.srvrpccnt[NFSPROC_WRITE] -
552 nfsrvstats.srvvop_writes);
555 * The new client doesn't do write gathering. It was
556 * only useful for NFSv2.
558 printf("%9d %9d %9d\n",
559 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
560 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
564 u_char signalled; /* set if alarm goes off "early" */
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.
573 sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
575 struct nfsstats nfsstats, lastst, *nfsstatsp;
576 struct nfsrvstats nfsrvstats, lastsrvst, *nfsrvstatsp;
580 nfsrvstatsp = &lastsrvst;
581 readstats(&nfsstatsp, &nfsrvstatsp, 0);
582 if (clientOnly && !nfsstatsp) {
583 printf("Client not present!\n");
586 if (serverOnly && !nfsrvstatsp) {
587 printf("Server not present!\n");
593 nfsstatsp = &nfsstats;
594 nfsrvstatsp = &nfsrvstats;
595 readstats(&nfsstatsp, &nfsrvstatsp, 0);
598 printhdr(clientOnly, serverOnly);
599 if (clientOnly && serverOnly)
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])
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),
625 sperc2(DELTA(biocache_writes),
627 sperc1(DELTA(accesscache_hits),
628 DELTA(accesscache_misses)),
629 sperc2(DELTA(biocache_readdirs),
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]));
649 lastsrvst = nfsrvstats;
658 printhdr(int clientOnly, int serverOnly)
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",
664 if (widemode && clientOnly) {
665 printf(" Attr Lkup BioR BioW Accs BioD");
674 (void)fprintf(stderr,
675 "usage: nfsstat [-cemoszW] [-M core] [-N system] [-w wait]\n");
679 static char SPBuf[64][8];
683 sperc1(int hits, int misses)
685 char *p = SPBuf[SPIndex];
689 (int)(char)((quad_t)hits * 100 / (hits + misses)));
693 SPIndex = (SPIndex + 1) & 63;
698 sperc2(int ttl, int misses)
700 char *p = SPBuf[SPIndex];
704 (int)(char)((quad_t)(ttl - misses) * 100 / ttl));
708 SPIndex = (SPIndex + 1) & 63;
713 * Print a description of the nfs stats for the experimental client/server.
716 exp_intpr(int clientOnly, int serverOnly)
720 nfssvc_flag = NFSSVC_GETSTATS;
723 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
725 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
727 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
728 err(1, "Can't get stats");
729 if (clientOnly != 0) {
731 printf("Client Info:\n");
732 printf("Rpc Counts:\n");
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");
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]);
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]);
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]);
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]);
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);
799 printf("%9.9s\n", "LocalLock");
800 printf("%9d\n", ext_nfsstats.cllocallocks);
802 printf("Rpc Info:\n");
803 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
804 "TimedOut", "Invalid", "X Replies", "Retries",
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);
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");
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);
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");
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);
843 ext_nfsstats.direofcache_hits,
844 ext_nfsstats.direofcache_misses);
846 if (serverOnly != 0) {
848 printf("\nServer Info:\n");
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");
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]);
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]);
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]);
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]);
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]);
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]);
932 printf("%9.9s %9.9s %9.9s\n",
933 "Retfailed", "Faults", "Clients");
935 printf("%9d %9d %9d\n",
936 ext_nfsstats.srv_errs, ext_nfsstats.srvrpc_errs,
937 ext_nfsstats.srvclients);
939 printf("%9.9s %9.9s %9.9s %9.9s %9.9s \n",
940 "OpenOwner", "Opens", "LockOwner",
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);
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");
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);
965 * Print a running summary of nfs statistics for the experimental client and/or
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.
972 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
974 struct ext_nfsstats nfsstats, lastst, *ext_nfsstatsp;
977 ext_nfsstatsp = &lastst;
978 if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
979 err(1, "Can't get stats");
983 ext_nfsstatsp = &nfsstats;
984 if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
985 err(1, "Can't get stats");
988 printhdr(clientOnly, serverOnly);
989 if (clientOnly && serverOnly)
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])
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),
1015 sperc2(DELTA(biocache_writes),
1017 sperc1(DELTA(accesscache_hits),
1018 DELTA(accesscache_misses)),
1019 sperc2(DELTA(biocache_readdirs),
1020 DELTA(readdir_bios))
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]));