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 memf = nlistf = NULL;
113 while ((ch = getopt(argc, argv, "cesWM:N:ow:z")) != -1)
125 interval = atoi(optarg);
141 if (extra_output != 0)
142 err(1, "-o incompatible with -e");
147 err(1, "-e incompatible with -o");
157 #define BACKWARD_COMPATIBILITY
158 #ifdef BACKWARD_COMPATIBILITY
160 interval = atoi(*argv);
168 if (run_v4 != 0 && modfind("nfscommon") < 0)
169 errx(1, "new client/server not loaded");
171 if (run_v4 == 0 && (nlistf != NULL || memf != NULL)) {
174 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY,
176 errx(1, "kvm_openfiles: %s", errbuf);
178 if (kvm_nlist(kd, nl) != 0) {
179 errx(1, "kvm_nlist: can't get names");
185 exp_sidewaysintpr(interval, clientOnly, serverOnly);
187 sidewaysintpr(interval, clientOnly, serverOnly);
189 if (extra_output != 0)
190 exp_intpr(clientOnly, serverOnly);
192 intpr(clientOnly, serverOnly);
198 * Read the nfs stats using sysctl(3) for live kernels, or kvm_read
202 readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
205 struct nfsstats client;
206 struct nfsrvstats server;
211 if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
212 *stp, sizeof(struct nfsstats)) < 0) {
215 if (*srvstp != NULL && kvm_read(kd,
216 (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
217 sizeof(struct nfsrvstats)) < 0) {
222 bzero(&zerostat, sizeof(zerostat));
223 buflen = sizeof(struct nfsstats);
224 if (*stp != NULL && sysctlbyname("vfs.oldnfs.nfsstats", *stp,
225 &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
227 err(1, "sysctl: vfs.oldnfs.nfsstats");
230 buflen = sizeof(struct nfsrvstats);
231 if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
232 *srvstp, &buflen, zero ? &zerostat : NULL,
233 zero ? buflen : 0) < 0) {
235 err(1, "sysctl: vfs.nfsrv.nfsrvstats");
242 * Print a description of the nfs stats.
245 intpr(int clientOnly, int serverOnly)
247 struct nfsstats nfsstats, *nfsstatsp;
248 struct nfsrvstats nfsrvstats, *nfsrvstatsp;
253 * Only read the stats we are going to display to avoid zeroing
254 * stats the user didn't request.
257 nfsstatsp = &nfsstats;
261 nfsrvstatsp = &nfsrvstats;
265 readstats(&nfsstatsp, &nfsrvstatsp, zflag);
267 if (clientOnly && !nfsstatsp) {
268 printf("Client not present!\n");
272 nfssvc_flag = NFSSVC_GETSTATS;
275 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
277 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
279 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
280 err(1, "Can't get stats");
283 printf("Client Info:\n");
284 printf("Rpc Counts:\n");
285 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
286 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
287 "Write", "Create", "Remove");
289 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
290 nfsstats.rpccnt[NFSPROC_GETATTR],
291 nfsstats.rpccnt[NFSPROC_SETATTR],
292 nfsstats.rpccnt[NFSPROC_LOOKUP],
293 nfsstats.rpccnt[NFSPROC_READLINK],
294 nfsstats.rpccnt[NFSPROC_READ],
295 nfsstats.rpccnt[NFSPROC_WRITE],
296 nfsstats.rpccnt[NFSPROC_CREATE],
297 nfsstats.rpccnt[NFSPROC_REMOVE]);
299 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
300 ext_nfsstats.rpccnt[NFSPROC_GETATTR],
301 ext_nfsstats.rpccnt[NFSPROC_SETATTR],
302 ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
303 ext_nfsstats.rpccnt[NFSPROC_READLINK],
304 ext_nfsstats.rpccnt[NFSPROC_READ],
305 ext_nfsstats.rpccnt[NFSPROC_WRITE],
306 ext_nfsstats.rpccnt[NFSPROC_CREATE],
307 ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
308 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
309 "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
310 "Readdir", "RdirPlus", "Access");
312 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
313 nfsstats.rpccnt[NFSPROC_RENAME],
314 nfsstats.rpccnt[NFSPROC_LINK],
315 nfsstats.rpccnt[NFSPROC_SYMLINK],
316 nfsstats.rpccnt[NFSPROC_MKDIR],
317 nfsstats.rpccnt[NFSPROC_RMDIR],
318 nfsstats.rpccnt[NFSPROC_READDIR],
319 nfsstats.rpccnt[NFSPROC_READDIRPLUS],
320 nfsstats.rpccnt[NFSPROC_ACCESS]);
322 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
323 ext_nfsstats.rpccnt[NFSPROC_RENAME],
324 ext_nfsstats.rpccnt[NFSPROC_LINK],
325 ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
326 ext_nfsstats.rpccnt[NFSPROC_MKDIR],
327 ext_nfsstats.rpccnt[NFSPROC_RMDIR],
328 ext_nfsstats.rpccnt[NFSPROC_READDIR],
329 ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
330 ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
331 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
332 "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
334 printf("%9d %9d %9d %9d %9d\n",
335 nfsstats.rpccnt[NFSPROC_MKNOD],
336 nfsstats.rpccnt[NFSPROC_FSSTAT],
337 nfsstats.rpccnt[NFSPROC_FSINFO],
338 nfsstats.rpccnt[NFSPROC_PATHCONF],
339 nfsstats.rpccnt[NFSPROC_COMMIT]);
341 printf("%9d %9d %9d %9d %9d\n",
342 ext_nfsstats.rpccnt[NFSPROC_MKNOD],
343 ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
344 ext_nfsstats.rpccnt[NFSPROC_FSINFO],
345 ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
346 ext_nfsstats.rpccnt[NFSPROC_COMMIT]);
347 printf("Rpc Info:\n");
348 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
349 "TimedOut", "Invalid", "X Replies", "Retries",
352 printf("%9d %9d %9d %9d %9d\n",
353 nfsstats.rpctimeouts,
355 nfsstats.rpcunexpected,
357 nfsstats.rpcrequests);
359 printf("%9d %9d %9d %9d %9d\n",
360 ext_nfsstats.rpctimeouts,
361 ext_nfsstats.rpcinvalid,
362 ext_nfsstats.rpcunexpected,
363 ext_nfsstats.rpcretries,
364 ext_nfsstats.rpcrequests);
365 printf("Cache Info:\n");
366 printf("%9.9s %9.9s %9.9s %9.9s",
367 "Attr Hits", "Misses", "Lkup Hits", "Misses");
368 printf(" %9.9s %9.9s %9.9s %9.9s\n",
369 "BioR Hits", "Misses", "BioW Hits", "Misses");
371 printf("%9d %9d %9d %9d",
372 nfsstats.attrcache_hits,
373 nfsstats.attrcache_misses,
374 nfsstats.lookupcache_hits,
375 nfsstats.lookupcache_misses);
376 printf(" %9d %9d %9d %9d\n",
377 nfsstats.biocache_reads-nfsstats.read_bios,
379 nfsstats.biocache_writes-nfsstats.write_bios,
380 nfsstats.write_bios);
382 printf("%9d %9d %9d %9d",
383 ext_nfsstats.attrcache_hits,
384 ext_nfsstats.attrcache_misses,
385 ext_nfsstats.lookupcache_hits,
386 ext_nfsstats.lookupcache_misses);
387 printf(" %9d %9d %9d %9d\n",
388 ext_nfsstats.biocache_reads -
389 ext_nfsstats.read_bios,
390 ext_nfsstats.read_bios,
391 ext_nfsstats.biocache_writes -
392 ext_nfsstats.write_bios,
393 ext_nfsstats.write_bios);
395 printf("%9.9s %9.9s %9.9s %9.9s",
396 "BioRLHits", "Misses", "BioD Hits", "Misses");
397 printf(" %9.9s %9.9s %9.9s %9.9s\n", "DirE Hits", "Misses", "Accs Hits", "Misses");
399 printf("%9d %9d %9d %9d",
400 nfsstats.biocache_readlinks -
401 nfsstats.readlink_bios,
402 nfsstats.readlink_bios,
403 nfsstats.biocache_readdirs -
404 nfsstats.readdir_bios,
405 nfsstats.readdir_bios);
406 printf(" %9d %9d %9d %9d\n",
407 nfsstats.direofcache_hits,
408 nfsstats.direofcache_misses,
409 nfsstats.accesscache_hits,
410 nfsstats.accesscache_misses);
412 printf("%9d %9d %9d %9d",
413 ext_nfsstats.biocache_readlinks -
414 ext_nfsstats.readlink_bios,
415 ext_nfsstats.readlink_bios,
416 ext_nfsstats.biocache_readdirs -
417 ext_nfsstats.readdir_bios,
418 ext_nfsstats.readdir_bios);
419 printf(" %9d %9d %9d %9d\n",
420 ext_nfsstats.direofcache_hits,
421 ext_nfsstats.direofcache_misses,
422 ext_nfsstats.accesscache_hits,
423 ext_nfsstats.accesscache_misses);
426 if (run_v4 == 0 && serverOnly && !nfsrvstatsp) {
427 printf("Server not present!\n");
431 printf("\nServer Info:\n");
432 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
433 "Getattr", "Setattr", "Lookup", "Readlink", "Read",
434 "Write", "Create", "Remove");
436 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
437 nfsrvstats.srvrpccnt[NFSPROC_GETATTR],
438 nfsrvstats.srvrpccnt[NFSPROC_SETATTR],
439 nfsrvstats.srvrpccnt[NFSPROC_LOOKUP],
440 nfsrvstats.srvrpccnt[NFSPROC_READLINK],
441 nfsrvstats.srvrpccnt[NFSPROC_READ],
442 nfsrvstats.srvrpccnt[NFSPROC_WRITE],
443 nfsrvstats.srvrpccnt[NFSPROC_CREATE],
444 nfsrvstats.srvrpccnt[NFSPROC_REMOVE]);
446 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
447 ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
448 ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
449 ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
450 ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
451 ext_nfsstats.srvrpccnt[NFSV4OP_READ],
452 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
453 ext_nfsstats.srvrpccnt[NFSV4OP_CREATE],
454 ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
455 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
456 "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
457 "Readdir", "RdirPlus", "Access");
459 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
460 nfsrvstats.srvrpccnt[NFSPROC_RENAME],
461 nfsrvstats.srvrpccnt[NFSPROC_LINK],
462 nfsrvstats.srvrpccnt[NFSPROC_SYMLINK],
463 nfsrvstats.srvrpccnt[NFSPROC_MKDIR],
464 nfsrvstats.srvrpccnt[NFSPROC_RMDIR],
465 nfsrvstats.srvrpccnt[NFSPROC_READDIR],
466 nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS],
467 nfsrvstats.srvrpccnt[NFSPROC_ACCESS]);
469 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
470 ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
471 ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
472 ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
473 ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
474 ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
475 ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
476 ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
477 ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
478 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
479 "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit");
481 printf("%9d %9d %9d %9d %9d\n",
482 nfsrvstats.srvrpccnt[NFSPROC_MKNOD],
483 nfsrvstats.srvrpccnt[NFSPROC_FSSTAT],
484 nfsrvstats.srvrpccnt[NFSPROC_FSINFO],
485 nfsrvstats.srvrpccnt[NFSPROC_PATHCONF],
486 nfsrvstats.srvrpccnt[NFSPROC_COMMIT]);
488 printf("%9d %9d %9d %9d %9d\n",
489 ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
490 ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
491 ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
492 ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
493 ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]);
494 printf("Server Ret-Failed\n");
496 printf("%17d\n", nfsrvstats.srvrpc_errs);
498 printf("%17d\n", ext_nfsstats.srvrpc_errs);
499 printf("Server Faults\n");
501 printf("%13d\n", nfsrvstats.srv_errs);
503 printf("%13d\n", ext_nfsstats.srv_errs);
504 printf("Server Cache Stats:\n");
505 printf("%9.9s %9.9s %9.9s %9.9s\n",
506 "Inprog", "Idem", "Non-idem", "Misses");
508 printf("%9d %9d %9d %9d\n",
509 nfsrvstats.srvcache_inproghits,
510 nfsrvstats.srvcache_idemdonehits,
511 nfsrvstats.srvcache_nonidemdonehits,
512 nfsrvstats.srvcache_misses);
514 printf("%9d %9d %9d %9d\n",
515 ext_nfsstats.srvcache_inproghits,
516 ext_nfsstats.srvcache_idemdonehits,
517 ext_nfsstats.srvcache_nonidemdonehits,
518 ext_nfsstats.srvcache_misses);
519 printf("Server Write Gathering:\n");
520 printf("%9.9s %9.9s %9.9s\n",
521 "WriteOps", "WriteRPC", "Opsaved");
523 printf("%9d %9d %9d\n",
524 nfsrvstats.srvvop_writes,
525 nfsrvstats.srvrpccnt[NFSPROC_WRITE],
526 nfsrvstats.srvrpccnt[NFSPROC_WRITE] -
527 nfsrvstats.srvvop_writes);
530 * The new client doesn't do write gathering. It was
531 * only useful for NFSv2.
533 printf("%9d %9d %9d\n",
534 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
535 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0);
539 u_char signalled; /* set if alarm goes off "early" */
542 * Print a running summary of nfs statistics.
543 * Repeat display every interval seconds, showing statistics
544 * collected over that interval. Assumes that interval is non-zero.
545 * First line printed at top of screen is always cumulative.
548 sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
550 struct nfsstats nfsstats, lastst, *nfsstatsp;
551 struct nfsrvstats nfsrvstats, lastsrvst, *nfsrvstatsp;
555 nfsrvstatsp = &lastsrvst;
556 readstats(&nfsstatsp, &nfsrvstatsp, 0);
557 if (clientOnly && !nfsstatsp) {
558 printf("Client not present!\n");
561 if (serverOnly && !nfsrvstatsp) {
562 printf("Server not present!\n");
568 nfsstatsp = &nfsstats;
569 nfsrvstatsp = &nfsrvstats;
570 readstats(&nfsstatsp, &nfsrvstatsp, 0);
573 printhdr(clientOnly, serverOnly);
574 if (clientOnly && serverOnly)
580 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
581 ((clientOnly && serverOnly) ? "Client:" : ""),
582 DELTA(attrcache_hits) + DELTA(attrcache_misses),
583 DELTA(lookupcache_hits) + DELTA(lookupcache_misses),
584 DELTA(biocache_readlinks),
585 DELTA(biocache_reads),
586 DELTA(biocache_writes),
587 nfsstats.rpccnt[NFSPROC_RENAME]-lastst.rpccnt[NFSPROC_RENAME],
588 DELTA(accesscache_hits) + DELTA(accesscache_misses),
589 DELTA(biocache_readdirs)
592 printf(" %s %s %s %s %s %s",
593 sperc1(DELTA(attrcache_hits),
594 DELTA(attrcache_misses)),
595 sperc1(DELTA(lookupcache_hits),
596 DELTA(lookupcache_misses)),
597 sperc2(DELTA(biocache_reads),
599 sperc2(DELTA(biocache_writes),
601 sperc1(DELTA(accesscache_hits),
602 DELTA(accesscache_misses)),
603 sperc2(DELTA(biocache_readdirs),
611 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
612 ((clientOnly && serverOnly) ? "Server:" : ""),
613 nfsrvstats.srvrpccnt[NFSPROC_GETATTR]-lastsrvst.srvrpccnt[NFSPROC_GETATTR],
614 nfsrvstats.srvrpccnt[NFSPROC_LOOKUP]-lastsrvst.srvrpccnt[NFSPROC_LOOKUP],
615 nfsrvstats.srvrpccnt[NFSPROC_READLINK]-lastsrvst.srvrpccnt[NFSPROC_READLINK],
616 nfsrvstats.srvrpccnt[NFSPROC_READ]-lastsrvst.srvrpccnt[NFSPROC_READ],
617 nfsrvstats.srvrpccnt[NFSPROC_WRITE]-lastsrvst.srvrpccnt[NFSPROC_WRITE],
618 nfsrvstats.srvrpccnt[NFSPROC_RENAME]-lastsrvst.srvrpccnt[NFSPROC_RENAME],
619 nfsrvstats.srvrpccnt[NFSPROC_ACCESS]-lastsrvst.srvrpccnt[NFSPROC_ACCESS],
620 (nfsrvstats.srvrpccnt[NFSPROC_READDIR]-lastsrvst.srvrpccnt[NFSPROC_READDIR])
621 +(nfsrvstats.srvrpccnt[NFSPROC_READDIRPLUS]-lastsrvst.srvrpccnt[NFSPROC_READDIRPLUS]));
623 lastsrvst = nfsrvstats;
632 printhdr(int clientOnly, int serverOnly)
634 printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s",
635 ((serverOnly && clientOnly) ? " " : " "),
636 "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename",
638 if (widemode && clientOnly) {
639 printf(" Attr Lkup BioR BioW Accs BioD");
648 (void)fprintf(stderr,
649 "usage: nfsstat [-ceoszW] [-M core] [-N system] [-w wait]\n");
653 static char SPBuf[64][8];
657 sperc1(int hits, int misses)
659 char *p = SPBuf[SPIndex];
663 (int)(char)((quad_t)hits * 100 / (hits + misses)));
667 SPIndex = (SPIndex + 1) & 63;
672 sperc2(int ttl, int misses)
674 char *p = SPBuf[SPIndex];
678 (int)(char)((quad_t)(ttl - misses) * 100 / ttl));
682 SPIndex = (SPIndex + 1) & 63;
687 * Print a description of the nfs stats for the experimental client/server.
690 exp_intpr(int clientOnly, int serverOnly)
694 nfssvc_flag = NFSSVC_GETSTATS;
697 nfssvc_flag |= NFSSVC_ZEROCLTSTATS;
699 nfssvc_flag |= NFSSVC_ZEROSRVSTATS;
701 if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0)
702 err(1, "Can't get stats");
703 if (clientOnly != 0) {
705 printf("Client Info:\n");
706 printf("Rpc Counts:\n");
708 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
709 , "Getattr", "Setattr", "Lookup", "Readlink",
710 "Read", "Write", "Create", "Remove");
712 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
713 ext_nfsstats.rpccnt[NFSPROC_GETATTR],
714 ext_nfsstats.rpccnt[NFSPROC_SETATTR],
715 ext_nfsstats.rpccnt[NFSPROC_LOOKUP],
716 ext_nfsstats.rpccnt[NFSPROC_READLINK],
717 ext_nfsstats.rpccnt[NFSPROC_READ],
718 ext_nfsstats.rpccnt[NFSPROC_WRITE],
719 ext_nfsstats.rpccnt[NFSPROC_CREATE],
720 ext_nfsstats.rpccnt[NFSPROC_REMOVE]);
723 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
724 , "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
725 "Readdir", "RdirPlus", "Access");
726 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
727 ext_nfsstats.rpccnt[NFSPROC_RENAME],
728 ext_nfsstats.rpccnt[NFSPROC_LINK],
729 ext_nfsstats.rpccnt[NFSPROC_SYMLINK],
730 ext_nfsstats.rpccnt[NFSPROC_MKDIR],
731 ext_nfsstats.rpccnt[NFSPROC_RMDIR],
732 ext_nfsstats.rpccnt[NFSPROC_READDIR],
733 ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS],
734 ext_nfsstats.rpccnt[NFSPROC_ACCESS]);
737 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
738 , "Mknod", "Fsstat", "Fsinfo", "PathConf",
739 "Commit", "SetClId", "SetClIdCf", "Lock");
740 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
741 ext_nfsstats.rpccnt[NFSPROC_MKNOD],
742 ext_nfsstats.rpccnt[NFSPROC_FSSTAT],
743 ext_nfsstats.rpccnt[NFSPROC_FSINFO],
744 ext_nfsstats.rpccnt[NFSPROC_PATHCONF],
745 ext_nfsstats.rpccnt[NFSPROC_COMMIT],
746 ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID],
747 ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM],
748 ext_nfsstats.rpccnt[NFSPROC_LOCK]);
750 printf("%9.9s %9.9s %9.9s %9.9s\n",
751 "LockT", "LockU", "Open", "OpenCfr");
752 printf("%9d %9d %9d %9d\n",
753 ext_nfsstats.rpccnt[NFSPROC_LOCKT],
754 ext_nfsstats.rpccnt[NFSPROC_LOCKU],
755 ext_nfsstats.rpccnt[NFSPROC_OPEN],
756 ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]);
759 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
760 , "OpenOwner", "Opens", "LockOwner",
761 "Locks", "Delegs", "LocalOwn",
762 "LocalOpen", "LocalLOwn");
763 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
764 ext_nfsstats.clopenowners,
765 ext_nfsstats.clopens,
766 ext_nfsstats.cllockowners,
767 ext_nfsstats.cllocks,
768 ext_nfsstats.cldelegates,
769 ext_nfsstats.cllocalopenowners,
770 ext_nfsstats.cllocalopens,
771 ext_nfsstats.cllocallockowners);
773 printf("%9.9s\n", "LocalLock");
774 printf("%9d\n", ext_nfsstats.cllocallocks);
776 printf("Rpc Info:\n");
777 printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n",
778 "TimedOut", "Invalid", "X Replies", "Retries",
781 printf("%9d %9d %9d %9d %9d\n",
782 ext_nfsstats.rpctimeouts,
783 ext_nfsstats.rpcinvalid,
784 ext_nfsstats.rpcunexpected,
785 ext_nfsstats.rpcretries,
786 ext_nfsstats.rpcrequests);
788 printf("Cache Info:\n");
789 printf("%9.9s %9.9s %9.9s %9.9s",
790 "Attr Hits", "Misses", "Lkup Hits", "Misses");
791 printf(" %9.9s %9.9s %9.9s %9.9s\n",
792 "BioR Hits", "Misses", "BioW Hits", "Misses");
794 printf("%9d %9d %9d %9d",
795 ext_nfsstats.attrcache_hits,
796 ext_nfsstats.attrcache_misses,
797 ext_nfsstats.lookupcache_hits,
798 ext_nfsstats.lookupcache_misses);
799 printf(" %9d %9d %9d %9d\n",
800 ext_nfsstats.biocache_reads - ext_nfsstats.read_bios,
801 ext_nfsstats.read_bios,
802 ext_nfsstats.biocache_writes - ext_nfsstats.write_bios,
803 ext_nfsstats.write_bios);
805 printf("%9.9s %9.9s %9.9s %9.9s",
806 "BioRLHits", "Misses", "BioD Hits", "Misses");
807 printf(" %9.9s %9.9s\n", "DirE Hits", "Misses");
809 printf("%9d %9d %9d %9d",
810 ext_nfsstats.biocache_readlinks -
811 ext_nfsstats.readlink_bios,
812 ext_nfsstats.readlink_bios,
813 ext_nfsstats.biocache_readdirs -
814 ext_nfsstats.readdir_bios,
815 ext_nfsstats.readdir_bios);
817 ext_nfsstats.direofcache_hits,
818 ext_nfsstats.direofcache_misses);
820 if (serverOnly != 0) {
822 printf("\nServer Info:\n");
824 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
825 , "Getattr", "Setattr", "Lookup", "Readlink",
826 "Read", "Write", "Create", "Remove");
828 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
829 ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR],
830 ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR],
831 ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP],
832 ext_nfsstats.srvrpccnt[NFSV4OP_READLINK],
833 ext_nfsstats.srvrpccnt[NFSV4OP_READ],
834 ext_nfsstats.srvrpccnt[NFSV4OP_WRITE],
835 ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE],
836 ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]);
839 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
840 , "Rename", "Link", "Symlink", "Mkdir", "Rmdir",
841 "Readdir", "RdirPlus", "Access");
842 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
843 ext_nfsstats.srvrpccnt[NFSV4OP_RENAME],
844 ext_nfsstats.srvrpccnt[NFSV4OP_LINK],
845 ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK],
846 ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR],
847 ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR],
848 ext_nfsstats.srvrpccnt[NFSV4OP_READDIR],
849 ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS],
850 ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]);
853 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
854 , "Mknod", "Fsstat", "Fsinfo", "PathConf",
855 "Commit", "LookupP", "SetClId", "SetClIdCf");
856 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
857 ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD],
858 ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT],
859 ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO],
860 ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF],
861 ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT],
862 ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP],
863 ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID],
864 ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]);
867 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
868 , "Open", "OpenAttr", "OpenDwnGr", "OpenCfrm",
869 "DelePurge", "DeleRet", "GetFH", "Lock");
870 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
871 ext_nfsstats.srvrpccnt[NFSV4OP_OPEN],
872 ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR],
873 ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE],
874 ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM],
875 ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE],
876 ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN],
877 ext_nfsstats.srvrpccnt[NFSV4OP_GETFH],
878 ext_nfsstats.srvrpccnt[NFSV4OP_LOCK]);
881 "%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n"
882 , "LockT", "LockU", "Close", "Verify", "NVerify",
883 "PutFH", "PutPubFH", "PutRootFH");
884 printf("%9d %9d %9d %9d %9d %9d %9d %9d\n",
885 ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT],
886 ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU],
887 ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE],
888 ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY],
889 ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY],
890 ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH],
891 ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH],
892 ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH]);
894 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
895 "Renew", "RestoreFH", "SaveFH", "Secinfo",
896 "RelLckOwn", "V4Create");
897 printf("%9d %9d %9d %9d %9d %9d\n",
898 ext_nfsstats.srvrpccnt[NFSV4OP_RENEW],
899 ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH],
900 ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH],
901 ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO],
902 ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN],
903 ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]);
906 printf("%9.9s %9.9s %9.9s\n",
907 "Retfailed", "Faults", "Clients");
909 printf("%9d %9d %9d\n",
910 ext_nfsstats.srv_errs, ext_nfsstats.srvrpc_errs,
911 ext_nfsstats.srvclients);
913 printf("%9.9s %9.9s %9.9s %9.9s %9.9s \n",
914 "OpenOwner", "Opens", "LockOwner",
916 printf("%9d %9d %9d %9d %9d \n",
917 ext_nfsstats.srvopenowners,
918 ext_nfsstats.srvopens,
919 ext_nfsstats.srvlockowners,
920 ext_nfsstats.srvlocks,
921 ext_nfsstats.srvdelegates);
923 printf("Server Cache Stats:\n");
924 printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n",
925 "Inprog", "Idem", "Non-idem", "Misses",
926 "CacheSize", "TCPPeak");
928 printf("%9d %9d %9d %9d %9d %9d\n",
929 ext_nfsstats.srvcache_inproghits,
930 ext_nfsstats.srvcache_idemdonehits,
931 ext_nfsstats.srvcache_nonidemdonehits,
932 ext_nfsstats.srvcache_misses,
933 ext_nfsstats.srvcache_size,
934 ext_nfsstats.srvcache_tcppeak);
939 * Print a running summary of nfs statistics for the experimental client and/or
941 * Repeat display every interval seconds, showing statistics
942 * collected over that interval. Assumes that interval is non-zero.
943 * First line printed at top of screen is always cumulative.
946 exp_sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
948 struct ext_nfsstats nfsstats, lastst, *ext_nfsstatsp;
951 ext_nfsstatsp = &lastst;
952 if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
953 err(1, "Can't get stats");
957 ext_nfsstatsp = &nfsstats;
958 if (nfssvc(NFSSVC_GETSTATS, ext_nfsstatsp) < 0)
959 err(1, "Can't get stats");
962 printhdr(clientOnly, serverOnly);
963 if (clientOnly && serverOnly)
969 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
970 ((clientOnly && serverOnly) ? "Client:" : ""),
971 DELTA(attrcache_hits) + DELTA(attrcache_misses),
972 DELTA(lookupcache_hits) + DELTA(lookupcache_misses),
973 DELTA(biocache_readlinks),
974 DELTA(biocache_reads),
975 DELTA(biocache_writes),
976 nfsstats.rpccnt[NFSPROC_RENAME] -
977 lastst.rpccnt[NFSPROC_RENAME],
978 DELTA(accesscache_hits) + DELTA(accesscache_misses),
979 DELTA(biocache_readdirs)
982 printf(" %s %s %s %s %s %s",
983 sperc1(DELTA(attrcache_hits),
984 DELTA(attrcache_misses)),
985 sperc1(DELTA(lookupcache_hits),
986 DELTA(lookupcache_misses)),
987 sperc2(DELTA(biocache_reads),
989 sperc2(DELTA(biocache_writes),
991 sperc1(DELTA(accesscache_hits),
992 DELTA(accesscache_misses)),
993 sperc2(DELTA(biocache_readdirs),
1001 printf("%s %6d %6d %6d %6d %6d %6d %6d %6d",
1002 ((clientOnly && serverOnly) ? "Server:" : ""),
1003 nfsstats.srvrpccnt[NFSV4OP_GETATTR] -
1004 lastst.srvrpccnt[NFSV4OP_GETATTR],
1005 nfsstats.srvrpccnt[NFSV4OP_LOOKUP] -
1006 lastst.srvrpccnt[NFSV4OP_LOOKUP],
1007 nfsstats.srvrpccnt[NFSV4OP_READLINK] -
1008 lastst.srvrpccnt[NFSV4OP_READLINK],
1009 nfsstats.srvrpccnt[NFSV4OP_READ] -
1010 lastst.srvrpccnt[NFSV4OP_READ],
1011 nfsstats.srvrpccnt[NFSV4OP_WRITE] -
1012 lastst.srvrpccnt[NFSV4OP_WRITE],
1013 nfsstats.srvrpccnt[NFSV4OP_RENAME] -
1014 lastst.srvrpccnt[NFSV4OP_RENAME],
1015 nfsstats.srvrpccnt[NFSV4OP_ACCESS] -
1016 lastst.srvrpccnt[NFSV4OP_ACCESS],
1017 (nfsstats.srvrpccnt[NFSV4OP_READDIR] -
1018 lastst.srvrpccnt[NFSV4OP_READDIR]) +
1019 (nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS] -
1020 lastst.srvrpccnt[NFSV4OP_READDIRPLUS]));