Index: usr.bin/systat/Makefile =================================================================== --- usr.bin/systat/Makefile +++ usr.bin/systat/Makefile @@ -16,6 +16,6 @@ WARNS?= 1 -LIBADD= ncursesw m devstat kvm +LIBADD= ncursesw m devstat kvm util .include Index: usr.bin/systat/vmstat.c =================================================================== --- usr.bin/systat/vmstat.c +++ usr.bin/systat/vmstat.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,7 @@ #define oldnchtotal s1.nchstats static enum state { BOOT, TIME, RUN } state = TIME; +enum divider { IEC = 0, SI = HN_DIVISOR_1000 }; static void allocinfo(struct Info *); static void copyinfo(struct Info *, struct Info *); @@ -136,6 +138,8 @@ 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 real_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); @@ -489,15 +493,15 @@ 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); @@ -507,7 +511,7 @@ PUTRATE(v_cow_faults, VMSTATROW + 1, VMSTATCOL + 2, 8 - 2); PUTRATE(v_zfod, VMSTATROW + 2, VMSTATCOL + 2, 8 - 2); PUTRATE(v_ozfod, VMSTATROW + 3, VMSTATCOL, 8); - putint(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0, + putuint64(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0, VMSTATROW + 4, VMSTATCOL + 1, 8 - 1); PUTRATE(v_dfree, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2); PUTRATE(v_pfree, VMSTATROW + 6, VMSTATCOL + 2, 8 - 2); @@ -516,13 +520,13 @@ 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); @@ -556,7 +560,7 @@ putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7); putint(s.freevnodes, VNSTATROW + 3, VNSTATCOL, 7); putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 8); - putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), + putuint64((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), NAMEIROW + 2, NAMEICOL + 9, 7); #define nz(x) ((x) ? (x) : 1) putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) * @@ -663,9 +667,22 @@ static void putint(int n, int l, int lc, int w) +{ + real_putuint64(n, l, lc, w, SI); +} + +static void +putuint64(uint64_t n, int l, int lc, int w) +{ + real_putuint64(n, l, lc, w, IEC); +} + +static void +real_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 @@ -678,11 +695,12 @@ 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('*');