From owner-svn-src-all@freebsd.org Tue Nov 21 19:55:33 2017 Return-Path: Delivered-To: svn-src-all@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 60EDEDF7EA1; Tue, 21 Nov 2017 19:55:33 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 3B3D87DA0F; Tue, 21 Nov 2017 19:55:33 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vALJtWPV047908; Tue, 21 Nov 2017 19:55:32 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vALJtWhg047906; Tue, 21 Nov 2017 19:55:32 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201711211955.vALJtWhg047906@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 21 Nov 2017 19:55:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326073 - head/usr.bin/systat X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/usr.bin/systat X-SVN-Commit-Revision: 326073 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Nov 2017 19:55:33 -0000 Author: kib Date: Tue Nov 21 19:55:32 2017 New Revision: 326073 URL: https://svnweb.freebsd.org/changeset/base/326073 Log: systat: use and correctly display 64bit counters. Following struct vmtotal changes, make systat use and correctly display 64-bit counters. Switch to humanize_number(3) to overcome homegrown arithmetics limits in pretty printing large numbers. Use 1024 as a divisor for memory fields to make it consistent with other tools and users expectations. Submitted by: Pawel Biernacki Sponsored by: Mysterious Code Ltd. PR: 2137 Differential revision: https://reviews.freebsd.org/D13105 Modified: head/usr.bin/systat/Makefile head/usr.bin/systat/vmstat.c Modified: head/usr.bin/systat/Makefile ============================================================================== --- head/usr.bin/systat/Makefile Tue Nov 21 19:23:20 2017 (r326072) +++ head/usr.bin/systat/Makefile Tue Nov 21 19:55:32 2017 (r326073) @@ -16,6 +16,6 @@ CFLAGS+= -DINET6 WARNS?= 1 -LIBADD= ncursesw m devstat kvm +LIBADD= ncursesw m devstat kvm util .include Modified: head/usr.bin/systat/vmstat.c ============================================================================== --- head/usr.bin/systat/vmstat.c Tue Nov 21 19:23:20 2017 (r326072) +++ head/usr.bin/systat/vmstat.c Tue Nov 21 19:55:32 2017 (r326073) @@ -57,6 +57,7 @@ static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkel #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ struct statinfo cur, last, run; #define oldnchtotal s1.nchstats static enum state { BOOT, TIME, RUN } state = TIME; +enum divisor { IEC = 0, SI = HN_DIVISOR_1000 }; static void allocinfo(struct Info *); static void copyinfo(struct Info *, struct Info *); @@ -138,6 +140,8 @@ static float cputime(int); static void dinfo(int, int, struct statinfo *, struct statinfo *); static void getinfo(struct Info *); static void putint(int, int, int, int); +static void putuint64(uint64_t, int, int, int); +static void do_putuint64(uint64_t, int, int, int, int); static void putfloat(double, int, int, int, int, int); static void putlongdouble(long double, int, int, int, int, int); static int ucount(void); @@ -491,15 +495,15 @@ showkre(void) putfloat(100.0 * s.v_kmem_map_size / kmem_size, STATROW + 1, STATCOL + 22, 2, 0, 1); - putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); - putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); - putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8); - putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8); - putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7); - putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7); - putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8); - putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8); - putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7); + putuint64(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7); + putuint64(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7); + putuint64(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8); + putuint64(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8); + putuint64(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7); + putuint64(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7); + putuint64(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8); + putuint64(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8); + putuint64(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7); putint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3); putint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3); putint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3); @@ -518,13 +522,13 @@ showkre(void) PUTRATE(v_pdwakeups, VMSTATROW + 9, VMSTATCOL, 8); PUTRATE(v_pdpages, VMSTATROW + 10, VMSTATCOL, 8); PUTRATE(v_intrans, VMSTATROW + 11, VMSTATCOL, 8); - putint(pgtokb(s.v_wire_count), VMSTATROW + 12, VMSTATCOL, 8); - putint(pgtokb(s.v_active_count), VMSTATROW + 13, VMSTATCOL, 8); - putint(pgtokb(s.v_inactive_count), VMSTATROW + 14, VMSTATCOL, 8); - putint(pgtokb(s.v_laundry_count), VMSTATROW + 15, VMSTATCOL, 8); - putint(pgtokb(s.v_free_count), VMSTATROW + 16, VMSTATCOL, 8); + putuint64(pgtokb(s.v_wire_count), VMSTATROW + 12, VMSTATCOL, 8); + putuint64(pgtokb(s.v_active_count), VMSTATROW + 13, VMSTATCOL, 8); + putuint64(pgtokb(s.v_inactive_count), VMSTATROW + 14, VMSTATCOL, 8); + putuint64(pgtokb(s.v_laundry_count), VMSTATROW + 15, VMSTATCOL, 8); + putuint64(pgtokb(s.v_free_count), VMSTATROW + 16, VMSTATCOL, 8); if (LINES - 1 > VMSTATROW + 17) - putint(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8); + putuint64(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8); PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5); PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5); PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5); @@ -666,8 +670,23 @@ cputime(int indx) static void putint(int n, int l, int lc, int w) { + + do_putuint64(n, l, lc, w, SI); +} + +static void +putuint64(uint64_t n, int l, int lc, int w) +{ + + do_putuint64(n, l, lc, w, IEC); +} + +static void +do_putuint64(uint64_t n, int l, int lc, int w, int div) +{ int snr; char b[128]; + char buf[128]; move(l, lc); #ifdef DEBUG @@ -680,11 +699,12 @@ putint(int n, int l, int lc, int w) addch(' '); return; } - snr = snprintf(b, sizeof(b), "%*d", w, n); - if (snr != w) - snr = snprintf(b, sizeof(b), "%*dk", w - 1, n / 1000); - if (snr != w) - snr = snprintf(b, sizeof(b), "%*dM", w - 1, n / 1000000); + snr = snprintf(b, sizeof(b), "%*jd", w, (uintmax_t)n); + if (snr != w) { + humanize_number(buf, w, n, "", HN_AUTOSCALE, + HN_NOSPACE | HN_DECIMAL | div); + snr = snprintf(b, sizeof(b), "%*s", w, buf); + } if (snr != w) { while (w-- > 0) addch('*');