summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2007-10-18 16:38:07 +0000
committerjhb <jhb@FreeBSD.org>2007-10-18 16:38:07 +0000
commit1f6b3a5f2c43971b35cacb43e695cfb721cfb5f6 (patch)
tree4912db43a06543e8705b20f6026b02a33b0ebb20 /usr.bin
parentd2c2b5f35cc0c9d43982c2e6e731dd44b50b4112 (diff)
downloadFreeBSD-src-1f6b3a5f2c43971b35cacb43e695cfb721cfb5f6.zip
FreeBSD-src-1f6b3a5f2c43971b35cacb43e695cfb721cfb5f6.tar.gz
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)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/nfsstat/nfsstat.16
-rw-r--r--usr.bin/nfsstat/nfsstat.c66
2 files changed, 48 insertions, 24 deletions
diff --git a/usr.bin/nfsstat/nfsstat.1 b/usr.bin/nfsstat/nfsstat.1
index e35dd3f..a7c2a13 100644
--- a/usr.bin/nfsstat/nfsstat.1
+++ b/usr.bin/nfsstat/nfsstat.1
@@ -32,7 +32,7 @@
.\" From: @(#)nfsstat.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd June 6, 1993
+.Dd October 18, 2007
.Dt NFSSTAT 1
.Os
.Sh NAME
@@ -42,7 +42,7 @@
statistics
.Sh SYNOPSIS
.Nm
-.Op Fl csW
+.Op Fl cszW
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl w Ar wait
@@ -80,6 +80,8 @@ Display a shorter summary of
activity for both the client and server at
.Ar wait
second intervals.
+.It Fl z
+Reset statistics after displaying them.
.El
.Sh FILES
.Bl -tag -width ".Pa /boot/kernel/kernel" -compact
diff --git a/usr.bin/nfsstat/nfsstat.c b/usr.bin/nfsstat/nfsstat.c
index dda4bbb..5a1495a 100644
--- a/usr.bin/nfsstat/nfsstat.c
+++ b/usr.bin/nfsstat/nfsstat.c
@@ -81,6 +81,7 @@ kvm_t *kd;
static int deadkernel = 0;
static int widemode = 0;
+static int zflag = 0;
void intpr(int, int);
void printhdr(int, int);
@@ -92,9 +93,7 @@ char *sperc2(int, int);
#define DELTA(field) (nfsstats.field - lastst.field)
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
u_int interval;
int clientOnly = -1;
@@ -105,7 +104,7 @@ main(argc, argv)
interval = 0;
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "csWM:N:w:")) != -1)
+ while ((ch = getopt(argc, argv, "csWM:N:w:z")) != -1)
switch(ch) {
case 'M':
memf = optarg;
@@ -129,6 +128,9 @@ main(argc, argv)
if (clientOnly < 0)
clientOnly = 0;
break;
+ case 'z':
+ zflag = 1;
+ break;
case '?':
default:
usage();
@@ -171,30 +173,40 @@ main(argc, argv)
* for dead ones.
*/
void
-readstats(stp, srvstp)
- struct nfsstats **stp;
- struct nfsrvstats **srvstp;
+readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
{
+ union {
+ struct nfsstats client;
+ struct nfsrvstats server;
+ } zerostat;
size_t buflen;
if (deadkernel) {
- if (kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value, *stp,
- sizeof(struct nfsstats)) < 0) {
+ if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
+ *stp, sizeof(struct nfsstats)) < 0) {
*stp = NULL;
}
- if (kvm_read(kd, (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
- sizeof(struct nfsrvstats)) < 0) {
+ if (*srvstp != NULL && kvm_read(kd,
+ (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
+ sizeof(struct nfsrvstats)) < 0) {
*srvstp = NULL;
}
} else {
+ if (zero)
+ bzero(&zerostat, sizeof(zerostat));
buflen = sizeof(struct nfsstats);
- if (sysctlbyname("vfs.nfs.nfsstats", *stp, &buflen,
- (void *)0, (size_t)0) < 0) {
+ if (*stp != NULL && sysctlbyname("vfs.nfs.nfsstats", *stp,
+ &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
+ if (errno != ENOENT)
+ err(1, "sysctl: vfs.nfs.nfsstats");
*stp = NULL;
}
buflen = sizeof(struct nfsrvstats);
- if (sysctlbyname("vfs.nfsrv.nfsrvstats", *srvstp, &buflen,
- (void *)0, (size_t)0) < 0) {
+ if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
+ *srvstp, &buflen, zero ? &zerostat : NULL,
+ zero ? buflen : 0) < 0) {
+ if (errno != ENOENT)
+ err(1, "sysctl: vfs.nfsrv.nfsrvstats");
*srvstp = NULL;
}
}
@@ -209,10 +221,20 @@ intpr(int clientOnly, int serverOnly)
struct nfsstats nfsstats, *nfsstatsp;
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) {
printf("Client not present!\n");
@@ -365,7 +387,7 @@ sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
nfsstatsp = &lastst;
nfsrvstatsp = &lastsrvst;
- readstats(&nfsstatsp, &nfsrvstatsp);
+ readstats(&nfsstatsp, &nfsrvstatsp, 0);
if (clientOnly && !nfsstatsp) {
printf("Client not present!\n");
clientOnly = 0;
@@ -379,7 +401,7 @@ sidewaysintpr(u_int interval, int clientOnly, int serverOnly)
for (;;) {
nfsstatsp = &nfsstats;
nfsrvstatsp = &nfsrvstats;
- readstats(&nfsstatsp, &nfsrvstatsp);
+ readstats(&nfsstatsp, &nfsrvstatsp, 0);
if (--hdrcnt == 0) {
printhdr(clientOnly, serverOnly);
@@ -455,10 +477,10 @@ printhdr(int clientOnly, int serverOnly)
}
void
-usage()
+usage(void)
{
(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);
}
OpenPOWER on IntegriCloud