summaryrefslogtreecommitdiffstats
path: root/utils/nfsstat/nfsstat.c
diff options
context:
space:
mode:
authorKevin Constantine <kevin.constantine@disneyanimation.com>2009-04-04 07:18:26 -0400
committerSteve Dickson <steved@redhat.com>2009-04-04 07:18:26 -0400
commitca8eb17798fb9b4936a38cc58fe379e9e8d379f9 (patch)
treee8ecf4a8e42297ba8436601fc5b7cf4c0b70cd98 /utils/nfsstat/nfsstat.c
parent524cdc4eb1663e5c10d12160e48c45dc81852568 (diff)
downloadnfs-utils-ca8eb17798fb9b4936a38cc58fe379e9e8d379f9.tar.gz
nfs-utils-ca8eb17798fb9b4936a38cc58fe379e9e8d379f9.tar.xz
nfs-utils-ca8eb17798fb9b4936a38cc58fe379e9e8d379f9.zip
nfsstat: Add --list flag
nfsstat.c: Adds the --list flag to print information in a list format instead of the standard multi-column format nfsstat.man: Updates the manpage to include the --list flag. Signed-off-by: Kevin Constantine <kevin.constantine@disneyanimation.com> Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/nfsstat/nfsstat.c')
-rw-r--r--utils/nfsstat/nfsstat.c83
1 files changed, 80 insertions, 3 deletions
diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c
index 7906b09..d5bdad7 100644
--- a/utils/nfsstat/nfsstat.c
+++ b/utils/nfsstat/nfsstat.c
@@ -170,10 +170,13 @@ DECLARE_CLT(cltinfo, _old);
static void print_all_stats(int, int, int);
static void print_server_stats(int, int);
static void print_client_stats(int, int);
+static void print_stats_list(int);
static void print_numbers(const char *, unsigned int *,
unsigned int);
static void print_callstats(const char *, const char **,
unsigned int *, unsigned int);
+static void print_callstats_list(const char *, const char **,
+ unsigned int *, unsigned int);
static int parse_raw_statfile(const char *, struct statinfo *);
static int parse_pretty_statfile(const char *, struct statinfo *);
@@ -233,6 +236,7 @@ void usage(char *name)
If # is provided, stats will be output every\n\
# seconds.\n\
-S, --since file Shows difference between current stats and those in 'file'\n\
+ -l, --list Prints stats in list format\n\
--version Show program version\n\
--help What you just did\n\
\n", name);
@@ -255,6 +259,7 @@ static struct option longopts[] =
{ "version", 0, 0, '\2' },
{ "sleep", 2, 0, 'Z' },
{ "since", 1, 0, 'S' },
+ { "list", 0, 0, 'l' },
{ NULL, 0, 0, 0 }
};
int opt_sleep;
@@ -267,6 +272,7 @@ main(int argc, char **argv)
opt_clt = 0,
opt_prt = 0,
sleep_time = 0,
+ opt_list =0,
opt_since = 0;
int c;
char *progname,
@@ -288,7 +294,7 @@ main(int argc, char **argv)
else
progname = argv[0];
- while ((c = getopt_long(argc, argv, "234acmno:Z::S:vrsz\1\2", longopts, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, "234acmno:Z::S:vrslz\1\2", longopts, NULL)) != EOF) {
switch (c) {
case 'a':
fprintf(stderr, "nfsstat: nfs acls are not yet supported.\n");
@@ -346,6 +352,9 @@ main(int argc, char **argv)
case 's':
opt_srv = 1;
break;
+ case 'l':
+ opt_list = 1;
+ break;
case 'z':
fprintf(stderr, "nfsstat: zeroing of nfs statistics "
"not yet supported\n");
@@ -426,14 +435,22 @@ main(int argc, char **argv)
get_stats(NFSCLTSTAT, clientinfo_tmp, &opt_clt, opt_srv, 0);
diff_stats(clientinfo_tmp, clientinfo, 0);
}
- print_all_stats(opt_srv, opt_clt, opt_prt);
+ if (opt_list) {
+ print_stats_list(opt_prt);
+ } else {
+ print_all_stats(opt_srv, opt_clt, opt_prt);
+ }
fflush(stdout);
update_old_counters(clientinfo_tmp, clientinfo);
sleep(sleep_time);
}
} else {
- print_all_stats(opt_srv, opt_clt, opt_prt);
+ if (opt_list) {
+ print_stats_list(opt_prt);
+ } else {
+ print_all_stats(opt_srv, opt_clt, opt_prt);
+ }
}
return 0;
@@ -568,6 +585,47 @@ print_client_stats(int opt_clt, int opt_prt)
}
}
+static void
+print_stats_list(int opt_prt)
+{
+ if (opt_prt & PRNT_CALLS) {
+ if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && has_stats(cltproc2info))) {
+ print_callstats_list(
+ "nfs v2 server",
+ nfsv2name, srvproc2info + 1, sizeof(nfsv2name)/sizeof(char *));
+ printf("\n");
+ print_callstats_list(
+ "nfs v2 client",
+ nfsv2name, cltproc2info + 1, sizeof(nfsv2name)/sizeof(char *));
+ printf("\n");
+ }
+ if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && has_stats(cltproc3info))) {
+ print_callstats_list(
+ "nfs v3 server",
+ nfsv3name, srvproc3info + 1, sizeof(nfsv3name)/sizeof(char *));
+ printf("\n");
+ print_callstats_list(
+ "nfs v3 client",
+ nfsv3name, cltproc3info + 1, sizeof(nfsv3name)/sizeof(char *));
+ printf("\n");
+ }
+ if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && has_stats(cltproc4info))) {
+ print_callstats_list(
+ "nfs v4 server",
+ nfssrvproc4name, srvproc4info + 1, sizeof(nfssrvproc4name)/sizeof(char *));
+ printf("\n");
+ print_callstats_list(
+ "nfs v4 ops",
+ nfssrvproc4opname, srvproc4opsinfo + 1, sizeof(nfssrvproc4opname)/sizeof(char *));
+ printf("\n");
+ print_callstats_list(
+ "nfs v4 client",
+ nfscltproc4name, cltproc4info + 1, sizeof(nfscltproc4name)/sizeof(char *));
+ printf("\n");
+ }
+ }
+}
+
static statinfo *
get_stat_info(const char *sp, struct statinfo *statp)
{
@@ -618,6 +676,25 @@ print_callstats(const char *hdr, const char **names,
printf("\n");
}
+static void
+print_callstats_list(const char *hdr, const char **names,
+ unsigned int *callinfo, unsigned int nr)
+{
+ unsigned long long calltotal;
+ int i;
+
+ for (i = 0, calltotal = 0; i < nr; i++) {
+ calltotal += callinfo[i];
+ }
+ printf("%13s %13s %8llu \n", hdr, "total:", calltotal);
+ printf("------------- ------------- --------\n");
+ for (i = 0; i < nr; i++) {
+ printf("%13s %12s: %8u \n", hdr, names[i], callinfo[i]);
+ }
+
+}
+
+
/* returns 0 on success, 1 otherwise */
static int
parse_raw_statfile(const char *name, struct statinfo *statp)