diff options
author | david m. richter <richterd@citi.umich.edu> | 2007-08-07 19:53:00 -0400 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2007-08-09 11:08:28 +1000 |
commit | 431593f9f485d47aafc7750f356bd45565182c5e (patch) | |
tree | 1b624d0d69139519724f3fc071ac2f36eca74813 | |
parent | 2357159ef3896a2f8d3fd74fb5d97a9a7d42986b (diff) | |
download | nfs-utils-431593f9f485d47aafc7750f356bd45565182c5e.tar.gz nfs-utils-431593f9f485d47aafc7750f356bd45565182c5e.tar.xz nfs-utils-431593f9f485d47aafc7750f356bd45565182c5e.zip |
nfsstat: fix a bug in diff_stats()
Fix a bug in diff_stats() that causes false-positives in
has_stats(), which can result in a bunch of zeros being displayed instead
of suppressed as intended.
Signed-off-by: David M. Richter <richterd@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
-rw-r--r-- | utils/nfsstat/nfsstat.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c index eb6e45d..1c44050 100644 --- a/utils/nfsstat/nfsstat.c +++ b/utils/nfsstat/nfsstat.c @@ -671,16 +671,37 @@ copy_stats(struct statinfo *dest, struct statinfo *src) static void diff_stats(struct statinfo *new, struct statinfo *old) { - int i, j, is_srv, should_diff; - + int i, j, is_srv, nodiff_first_index, should_diff; + + /* + * Different stat types have different formats in the /proc + * files: for the proc2/3/4-type stats, the first entry has + * the total number of subsequent entries; one does not want + * to diff that first entry. The other stat types aren't like + * this. So, we diff a given entry if it's not of one of the + * procX types ("i" < 2 for clt, < 4 for srv), or if it's not + * the first entry ("j" > 0). + */ is_srv = (new == srvinfo); + nodiff_first_index = 2 + (2 * is_srv); + for (i = 0; old[i].tag; i++) { for (j = 0; j < new[i].nrvals; j++) { - /* skip items in valptr that shouldn't be changed */ - should_diff = (i < (3 + is_srv) || j > 0); + should_diff = (i < nodiff_first_index || j > 0); if (should_diff) new[i].valptr[j] -= old[i].valptr[j]; } + + /* + * Make sure that the "totals" entry (last value in + * each stat array) for the procX-type stats has the + * "numentries" entry's (first value in procX-type + * stat arrays) constant value added-back after the + * diff -- i.e., it should always be included in the + * total. + */ + if (!strncmp("proc", new[i].tag, 4)) + new[i].valptr[new[i].nrvals - 1] += new[i].valptr[0]; } } |