MFC r287406:

Divide statistics in the number of packets with 1000 instead of 1024
in human-readable form.

PR:	183598
This commit is contained in:
hrs 2015-09-09 08:40:17 +00:00
parent bd8403067b
commit c02639b794

View File

@ -165,7 +165,8 @@ pfsync_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
* Display a formatted value, or a '-' in the same space.
*/
static void
show_stat(const char *fmt, int width, u_long value, short showvalue)
show_stat(const char *fmt, int width, u_long value, short showvalue,
int div1000)
{
const char *lsep, *rsep;
char newfmt[32];
@ -192,7 +193,8 @@ show_stat(const char *fmt, int width, u_long value, short showvalue)
/* Format in human readable form. */
humanize_number(buf, sizeof(buf), (int64_t)value, "",
HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL | \
((div1000) ? HN_DIVISOR_1000 : 0));
sprintf(newfmt, "%s%%%ds%s", lsep, width, rsep);
printf(newfmt, buf);
} else {
@ -287,7 +289,7 @@ intpr(int interval, void (*pfunc)(char *), int af)
printf("%-5.5s", ifa->ifa_name);
#define IFA_MTU(ifa) (((struct if_data *)(ifa)->ifa_data)->ifi_mtu)
show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa));
show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa), 0);
#undef IFA_MTU
switch (ifa->ifa_addr->sa_family) {
@ -373,18 +375,18 @@ intpr(int interval, void (*pfunc)(char *), int af)
}
#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
show_stat("lu", 8, IFA_STAT(ipackets), link|network);
show_stat("lu", 5, IFA_STAT(ierrors), link);
show_stat("lu", 5, IFA_STAT(iqdrops), link);
show_stat("lu", 8, IFA_STAT(ipackets), link|network, 1);
show_stat("lu", 5, IFA_STAT(ierrors), link, 1);
show_stat("lu", 5, IFA_STAT(iqdrops), link, 1);
if (bflag)
show_stat("lu", 10, IFA_STAT(ibytes), link|network);
show_stat("lu", 8, IFA_STAT(opackets), link|network);
show_stat("lu", 5, IFA_STAT(oerrors), link);
show_stat("lu", 10, IFA_STAT(ibytes), link|network, 0);
show_stat("lu", 8, IFA_STAT(opackets), link|network, 1);
show_stat("lu", 5, IFA_STAT(oerrors), link, 1);
if (bflag)
show_stat("lu", 10, IFA_STAT(obytes), link|network);
show_stat("NRSlu", 5, IFA_STAT(collisions), link);
show_stat("lu", 10, IFA_STAT(obytes), link|network, 0);
show_stat("NRSlu", 5, IFA_STAT(collisions), link, 1);
if (dflag)
show_stat("LSlu", 5, IFA_STAT(oqdrops), link);
show_stat("LSlu", 5, IFA_STAT(oqdrops), link, 1);
putchar('\n');
if (!aflag)
@ -569,16 +571,16 @@ sidewaysintpr(int interval)
fill_iftot(new);
show_stat("lu", 10, new->ift_ip - old->ift_ip, 1);
show_stat("lu", 5, new->ift_ie - old->ift_ie, 1);
show_stat("lu", 5, new->ift_id - old->ift_id, 1);
show_stat("lu", 10, new->ift_ib - old->ift_ib, 1);
show_stat("lu", 10, new->ift_op - old->ift_op, 1);
show_stat("lu", 5, new->ift_oe - old->ift_oe, 1);
show_stat("lu", 10, new->ift_ob - old->ift_ob, 1);
show_stat("NRSlu", 5, new->ift_co - old->ift_co, 1);
show_stat("lu", 10, new->ift_ip - old->ift_ip, 1, 1);
show_stat("lu", 5, new->ift_ie - old->ift_ie, 1, 1);
show_stat("lu", 5, new->ift_id - old->ift_id, 1, 1);
show_stat("lu", 10, new->ift_ib - old->ift_ib, 1, 0);
show_stat("lu", 10, new->ift_op - old->ift_op, 1, 1);
show_stat("lu", 5, new->ift_oe - old->ift_oe, 1, 1);
show_stat("lu", 10, new->ift_ob - old->ift_ob, 1, 0);
show_stat("NRSlu", 5, new->ift_co - old->ift_co, 1, 1);
if (dflag)
show_stat("LSlu", 5, new->ift_od - old->ift_od, 1);
show_stat("LSlu", 5, new->ift_od - old->ift_od, 1, 1);
putchar('\n');
fflush(stdout);