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 *);
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", 0, 0, '\2' },
{ "sleep", 2, 0, 'Z' },
{ "since", 1, 0, 'S' },
+ { "list", 0, 0, 'l' },
{ NULL, 0, 0, 0 }
};
int opt_sleep;
opt_clt = 0,
opt_prt = 0,
sleep_time = 0,
+ opt_list =0,
opt_since = 0;
int c;
char *progname,
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");
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");
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;
}
}
+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)
{
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)