Add a -z flag to nfsstat which zeros the NFS statistics after displaying

them.

MFC after:	1 week
Requested by:	ps
Submitted by:	ps (6 years ago)
This commit is contained in:
John Baldwin 2007-10-18 16:38:07 +00:00
parent 9e916c3163
commit 813947b737
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=172759
4 changed files with 50 additions and 26 deletions

View File

@ -88,7 +88,7 @@ uma_zone_t nfsmount_zone;
struct nfsstats nfsstats; struct nfsstats nfsstats;
SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW, 0, "NFS filesystem"); SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW, 0, "NFS filesystem");
SYSCTL_STRUCT(_vfs_nfs, NFS_NFSSTATS, nfsstats, CTLFLAG_RD, SYSCTL_STRUCT(_vfs_nfs, NFS_NFSSTATS, nfsstats, CTLFLAG_RW,
&nfsstats, nfsstats, "S,nfsstats"); &nfsstats, nfsstats, "S,nfsstats");
static int nfs_ip_paranoia = 1; static int nfs_ip_paranoia = 1;
SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_ip_paranoia, CTLFLAG_RW, SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_ip_paranoia, CTLFLAG_RW,

View File

@ -135,7 +135,7 @@ SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks, 0, "
SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, ""); SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, "");
struct nfsrvstats nfsrvstats; struct nfsrvstats nfsrvstats;
SYSCTL_STRUCT(_vfs_nfsrv, NFS_NFSRVSTATS, nfsrvstats, CTLFLAG_RD, SYSCTL_STRUCT(_vfs_nfsrv, NFS_NFSRVSTATS, nfsrvstats, CTLFLAG_RW,
&nfsrvstats, nfsrvstats, "S,nfsrvstats"); &nfsrvstats, nfsrvstats, "S,nfsrvstats");
static int nfsrv_access(struct vnode *, int, struct ucred *, int, static int nfsrv_access(struct vnode *, int, struct ucred *, int,

View File

@ -32,7 +32,7 @@
.\" From: @(#)nfsstat.1 8.1 (Berkeley) 6/6/93 .\" From: @(#)nfsstat.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd June 6, 1993 .Dd October 18, 2007
.Dt NFSSTAT 1 .Dt NFSSTAT 1
.Os .Os
.Sh NAME .Sh NAME
@ -42,7 +42,7 @@
statistics statistics
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl csW .Op Fl cszW
.Op Fl M Ar core .Op Fl M Ar core
.Op Fl N Ar system .Op Fl N Ar system
.Op Fl w Ar wait .Op Fl w Ar wait
@ -80,6 +80,8 @@ Display a shorter summary of
activity for both the client and server at activity for both the client and server at
.Ar wait .Ar wait
second intervals. second intervals.
.It Fl z
Reset statistics after displaying them.
.El .El
.Sh FILES .Sh FILES
.Bl -tag -width ".Pa /boot/kernel/kernel" -compact .Bl -tag -width ".Pa /boot/kernel/kernel" -compact

View File

@ -81,6 +81,7 @@ kvm_t *kd;
static int deadkernel = 0; static int deadkernel = 0;
static int widemode = 0; static int widemode = 0;
static int zflag = 0;
void intpr(int, int); void intpr(int, int);
void printhdr(int, int); void printhdr(int, int);
@ -92,9 +93,7 @@ char *sperc2(int, int);
#define DELTA(field) (nfsstats.field - lastst.field) #define DELTA(field) (nfsstats.field - lastst.field)
int int
main(argc, argv) main(int argc, char **argv)
int argc;
char **argv;
{ {
u_int interval; u_int interval;
int clientOnly = -1; int clientOnly = -1;
@ -105,7 +104,7 @@ main(argc, argv)
interval = 0; interval = 0;
memf = nlistf = NULL; memf = nlistf = NULL;
while ((ch = getopt(argc, argv, "csWM:N:w:")) != -1) while ((ch = getopt(argc, argv, "csWM:N:w:z")) != -1)
switch(ch) { switch(ch) {
case 'M': case 'M':
memf = optarg; memf = optarg;
@ -129,6 +128,9 @@ main(argc, argv)
if (clientOnly < 0) if (clientOnly < 0)
clientOnly = 0; clientOnly = 0;
break; break;
case 'z':
zflag = 1;
break;
case '?': case '?':
default: default:
usage(); usage();
@ -171,30 +173,40 @@ main(argc, argv)
* for dead ones. * for dead ones.
*/ */
void void
readstats(stp, srvstp) readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
struct nfsstats **stp;
struct nfsrvstats **srvstp;
{ {
union {
struct nfsstats client;
struct nfsrvstats server;
} zerostat;
size_t buflen; size_t buflen;
if (deadkernel) { if (deadkernel) {
if (kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value, *stp, if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
sizeof(struct nfsstats)) < 0) { *stp, sizeof(struct nfsstats)) < 0) {
*stp = NULL; *stp = NULL;
} }
if (kvm_read(kd, (u_long)nl[N_NFSRVSTAT].n_value, *srvstp, if (*srvstp != NULL && kvm_read(kd,
sizeof(struct nfsrvstats)) < 0) { (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
sizeof(struct nfsrvstats)) < 0) {
*srvstp = NULL; *srvstp = NULL;
} }
} else { } else {
if (zero)
bzero(&zerostat, sizeof(zerostat));
buflen = sizeof(struct nfsstats); buflen = sizeof(struct nfsstats);
if (sysctlbyname("vfs.nfs.nfsstats", *stp, &buflen, if (*stp != NULL && sysctlbyname("vfs.nfs.nfsstats", *stp,
(void *)0, (size_t)0) < 0) { &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
if (errno != ENOENT)
err(1, "sysctl: vfs.nfs.nfsstats");
*stp = NULL; *stp = NULL;
} }
buflen = sizeof(struct nfsrvstats); buflen = sizeof(struct nfsrvstats);
if (sysctlbyname("vfs.nfsrv.nfsrvstats", *srvstp, &buflen, if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
(void *)0, (size_t)0) < 0) { *srvstp, &buflen, zero ? &zerostat : NULL,
zero ? buflen : 0) < 0) {
if (errno != ENOENT)
err(1, "sysctl: vfs.nfsrv.nfsrvstats");
*srvstp = NULL; *srvstp = NULL;
} }
} }
@ -209,10 +221,20 @@ intpr(int clientOnly, int serverOnly)
struct nfsstats nfsstats, *nfsstatsp; struct nfsstats nfsstats, *nfsstatsp;
struct nfsrvstats nfsrvstats, *nfsrvstatsp; struct nfsrvstats nfsrvstats, *nfsrvstatsp;
nfsstatsp = &nfsstats; /*
nfsrvstatsp = &nfsrvstats; * Only read the stats we are going to display to avoid zeroing
* stats the user didn't request.
*/
if (clientOnly)
nfsstatsp = &nfsstats;
else
nfsstatsp = NULL;
if (serverOnly)
nfsrvstatsp = &nfsrvstats;
else
nfsrvstatsp = NULL;
readstats(&nfsstatsp, &nfsrvstatsp); readstats(&nfsstatsp, &nfsrvstatsp, zflag);
if (clientOnly && !nfsstatsp) { if (clientOnly && !nfsstatsp) {
printf("Client not present!\n"); printf("Client not present!\n");
@ -365,7 +387,7 @@ sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
nfsstatsp = &lastst; nfsstatsp = &lastst;
nfsrvstatsp = &lastsrvst; nfsrvstatsp = &lastsrvst;
readstats(&nfsstatsp, &nfsrvstatsp); readstats(&nfsstatsp, &nfsrvstatsp, 0);
if (clientOnly && !nfsstatsp) { if (clientOnly && !nfsstatsp) {
printf("Client not present!\n"); printf("Client not present!\n");
clientOnly = 0; clientOnly = 0;
@ -379,7 +401,7 @@ sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
for (;;) { for (;;) {
nfsstatsp = &nfsstats; nfsstatsp = &nfsstats;
nfsrvstatsp = &nfsrvstats; nfsrvstatsp = &nfsrvstats;
readstats(&nfsstatsp, &nfsrvstatsp); readstats(&nfsstatsp, &nfsrvstatsp, 0);
if (--hdrcnt == 0) { if (--hdrcnt == 0) {
printhdr(clientOnly, serverOnly); printhdr(clientOnly, serverOnly);
@ -455,10 +477,10 @@ printhdr(int clientOnly, int serverOnly)
} }
void void
usage() usage(void)
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: nfsstat [-csW] [-M core] [-N system] [-w interval]\n"); "usage: nfsstat [-cszW] [-M core] [-N system] [-w interval]\n");
exit(1); exit(1);
} }