]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfsstat: Add --list flag
authorKevin Constantine <kevin.constantine@disneyanimation.com>
Sat, 4 Apr 2009 11:18:26 +0000 (07:18 -0400)
committerSteve Dickson <steved@redhat.com>
Sat, 4 Apr 2009 11:18:26 +0000 (07:18 -0400)
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>
utils/nfsstat/nfsstat.c
utils/nfsstat/nfsstat.man

index 7906b095eb47e46456e06b57d422ac94cf9feb86..d5bdad7365cadd908362d4fc612670f4e7e56a6a 100644 (file)
@@ -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_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_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 *);
 
 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\
                            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);
   --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' },
        { "version", 0, 0, '\2' },
        { "sleep", 2, 0, 'Z' },
        { "since", 1, 0, 'S' },
+       { "list", 0, 0, 'l' },
        { NULL, 0, 0, 0 }
 };
 int opt_sleep;
        { 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_clt = 0,
                        opt_prt = 0,
                        sleep_time = 0,
+                       opt_list =0,
                        opt_since = 0;
        int             c;
        char           *progname,
                        opt_since = 0;
        int             c;
        char           *progname,
@@ -288,7 +294,7 @@ main(int argc, char **argv)
        else
                progname = argv[0];
 
        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");
                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 's':
                        opt_srv = 1;
                        break;
+               case 'l':
+                       opt_list = 1;
+                       break;
                case 'z':
                        fprintf(stderr, "nfsstat: zeroing of nfs statistics "
                                        "not yet supported\n");
                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);
                        }
                                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 {
                        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;
        }
 
        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)
 {
 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");
 }
 
        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)
 /* returns 0 on success, 1 otherwise */
 static int
 parse_raw_statfile(const char *name, struct statinfo *statp)
index 461b2c02e7cf9ad5bd15ce01b8da0e2fdfb9ed4a..52215a9293a5ff90915517a715e381230be9aa91 100644 (file)
@@ -72,6 +72,9 @@ Display all of the above facilities.
 .B \-v, \-\-verbose
 This is equivalent to \fB\-o all\fR.
 .TP
 .B \-v, \-\-verbose
 This is equivalent to \fB\-o all\fR.
 .TP
+.B \-l, \-\-list
+Print information in list form.
+.TP
 .BI "\-S, \-\-since " file
 Instead of printing current statistics, 
 .B nfsstat
 .BI "\-S, \-\-since " file
 Instead of printing current statistics, 
 .B nfsstat