From owner-svn-src-head@freebsd.org Wed Sep 2 18:42:36 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2A9909C8E96; Wed, 2 Sep 2015 18:42:36 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1AE0AD61; Wed, 2 Sep 2015 18:42:36 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t82IgZdn069909; Wed, 2 Sep 2015 18:42:35 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t82IgZxt069908; Wed, 2 Sep 2015 18:42:35 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201509021842.t82IgZxt069908@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Wed, 2 Sep 2015 18:42:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287406 - head/usr.bin/netstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2015 18:42:36 -0000 Author: hrs Date: Wed Sep 2 18:42:35 2015 New Revision: 287406 URL: https://svnweb.freebsd.org/changeset/base/287406 Log: Divide statistics in the number of packets with 1000 instead of 1024 in human-readable form. PR: 183598 Modified: head/usr.bin/netstat/if.c Modified: head/usr.bin/netstat/if.c ============================================================================== --- head/usr.bin/netstat/if.c Wed Sep 2 17:29:30 2015 (r287405) +++ head/usr.bin/netstat/if.c Wed Sep 2 18:42:35 2015 (r287406) @@ -201,7 +201,7 @@ pfsync_stats(u_long off, const char *nam */ static void show_stat(const char *fmt, int width, const char *name, - u_long value, short showvalue) + u_long value, short showvalue, int div1000) { const char *lsep, *rsep; char newfmt[64]; @@ -238,7 +238,8 @@ show_stat(const char *fmt, int width, co /* 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)); maybe_pad(lsep); snprintf(newfmt, sizeof(newfmt), "{:%s/%%%ds}", name, width); xo_emit(newfmt, buf); @@ -353,7 +354,7 @@ intpr(void (*pfunc)(char *), int af) name, ifa->ifa_flags, xname); #define IFA_MTU(ifa) (((struct if_data *)(ifa)->ifa_data)->ifi_mtu) - show_stat("lu", 6, "mtu", IFA_MTU(ifa), IFA_MTU(ifa)); + show_stat("lu", 6, "mtu", IFA_MTU(ifa), IFA_MTU(ifa), 0); #undef IFA_MTU switch (ifa->ifa_addr->sa_family) { @@ -416,22 +417,25 @@ intpr(void (*pfunc)(char *), int af) #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) show_stat("lu", 8, "received-packets", IFA_STAT(ipackets), - link|network); - show_stat("lu", 5, "received-errors", IFA_STAT(ierrors), link); - show_stat("lu", 5, "dropped-packets", IFA_STAT(iqdrops), link); + link|network, 1); + show_stat("lu", 5, "received-errors", IFA_STAT(ierrors), + link, 1); + show_stat("lu", 5, "dropped-packets", IFA_STAT(iqdrops), + link, 1); if (bflag) show_stat("lu", 10, "received-bytes", IFA_STAT(ibytes), - link|network); + link|network, 0); show_stat("lu", 8, "sent-packets", IFA_STAT(opackets), - link|network); - show_stat("lu", 5, "send-errors", IFA_STAT(oerrors), link); + link|network, 1); + show_stat("lu", 5, "send-errors", IFA_STAT(oerrors), link, 1); if (bflag) show_stat("lu", 10, "sent-bytes", IFA_STAT(obytes), - link|network); - show_stat("NRSlu", 5, "collisions", IFA_STAT(collisions), link); + link|network, 0); + show_stat("NRSlu", 5, "collisions", IFA_STAT(collisions), + link, 1); if (dflag) show_stat("LSlu", 5, "dropped-packets", - IFA_STAT(oqdrops), link); + IFA_STAT(oqdrops), link, 1); xo_emit("\n"); if (!aflag) { @@ -616,24 +620,24 @@ loop: xo_open_instance("stats"); show_stat("lu", 10, "received-packets", - new->ift_ip - old->ift_ip, 1); + new->ift_ip - old->ift_ip, 1, 1); show_stat("lu", 5, "received-errors", - new->ift_ie - old->ift_ie, 1); + new->ift_ie - old->ift_ie, 1, 1); show_stat("lu", 5, "dropped-packets", - new->ift_id - old->ift_id, 1); + new->ift_id - old->ift_id, 1, 1); show_stat("lu", 10, "received-bytes", - new->ift_ib - old->ift_ib, 1); + new->ift_ib - old->ift_ib, 1, 0); show_stat("lu", 10, "sent-packets", - new->ift_op - old->ift_op, 1); + new->ift_op - old->ift_op, 1, 1); show_stat("lu", 5, "send-errors", - new->ift_oe - old->ift_oe, 1); + new->ift_oe - old->ift_oe, 1, 1); show_stat("lu", 10, "sent-bytes", - new->ift_ob - old->ift_ob, 1); + new->ift_ob - old->ift_ob, 1, 0); show_stat("NRSlu", 5, "collisions", - new->ift_co - old->ift_co, 1); + new->ift_co - old->ift_co, 1, 1); if (dflag) show_stat("LSlu", 5, "dropped-packets", - new->ift_od - old->ift_od, 1); + new->ift_od - old->ift_od, 1, 1); xo_close_instance("stats"); xo_emit("\n"); xo_flush();