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, int, 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 void get_stats(const char *, struct statinfo *, int *, int,
int);
static int has_stats(const unsigned int *);
+static int has_rpcstats(const unsigned int *, int);
static void diff_stats(struct statinfo *, struct statinfo *, int);
static void unpause(int);
static void update_old_counters(struct statinfo *, 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;
int
main(int argc, char **argv)
opt_srv = 0,
opt_clt = 0,
opt_prt = 0,
- opt_sleep = 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_srv, opt_clt, opt_prt);
+ } else {
+ print_all_stats(opt_srv, opt_clt, opt_prt);
+ }
fflush(stdout);
- update_old_counters(clientinfo_tmp, clientinfo);
+ if (opt_srv)
+ update_old_counters(serverinfo_tmp, serverinfo);
+ if (opt_clt)
+ 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_srv, opt_clt, opt_prt);
+ } else {
+ print_all_stats(opt_srv, opt_clt, opt_prt);
+ }
}
return 0;
static void
print_server_stats(int opt_srv, int opt_prt)
{
- if (opt_srv) {
- if (opt_prt & PRNT_NET) {
- print_numbers(
- LABEL_srvnet
- "packets udp tcp tcpconn\n",
- srvnetinfo, 4
- );
+ if (!opt_srv)
+ return;
+
+ if (opt_prt & PRNT_NET) {
+ if (opt_sleep && !has_rpcstats(srvnetinfo, 4)) {
+ } else {
+ print_numbers( LABEL_srvnet
+ "packets udp tcp tcpconn\n",
+ srvnetinfo, 4);
printf("\n");
}
- if (opt_prt & PRNT_RPC) {
- print_numbers(
- LABEL_srvrpc
- "calls badcalls badauth badclnt xdrcall\n",
- srvrpcinfo, 5
- );
+ }
+ if (opt_prt & PRNT_RPC) {
+ if (opt_sleep && !has_rpcstats(srvrpcinfo, 5)) {
+ ;
+ } else {
+ print_numbers(LABEL_srvrpc
+ "calls badcalls badauth badclnt xdrcall\n",
+ srvrpcinfo, 5);
printf("\n");
}
- if (opt_prt & PRNT_RC) {
- print_numbers(
- LABEL_srvrc
- "hits misses nocache\n",
- srvrcinfo, 3
- );
+ }
+ if (opt_prt & PRNT_RC) {
+ if (opt_sleep && !has_rpcstats(srvrcinfo, 3)) {
+ ;
+ } else {
+ print_numbers(LABEL_srvrc
+ "hits misses nocache\n",
+ srvrcinfo, 3);
printf("\n");
}
+ }
- /*
- * 2.2 puts all fh-related info after the 'rc' header
- * 2.4 puts all fh-related info after the 'fh' header, but relocates
- * 'stale' to the start and swaps dir and nondir :-(
- * We preseve the 2.2 order
- */
- if (opt_prt & PRNT_FH) {
- if (get_stat_info("fh", srvinfo)) { /* >= 2.4 */
- int t = srvfhinfo[3];
- srvfhinfo[3]=srvfhinfo[4];
- srvfhinfo[4]=t;
-
- srvfhinfo[5]=srvfhinfo[0]; /* relocate 'stale' */
-
- print_numbers(
- LABEL_srvfh
- "lookup anon ncachedir ncachedir stale\n",
- srvfhinfo + 1, 5);
- } else /* < 2.4 */
- print_numbers(
- LABEL_srvfh
- "lookup anon ncachedir ncachedir stale\n",
- srvrcinfo + 3, 5);
- printf("\n");
+ /*
+ * 2.2 puts all fh-related info after the 'rc' header
+ * 2.4 puts all fh-related info after the 'fh' header, but relocates
+ * 'stale' to the start and swaps dir and nondir :-(
+ * We preseve the 2.2 order
+ */
+ if (opt_prt & PRNT_FH) {
+ if (get_stat_info("fh", srvinfo)) { /* >= 2.4 */
+ int t = srvfhinfo[3];
+ srvfhinfo[3]=srvfhinfo[4];
+ srvfhinfo[4]=t;
+
+ srvfhinfo[5]=srvfhinfo[0]; /* relocate 'stale' */
+
+ print_numbers(
+ LABEL_srvfh
+ "lookup anon ncachedir ncachedir stale\n",
+ srvfhinfo + 1, 5);
+ } else /* < 2.4 */
+ print_numbers(
+ LABEL_srvfh
+ "lookup anon ncachedir ncachedir stale\n",
+ srvrcinfo + 3, 5);
+ printf("\n");
+ }
+ if (opt_prt & PRNT_CALLS) {
+ if ((opt_prt & PRNT_V2) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(srvproc2info))) {
+ if (opt_sleep && !has_stats(srvproc2info)) {
+ ;
+ } else {
+ print_callstats(LABEL_srvproc2,
+ nfsv2name, srvproc2info + 1,
+ sizeof(nfsv2name)/sizeof(char *));
+ }
}
- if (opt_prt & PRNT_CALLS) {
- if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && has_stats(srvproc2info)))
- print_callstats(
- LABEL_srvproc2,
- nfsv2name, srvproc2info + 1, sizeof(nfsv2name)/sizeof(char *)
- );
- if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && has_stats(srvproc3info)))
- print_callstats(
- LABEL_srvproc3,
- nfsv3name, srvproc3info + 1, sizeof(nfsv3name)/sizeof(char *)
- );
- if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && has_stats(srvproc4info))) {
- print_callstats(
- LABEL_srvproc4,
- nfssrvproc4name, srvproc4info + 1, sizeof(nfssrvproc4name)/sizeof(char *)
- );
- print_callstats(
- LABEL_srvproc4ops,
- nfssrvproc4opname, srvproc4opsinfo + 1, sizeof(nfssrvproc4opname)/sizeof(char *)
- );
+ if ((opt_prt & PRNT_V3) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(srvproc3info))) {
+ if (opt_sleep && !has_stats(srvproc3info)) {
+ ;
+ } else {
+ print_callstats(LABEL_srvproc3,
+ nfsv3name, srvproc3info + 1,
+ sizeof(nfsv3name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V4) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(srvproc4info))) {
+ if (opt_sleep && !has_stats(srvproc4info)) {
+ ;
+ } else {
+ print_callstats( LABEL_srvproc4,
+ nfssrvproc4name, srvproc4info + 1,
+ sizeof(nfssrvproc4name)/sizeof(char *));
+ print_callstats(LABEL_srvproc4ops,
+ nfssrvproc4opname, srvproc4opsinfo + 1,
+ sizeof(nfssrvproc4opname)/sizeof(char *));
}
}
}
static void
print_client_stats(int opt_clt, int opt_prt)
{
- if (opt_clt) {
- if (opt_prt & PRNT_NET) {
- print_numbers(
- LABEL_cltnet
- "packets udp tcp tcpconn\n",
- cltnetinfo, 4
- );
+ if (!opt_clt)
+ return;
+
+ if (opt_prt & PRNT_NET) {
+ if (opt_sleep && !has_rpcstats(cltnetinfo, 4)) {
+ ;
+ } else {
+ print_numbers(LABEL_cltnet
+ "packets udp tcp tcpconn\n",
+ cltnetinfo, 4);
printf("\n");
}
- if (opt_prt & PRNT_RPC) {
- print_numbers(
- LABEL_cltrpc
- "calls retrans authrefrsh\n",
- cltrpcinfo, 3
- );
+ }
+ if (opt_prt & PRNT_RPC) {
+ if (opt_sleep && !has_rpcstats(cltrpcinfo, 3)) {
+ ;
+ } else {
+ print_numbers(LABEL_cltrpc
+ "calls retrans authrefrsh\n",
+ cltrpcinfo, 3);
printf("\n");
}
- if (opt_prt & PRNT_CALLS) {
- if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && has_stats(cltproc2info)))
- print_callstats(
- LABEL_cltproc2,
- nfsv2name, cltproc2info + 1, sizeof(nfsv2name)/sizeof(char *)
- );
- if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && has_stats(cltproc3info)))
- print_callstats(
- LABEL_cltproc3,
- nfsv3name, cltproc3info + 1, sizeof(nfsv3name)/sizeof(char *)
- );
- if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && has_stats(cltproc4info)))
- print_callstats(
- LABEL_cltproc4,
- nfscltproc4name, cltproc4info + 1, sizeof(nfscltproc4name)/sizeof(char *)
- );
+ }
+ if (opt_prt & PRNT_CALLS) {
+ if ((opt_prt & PRNT_V2) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(cltproc2info))) {
+ if (opt_sleep && !has_stats(cltproc2info)) {
+ ;
+ } else {
+ print_callstats(LABEL_cltproc2,
+ nfsv2name, cltproc2info + 1,
+ sizeof(nfsv2name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V3) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(cltproc3info))) {
+ if (opt_sleep && !has_stats(cltproc3info)) {
+ ;
+ } else {
+ print_callstats(LABEL_cltproc3,
+ nfsv3name, cltproc3info + 1,
+ sizeof(nfsv3name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V4) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(cltproc4info))) {
+ if (opt_sleep && !has_stats(cltproc4info)) {
+ ;
+ } else {
+ print_callstats(LABEL_cltproc4,
+ nfscltproc4name, cltproc4info + 1,
+ sizeof(nfscltproc4name)/sizeof(char *));
+ }
+ }
+ }
+}
+
+static void
+print_clnt_list(int opt_prt)
+{
+ if (opt_prt & PRNT_CALLS) {
+ if ((opt_prt & PRNT_V2) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(cltproc2info))) {
+ if (opt_sleep && !has_stats(cltproc2info)) {
+ ;
+ } else {
+ print_callstats_list("nfs v2 client",
+ nfsv2name, cltproc2info + 1,
+ sizeof(nfsv2name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V3) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(cltproc3info))) {
+ if (opt_sleep && !has_stats(cltproc3info)) {
+ ;
+ } else {
+ print_callstats_list("nfs v3 client",
+ nfsv3name, cltproc3info + 1,
+ sizeof(nfsv3name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V4) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(cltproc4info))) {
+ if (opt_sleep && !has_stats(cltproc4info)) {
+ ;
+ } else {
+ print_callstats_list("nfs v4 ops",
+ nfssrvproc4opname, srvproc4opsinfo + 1,
+ sizeof(nfssrvproc4opname)/sizeof(char *));
+ print_callstats_list("nfs v4 client",
+ nfscltproc4name, cltproc4info + 1,
+ sizeof(nfscltproc4name)/sizeof(char *));
+ }
}
}
}
+static void
+print_serv_list(int opt_prt)
+{
+ if (opt_prt & PRNT_CALLS) {
+ if ((opt_prt & PRNT_V2) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(srvproc2info))) {
+ if (opt_sleep && !has_stats(srvproc2info)) {
+ ;
+ } else {
+ print_callstats_list("nfs v2 server",
+ nfsv2name, srvproc2info + 1,
+ sizeof(nfsv2name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V3) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(srvproc3info))) {
+ if (opt_sleep && !has_stats(srvproc3info)) {
+ ;
+ } else {
+ print_callstats_list("nfs v3 server",
+ nfsv3name, srvproc3info + 1,
+ sizeof(nfsv3name)/sizeof(char *));
+ }
+ }
+ if ((opt_prt & PRNT_V4) ||
+ ((opt_prt & PRNT_AUTO) && has_stats(srvproc4opsinfo))) {
+ if (opt_sleep && !has_stats(srvproc4info)) {
+ ;
+ } else {
+ print_callstats_list("nfs v4 ops",
+ nfssrvproc4opname, srvproc4opsinfo + 1,
+ sizeof(nfssrvproc4opname)/sizeof(char *));
+ }
+ }
+ }
+}
+static void
+print_stats_list(int opt_srv, int opt_clt, int opt_prt)
+{
+ if (opt_srv)
+ print_serv_list(opt_prt);
+
+ if (opt_clt)
+ print_clnt_list(opt_prt);
+}
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];
+ }
+ if (!calltotal)
+ return;
+ printf("%13s %13s %8llu \n", hdr, "total:", calltotal);
+ printf("------------- ------------- --------\n");
+ for (i = 0; i < nr; i++) {
+ if (callinfo[i])
+ printf("%13s %12s: %8u \n", hdr, names[i], callinfo[i]);
+ }
+ printf("\n");
+
+}
+
+
/* returns 0 on success, 1 otherwise */
static int
parse_raw_statfile(const char *name, struct statinfo *statp)
{
return (info[0] && info[info[0] + 1] > info[0]);
}
+static int
+has_rpcstats(const unsigned int *info, int size)
+{
+ int i, cnt;
+
+ for (i=0, cnt=0; i < size; i++)
+ cnt += info[i];
+ return cnt;
+}
/*
* take the difference of each individual stat value in 'new' and 'old'