Date: Fri, 17 Feb 2012 08:24:58 +0000 (UTC) From: Adrian Chadd <adrian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r231863 - head/tools/tools/ath/athstats Message-ID: <201202170824.q1H8OwX0057533@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: adrian Date: Fri Feb 17 08:24:58 2012 New Revision: 231863 URL: http://svn.freebsd.org/changeset/base/231863 Log: Fix up this local copy of statfoo to support > 128 statistics. This allows all of the athstats statistics to work again. Specifics: * The previous code used chars < 0x80 as printable, and chars >= 0x80 as "statistics" * .. which meant any statistic above 127 would wrap around to 0; * .. so once I added the 802.11n TX/RX statistics to athstats, the tail end of the statistics list weren't accessible. This patch: * adds a define which represents the magic character, rather than a hard coded one * the statistic in question is little endian encoded after the magic character. Notes: * statfoo is useful enough to possibly warrant turning into a library API. Modified: head/tools/tools/ath/athstats/statfoo.c head/tools/tools/ath/athstats/statfoo.h Modified: head/tools/tools/ath/athstats/statfoo.c ============================================================================== --- head/tools/tools/ath/athstats/statfoo.c Fri Feb 17 07:59:37 2012 (r231862) +++ head/tools/tools/ath/athstats/statfoo.c Fri Feb 17 08:24:58 2012 (r231863) @@ -60,7 +60,9 @@ statfoo_setfmt(struct statfoo *sf, const } if (j != 0) sf->fmts[j++] = ' '; - sf->fmts[j++] = 0x80 | i; + sf->fmts[j++] = FMTS_IS_STAT; + sf->fmts[j++] = i & 0xff; + sf->fmts[j++] = (i >> 8) & 0xff; } sf->fmts[j] = '\0'; #undef N @@ -89,10 +91,14 @@ static void statfoo_print_header(struct statfoo *sf, FILE *fd) { const unsigned char *cp; + int i; + const struct fmt *f; for (cp = sf->fmts; *cp != '\0'; cp++) { - if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; + if (*cp == FMTS_IS_STAT) { + i = *(++cp); + i |= ((int) *(++cp)) << 8; + f = &sf->stats[i]; fprintf(fd, "%*s", f->width, f->label); } else putc(*cp, fd); @@ -105,11 +111,15 @@ statfoo_print_current(struct statfoo *sf { char buf[32]; const unsigned char *cp; + int i; + const struct fmt *f; for (cp = sf->fmts; *cp != '\0'; cp++) { - if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; - if (sf->get_curstat(sf, *cp &~ 0x80, buf, sizeof(buf))) + if (*cp == FMTS_IS_STAT) { + i = *(++cp); + i |= ((int) *(++cp)) << 8; + f = &sf->stats[i]; + if (sf->get_curstat(sf, i, buf, sizeof(buf))) fprintf(fd, "%*s", f->width, buf); } else putc(*cp, fd); @@ -122,11 +132,15 @@ statfoo_print_total(struct statfoo *sf, { char buf[32]; const unsigned char *cp; + const struct fmt *f; + int i; for (cp = sf->fmts; *cp != '\0'; cp++) { - if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; - if (sf->get_totstat(sf, *cp &~ 0x80, buf, sizeof(buf))) + if (*cp == FMTS_IS_STAT) { + i = *(++cp); + i |= ((int) *(++cp)) << 8; + f = &sf->stats[i]; + if (sf->get_totstat(sf, i, buf, sizeof(buf))) fprintf(fd, "%*s", f->width, buf); } else putc(*cp, fd); Modified: head/tools/tools/ath/athstats/statfoo.h ============================================================================== --- head/tools/tools/ath/athstats/statfoo.h Fri Feb 17 07:59:37 2012 (r231862) +++ head/tools/tools/ath/athstats/statfoo.h Fri Feb 17 08:24:58 2012 (r231863) @@ -79,6 +79,7 @@ struct statfoo { const char *name; /* statistics name, e.g. wlanstats */ const struct fmt *stats; /* statistics in class */ int nstats; /* number of stats */ +#define FMTS_IS_STAT 0x80 /* the following two bytes are the stat id */ unsigned char fmts[4096]; /* private: compiled stats to display */ STATFOO_DECL_METHODS(struct statfoo *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202170824.q1H8OwX0057533>