From 8a71d7ce804b0288a06d9f6dcbc74317e564eecf Mon Sep 17 00:00:00 2001 From: kstailey Date: Sun, 15 Dec 1996 18:52:19 +0000 Subject: [PATCH] added -s (display server report only) and -c (ditto client) flags --- usr.bin/nfsstat/nfsstat.c | 303 ++++++++++++++++++++------------------ 1 file changed, 161 insertions(+), 142 deletions(-) diff --git a/usr.bin/nfsstat/nfsstat.c b/usr.bin/nfsstat/nfsstat.c index f3d5dbe910b..6e35c4a5a33 100644 --- a/usr.bin/nfsstat/nfsstat.c +++ b/usr.bin/nfsstat/nfsstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfsstat.c,v 1.3 1996/08/06 18:36:59 deraadt Exp $ */ +/* $OpenBSD: nfsstat.c,v 1.4 1996/12/15 18:52:19 kstailey Exp $ */ /* $NetBSD: nfsstat.c,v 1.7 1996/03/03 17:21:30 thorpej Exp $ */ /* @@ -48,7 +48,7 @@ static char copyright[] = static char sccsid[] = "from: @(#)nfsstat.c 8.1 (Berkeley) 6/6/93"; static char *rcsid = "$NetBSD: nfsstat.c,v 1.7 1996/03/03 17:21:30 thorpej Exp $"; #else -static char *rcsid = "$OpenBSD: nfsstat.c,v 1.3 1996/08/06 18:36:59 deraadt Exp $"; +static char *rcsid = "$OpenBSD: nfsstat.c,v 1.4 1996/12/15 18:52:19 kstailey Exp $"; #endif #endif /* not lint */ @@ -72,6 +72,10 @@ static char *rcsid = "$OpenBSD: nfsstat.c,v 1.3 1996/08/06 18:36:59 deraadt Exp #include #include +#define SHOW_SERVER 0x01 +#define SHOW_CLIENT 0x02 +#define SHOW_ALL (SHOW_SERVER | SHOW_CLIENT) + struct nlist nl[] = { #define N_NFSSTAT 0 { "_nfsstats" }, @@ -88,13 +92,14 @@ main(argc, argv) extern int optind; extern char *optarg; u_int interval; + u_int display = SHOW_ALL; int ch; char *memf, *nlistf; char errbuf[_POSIX2_LINE_MAX]; interval = 0; memf = nlistf = NULL; - while ((ch = getopt(argc, argv, "M:N:w:")) != EOF) + while ((ch = getopt(argc, argv, "M:N:w:sc")) != EOF) switch(ch) { case 'M': memf = optarg; @@ -105,6 +110,12 @@ main(argc, argv) case 'w': interval = atoi(optarg); break; + case 's': + display = SHOW_SERVER; + break; + case 'c': + display = SHOW_CLIENT; + break; case '?': default: usage(); @@ -140,9 +151,9 @@ main(argc, argv) } if (interval) - sidewaysintpr(interval, nl[N_NFSSTAT].n_value); + sidewaysintpr(interval, nl[N_NFSSTAT].n_value, display); else - intpr(nl[N_NFSSTAT].n_value); + intpr(nl[N_NFSSTAT].n_value, display); exit(0); } @@ -150,8 +161,9 @@ main(argc, argv) * Print a description of the nfs stats. */ void -intpr(nfsstataddr) +intpr(nfsstataddr, display) u_long nfsstataddr; + u_int display; { struct nfsstats nfsstats; @@ -159,139 +171,143 @@ intpr(nfsstataddr) fprintf(stderr, "nfsstat: kvm_read failed\n"); exit(1); } - printf("Client Info:\n"); - printf("Rpc Counts:\n"); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Getattr", "Setattr", "Lookup", "Readlink", "Read", - "Write", "Create", "Remove"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", - nfsstats.rpccnt[NFSPROC_GETATTR], - nfsstats.rpccnt[NFSPROC_SETATTR], - nfsstats.rpccnt[NFSPROC_LOOKUP], - nfsstats.rpccnt[NFSPROC_READLINK], - nfsstats.rpccnt[NFSPROC_READ], - nfsstats.rpccnt[NFSPROC_WRITE], - nfsstats.rpccnt[NFSPROC_CREATE], - nfsstats.rpccnt[NFSPROC_REMOVE]); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Rename", "Link", "Symlink", "Mkdir", "Rmdir", - "Readdir", "RdirPlus", "Access"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", - nfsstats.rpccnt[NFSPROC_RENAME], - nfsstats.rpccnt[NFSPROC_LINK], - nfsstats.rpccnt[NFSPROC_SYMLINK], - nfsstats.rpccnt[NFSPROC_MKDIR], - nfsstats.rpccnt[NFSPROC_RMDIR], - nfsstats.rpccnt[NFSPROC_READDIR], - nfsstats.rpccnt[NFSPROC_READDIRPLUS], - nfsstats.rpccnt[NFSPROC_ACCESS]); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", - "GLease", "Vacate", "Evict"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", - nfsstats.rpccnt[NFSPROC_MKNOD], - nfsstats.rpccnt[NFSPROC_FSSTAT], - nfsstats.rpccnt[NFSPROC_FSINFO], - nfsstats.rpccnt[NFSPROC_PATHCONF], - nfsstats.rpccnt[NFSPROC_COMMIT], - nfsstats.rpccnt[NQNFSPROC_GETLEASE], - nfsstats.rpccnt[NQNFSPROC_VACATED], - nfsstats.rpccnt[NQNFSPROC_EVICTED]); - printf("Rpc Info:\n"); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n", - "TimedOut", "Invalid", "X Replies", "Retries", "Requests"); - printf("%9d %9d %9d %9d %9d\n", - nfsstats.rpctimeouts, - nfsstats.rpcinvalid, - nfsstats.rpcunexpected, - nfsstats.rpcretries, - nfsstats.rpcrequests); - printf("Cache Info:\n"); - printf("%9.9s %9.9s %9.9s %9.9s", - "Attr Hits", "Misses", "Lkup Hits", "Misses"); - printf(" %9.9s %9.9s %9.9s %9.9s\n", - "BioR Hits", "Misses", "BioW Hits", "Misses"); - printf("%9d %9d %9d %9d", - nfsstats.attrcache_hits, nfsstats.attrcache_misses, - nfsstats.lookupcache_hits, nfsstats.lookupcache_misses); - printf(" %9d %9d %9d %9d\n", - nfsstats.biocache_reads-nfsstats.read_bios, - nfsstats.read_bios, - nfsstats.biocache_writes-nfsstats.write_bios, - nfsstats.write_bios); - printf("%9.9s %9.9s %9.9s %9.9s", - "BioRLHits", "Misses", "BioD Hits", "Misses"); - printf(" %9.9s %9.9s\n", "DirE Hits", "Misses"); - printf("%9d %9d %9d %9d", - nfsstats.biocache_readlinks-nfsstats.readlink_bios, - nfsstats.readlink_bios, - nfsstats.biocache_readdirs-nfsstats.readdir_bios, - nfsstats.readdir_bios); - printf(" %9d %9d\n", - nfsstats.direofcache_hits, nfsstats.direofcache_misses); - printf("\nServer Info:\n"); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Getattr", "Setattr", "Lookup", "Readlink", "Read", - "Write", "Create", "Remove"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", - nfsstats.srvrpccnt[NFSPROC_GETATTR], - nfsstats.srvrpccnt[NFSPROC_SETATTR], - nfsstats.srvrpccnt[NFSPROC_LOOKUP], - nfsstats.srvrpccnt[NFSPROC_READLINK], - nfsstats.srvrpccnt[NFSPROC_READ], - nfsstats.srvrpccnt[NFSPROC_WRITE], - nfsstats.srvrpccnt[NFSPROC_CREATE], - nfsstats.srvrpccnt[NFSPROC_REMOVE]); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Rename", "Link", "Symlink", "Mkdir", "Rmdir", - "Readdir", "RdirPlus", "Access"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", - nfsstats.srvrpccnt[NFSPROC_RENAME], - nfsstats.srvrpccnt[NFSPROC_LINK], - nfsstats.srvrpccnt[NFSPROC_SYMLINK], - nfsstats.srvrpccnt[NFSPROC_MKDIR], - nfsstats.srvrpccnt[NFSPROC_RMDIR], - nfsstats.srvrpccnt[NFSPROC_READDIR], - nfsstats.srvrpccnt[NFSPROC_READDIRPLUS], - nfsstats.srvrpccnt[NFSPROC_ACCESS]); - printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", - "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", - "GLease", "Vacate", "Evict"); - printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", - nfsstats.srvrpccnt[NFSPROC_MKNOD], - nfsstats.srvrpccnt[NFSPROC_FSSTAT], - nfsstats.srvrpccnt[NFSPROC_FSINFO], - nfsstats.srvrpccnt[NFSPROC_PATHCONF], - nfsstats.srvrpccnt[NFSPROC_COMMIT], - nfsstats.srvrpccnt[NQNFSPROC_GETLEASE], - nfsstats.srvrpccnt[NQNFSPROC_VACATED], - nfsstats.srvrpccnt[NQNFSPROC_EVICTED]); - printf("Server Ret-Failed\n"); - printf("%17d\n", nfsstats.srvrpc_errs); - printf("Server Faults\n"); - printf("%13d\n", nfsstats.srv_errs); - printf("Server Cache Stats:\n"); - printf("%9.9s %9.9s %9.9s %9.9s\n", - "Inprog", "Idem", "Non-idem", "Misses"); - printf("%9d %9d %9d %9d\n", - nfsstats.srvcache_inproghits, - nfsstats.srvcache_idemdonehits, - nfsstats.srvcache_nonidemdonehits, - nfsstats.srvcache_misses); - printf("Server Lease Stats:\n"); - printf("%9.9s %9.9s %9.9s\n", - "Leases", "PeakL", "GLeases"); - printf("%9d %9d %9d\n", - nfsstats.srvnqnfs_leases, - nfsstats.srvnqnfs_maxleases, - nfsstats.srvnqnfs_getleases); - printf("Server Write Gathering:\n"); - printf("%9.9s %9.9s %9.9s\n", - "WriteOps", "WriteRPC", "Opsaved"); - printf("%9d %9d %9d\n", - nfsstats.srvvop_writes, - nfsstats.srvrpccnt[NFSPROC_WRITE], - nfsstats.srvrpccnt[NFSPROC_WRITE] - nfsstats.srvvop_writes); + if (display & SHOW_CLIENT) { + printf("Client Info:\n"); + printf("Rpc Counts:\n"); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Getattr", "Setattr", "Lookup", "Readlink", "Read", + "Write", "Create", "Remove"); + printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + nfsstats.rpccnt[NFSPROC_GETATTR], + nfsstats.rpccnt[NFSPROC_SETATTR], + nfsstats.rpccnt[NFSPROC_LOOKUP], + nfsstats.rpccnt[NFSPROC_READLINK], + nfsstats.rpccnt[NFSPROC_READ], + nfsstats.rpccnt[NFSPROC_WRITE], + nfsstats.rpccnt[NFSPROC_CREATE], + nfsstats.rpccnt[NFSPROC_REMOVE]); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Rename", "Link", "Symlink", "Mkdir", "Rmdir", + "Readdir", "RdirPlus", "Access"); + printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + nfsstats.rpccnt[NFSPROC_RENAME], + nfsstats.rpccnt[NFSPROC_LINK], + nfsstats.rpccnt[NFSPROC_SYMLINK], + nfsstats.rpccnt[NFSPROC_MKDIR], + nfsstats.rpccnt[NFSPROC_RMDIR], + nfsstats.rpccnt[NFSPROC_READDIR], + nfsstats.rpccnt[NFSPROC_READDIRPLUS], + nfsstats.rpccnt[NFSPROC_ACCESS]); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", + "GLease", "Vacate", "Evict"); + printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + nfsstats.rpccnt[NFSPROC_MKNOD], + nfsstats.rpccnt[NFSPROC_FSSTAT], + nfsstats.rpccnt[NFSPROC_FSINFO], + nfsstats.rpccnt[NFSPROC_PATHCONF], + nfsstats.rpccnt[NFSPROC_COMMIT], + nfsstats.rpccnt[NQNFSPROC_GETLEASE], + nfsstats.rpccnt[NQNFSPROC_VACATED], + nfsstats.rpccnt[NQNFSPROC_EVICTED]); + printf("Rpc Info:\n"); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n", + "TimedOut", "Invalid", "X Replies", "Retries", "Requests"); + printf("%9d %9d %9d %9d %9d\n", + nfsstats.rpctimeouts, + nfsstats.rpcinvalid, + nfsstats.rpcunexpected, + nfsstats.rpcretries, + nfsstats.rpcrequests); + printf("Cache Info:\n"); + printf("%9.9s %9.9s %9.9s %9.9s", + "Attr Hits", "Misses", "Lkup Hits", "Misses"); + printf(" %9.9s %9.9s %9.9s %9.9s\n", + "BioR Hits", "Misses", "BioW Hits", "Misses"); + printf("%9d %9d %9d %9d", + nfsstats.attrcache_hits, nfsstats.attrcache_misses, + nfsstats.lookupcache_hits, nfsstats.lookupcache_misses); + printf(" %9d %9d %9d %9d\n", + nfsstats.biocache_reads-nfsstats.read_bios, + nfsstats.read_bios, + nfsstats.biocache_writes-nfsstats.write_bios, + nfsstats.write_bios); + printf("%9.9s %9.9s %9.9s %9.9s", + "BioRLHits", "Misses", "BioD Hits", "Misses"); + printf(" %9.9s %9.9s\n", "DirE Hits", "Misses"); + printf("%9d %9d %9d %9d", + nfsstats.biocache_readlinks-nfsstats.readlink_bios, + nfsstats.readlink_bios, + nfsstats.biocache_readdirs-nfsstats.readdir_bios, + nfsstats.readdir_bios); + printf(" %9d %9d\n", + nfsstats.direofcache_hits, nfsstats.direofcache_misses); + } + if (display & SHOW_SERVER) { + printf("\nServer Info:\n"); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Getattr", "Setattr", "Lookup", "Readlink", "Read", + "Write", "Create", "Remove"); + printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + nfsstats.srvrpccnt[NFSPROC_GETATTR], + nfsstats.srvrpccnt[NFSPROC_SETATTR], + nfsstats.srvrpccnt[NFSPROC_LOOKUP], + nfsstats.srvrpccnt[NFSPROC_READLINK], + nfsstats.srvrpccnt[NFSPROC_READ], + nfsstats.srvrpccnt[NFSPROC_WRITE], + nfsstats.srvrpccnt[NFSPROC_CREATE], + nfsstats.srvrpccnt[NFSPROC_REMOVE]); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Rename", "Link", "Symlink", "Mkdir", "Rmdir", + "Readdir", "RdirPlus", "Access"); + printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + nfsstats.srvrpccnt[NFSPROC_RENAME], + nfsstats.srvrpccnt[NFSPROC_LINK], + nfsstats.srvrpccnt[NFSPROC_SYMLINK], + nfsstats.srvrpccnt[NFSPROC_MKDIR], + nfsstats.srvrpccnt[NFSPROC_RMDIR], + nfsstats.srvrpccnt[NFSPROC_READDIR], + nfsstats.srvrpccnt[NFSPROC_READDIRPLUS], + nfsstats.srvrpccnt[NFSPROC_ACCESS]); + printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", + "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", + "GLease", "Vacate", "Evict"); + printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", + nfsstats.srvrpccnt[NFSPROC_MKNOD], + nfsstats.srvrpccnt[NFSPROC_FSSTAT], + nfsstats.srvrpccnt[NFSPROC_FSINFO], + nfsstats.srvrpccnt[NFSPROC_PATHCONF], + nfsstats.srvrpccnt[NFSPROC_COMMIT], + nfsstats.srvrpccnt[NQNFSPROC_GETLEASE], + nfsstats.srvrpccnt[NQNFSPROC_VACATED], + nfsstats.srvrpccnt[NQNFSPROC_EVICTED]); + printf("Server Ret-Failed\n"); + printf("%17d\n", nfsstats.srvrpc_errs); + printf("Server Faults\n"); + printf("%13d\n", nfsstats.srv_errs); + printf("Server Cache Stats:\n"); + printf("%9.9s %9.9s %9.9s %9.9s\n", + "Inprog", "Idem", "Non-idem", "Misses"); + printf("%9d %9d %9d %9d\n", + nfsstats.srvcache_inproghits, + nfsstats.srvcache_idemdonehits, + nfsstats.srvcache_nonidemdonehits, + nfsstats.srvcache_misses); + printf("Server Lease Stats:\n"); + printf("%9.9s %9.9s %9.9s\n", + "Leases", "PeakL", "GLeases"); + printf("%9d %9d %9d\n", + nfsstats.srvnqnfs_leases, + nfsstats.srvnqnfs_maxleases, + nfsstats.srvnqnfs_getleases); + printf("Server Write Gathering:\n"); + printf("%9.9s %9.9s %9.9s\n", + "WriteOps", "WriteRPC", "Opsaved"); + printf("%9d %9d %9d\n", + nfsstats.srvvop_writes, + nfsstats.srvrpccnt[NFSPROC_WRITE], + nfsstats.srvrpccnt[NFSPROC_WRITE] - nfsstats.srvvop_writes); + } } u_char signalled; /* set if alarm goes off "early" */ @@ -303,9 +319,10 @@ u_char signalled; /* set if alarm goes off "early" */ * First line printed at top of screen is always cumulative. */ void -sidewaysintpr(interval, off) +sidewaysintpr(interval, off, display) u_int interval; u_long off; + u_int display; { struct nfsstats nfsstats, lastst; int hdrcnt, oldmask; @@ -325,7 +342,8 @@ sidewaysintpr(interval, off) fprintf(stderr, "nfsstat: kvm_read failed\n"); exit(1); } - printf("Client: %8d %8d %8d %8d %8d %8d %8d %8d\n", + if (display & SHOW_CLIENT) + printf("Client: %8d %8d %8d %8d %8d %8d %8d %8d\n", nfsstats.rpccnt[NFSPROC_GETATTR]-lastst.rpccnt[NFSPROC_GETATTR], nfsstats.rpccnt[NFSPROC_LOOKUP]-lastst.rpccnt[NFSPROC_LOOKUP], nfsstats.rpccnt[NFSPROC_READLINK]-lastst.rpccnt[NFSPROC_READLINK], @@ -335,7 +353,8 @@ sidewaysintpr(interval, off) nfsstats.rpccnt[NFSPROC_ACCESS]-lastst.rpccnt[NFSPROC_ACCESS], (nfsstats.rpccnt[NFSPROC_READDIR]-lastst.rpccnt[NFSPROC_READDIR]) +(nfsstats.rpccnt[NFSPROC_READDIRPLUS]-lastst.rpccnt[NFSPROC_READDIRPLUS])); - printf("Server: %8d %8d %8d %8d %8d %8d %8d %8d\n", + if (display & SHOW_SERVER) + printf("Server: %8d %8d %8d %8d %8d %8d %8d %8d\n", nfsstats.srvrpccnt[NFSPROC_GETATTR]-lastst.srvrpccnt[NFSPROC_GETATTR], nfsstats.srvrpccnt[NFSPROC_LOOKUP]-lastst.srvrpccnt[NFSPROC_LOOKUP], nfsstats.srvrpccnt[NFSPROC_READLINK]-lastst.srvrpccnt[NFSPROC_READLINK], -- 2.20.1