Index: usr.bin/systat/vmstat.c =================================================================== --- usr.bin/systat/vmstat.c +++ usr.bin/systat/vmstat.c @@ -66,6 +66,7 @@ #include #include #include +#include #include "systat.h" #include "extern.h" #include "devs.h" @@ -130,12 +131,11 @@ #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 *); static float cputime(int); -static void do_putuint64(uint64_t, int, int, int, int); +static void do_putuint64(uint64_t, int, int, int, bool); static void getinfo(struct Info *); static void putuint64(uint64_t, int, int, int); static int ucount(void); @@ -304,13 +304,11 @@ clear(); mvprintw(STATROW, STATCOL + 6, "users Load"); mvprintw(STATROW + 1, STATCOL + 3, "Mem usage: %%Phy %%Kmem"); - mvprintw(MEMROW, MEMCOL, "Mem: KB REAL VIRTUAL"); - mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); - mvprintw(MEMROW + 2, MEMCOL, "Act"); - mvprintw(MEMROW + 3, MEMCOL, "All"); + mvprintw(MEMROW, MEMCOL, "Memory: REAL VIRTUAL"); + mvprintw(MEMROW + 1, MEMCOL, " Total Share Total Share Free"); + mvprintw(MEMROW + 2, MEMCOL, " Act"); + mvprintw(MEMROW + 3, MEMCOL, " All"); - mvprintw(MEMROW + 1, MEMCOL + 41, "Free"); - mvprintw(PAGEROW, PAGECOL, " VN PAGER SWAP PAGER"); mvprintw(PAGEROW + 1, PAGECOL, " in out in out"); mvprintw(PAGEROW + 2, PAGECOL, "count"); @@ -343,7 +341,7 @@ mvprintw(GRAPHROW, GRAPHCOL, " . %%Sys . %%Intr . %%User . %%Nice . %%Idle"); - mvprintw(PROCSROW, PROCSCOL, "Proc:"); + mvprintw(PROCSROW, PROCSCOL, "Threads:"); mvprintw(PROCSROW + 1, PROCSCOL, " r p d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, "| | | | | | | | | | |"); @@ -454,21 +452,21 @@ putfloat(avenrun[1], STATROW, STATCOL + 26, 5, 2, 0); putfloat(avenrun[2], STATROW, STATCOL + 32, 5, 2, 0); mvaddstr(STATROW, STATCOL + 55, buf); -#define pgtokb(pg) ((pg) * (s.v_page_size / 1024)) +#define pgtob(pg) ((uint64_t)(pg) * s.v_page_size) putfloat(100.0 * (v_page_count - total.t_free) / v_page_count, STATROW + 1, STATCOL + 15, 2, 0, 1); putfloat(100.0 * s.v_kmem_map_size / kmem_size, STATROW + 1, STATCOL + 22, 2, 0, 1); - 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); + putuint64(pgtob(total.t_arm), MEMROW + 2, MEMCOL + 7, 5); + putuint64(pgtob(total.t_armshr), MEMROW + 2, MEMCOL + 13, 5); + putuint64(pgtob(total.t_avm), MEMROW + 2, MEMCOL + 21, 5); + putuint64(pgtob(total.t_avmshr), MEMROW + 2, MEMCOL + 27, 5); + putuint64(pgtob(total.t_rm), MEMROW + 3, MEMCOL + 7, 5); + putuint64(pgtob(total.t_rmshr), MEMROW + 3, MEMCOL + 13, 5); + putuint64(pgtob(total.t_vm), MEMROW + 3, MEMCOL + 21, 5); + putuint64(pgtob(total.t_vmshr), MEMROW + 3, MEMCOL + 27, 5); + putuint64(pgtob(total.t_free), MEMROW + 2, MEMCOL + 36, 5); 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); @@ -487,11 +485,11 @@ PUTRATE(v_pdwakeups, VMSTATROW + 9, VMSTATCOL, 8); PUTRATE(v_pdpages, VMSTATROW + 10, VMSTATCOL, 8); PUTRATE(v_intrans, VMSTATROW + 11, 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); + putuint64(pgtob(s.v_wire_count), VMSTATROW + 12, VMSTATCOL + 2, 6); + putuint64(pgtob(s.v_active_count), VMSTATROW + 13, VMSTATCOL + 2, 6); + putuint64(pgtob(s.v_inactive_count), VMSTATROW + 14, VMSTATCOL + 2, 6); + putuint64(pgtob(s.v_laundry_count), VMSTATROW + 15, VMSTATCOL + 2, 6); + putuint64(pgtob(s.v_free_count), VMSTATROW + 16, VMSTATCOL + 2, 6); if (LINES - 1 > VMSTATROW + 17) putuint64(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8); PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5); @@ -633,18 +631,18 @@ putint(int n, int l, int lc, int w) { - do_putuint64(n, l, lc, w, SI); + do_putuint64(n, l, lc, w, false); } static void putuint64(uint64_t n, int l, int lc, int w) { - do_putuint64(n, l, lc, w, IEC); + do_putuint64(n, l, lc, w, true); } static void -do_putuint64(uint64_t n, int l, int lc, int w, int div) +do_putuint64(uint64_t n, int l, int lc, int w, bool bytes) { int snr; char b[128]; @@ -661,10 +659,13 @@ addch(' '); return; } - snr = snprintf(b, sizeof(b), "%*ju", w, (uintmax_t)n); - if (snr != w) { - humanize_number(buf, w, n, "", HN_AUTOSCALE, - HN_NOSPACE | HN_DECIMAL | div); + if (!bytes) /* try to get an exact representation first */ + snr = snprintf(b, sizeof(b), "%*ju", w, (uintmax_t)n); + else + snr = 0; + if (snr != w) { /* too large, try to condense */ + humanize_number(buf, w + 1, n, "", HN_AUTOSCALE, + HN_NOSPACE | HN_DECIMAL | (bytes ? HN_B : HN_DIVISOR_1000)); snr = snprintf(b, sizeof(b), "%*s", w, buf); } if (snr != w) {