aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/systat/vmstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/systat/vmstat.c')
-rw-r--r--usr.bin/systat/vmstat.c221
1 files changed, 77 insertions, 144 deletions
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c
index 25f79d7e9308..ff4dbfcc2869 100644
--- a/usr.bin/systat/vmstat.c
+++ b/usr.bin/systat/vmstat.c
@@ -55,6 +55,7 @@ static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#include <err.h>
#include <errno.h>
#include <langinfo.h>
+#include <libutil.h>
#include <nlist.h>
#include <paths.h>
#include <signal.h>
@@ -63,7 +64,6 @@ static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#include <time.h>
#include <unistd.h>
#include <utmpx.h>
-#include <devstat.h>
#include "systat.h"
#include "extern.h"
#include "devs.h"
@@ -102,7 +102,6 @@ static struct Info {
/*
* Distribution of page usages.
*/
- u_int v_page_size; /* page size in bytes */
u_int v_free_count; /* number of pages free */
u_int v_wire_count; /* number of pages wired down */
u_int v_active_count; /* number of pages active */
@@ -122,22 +121,20 @@ static struct Info {
static u_long kmem_size;
static u_int v_page_count;
-struct statinfo cur, last, run;
#define total s.Total
#define nchtotal s.nchstats
#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 dinfo(int, int, struct statinfo *, struct statinfo *);
+static void do_putuint64(uint64_t, int, int, int, int);
static void getinfo(struct Info *);
-static void putint(int, int, int, int);
-static void putfloat(double, int, int, int, int, int);
-static void putlongdouble(long double, int, int, int, int, int);
+static void putuint64(uint64_t, int, int, int);
static int ucount(void);
static int ncpu;
@@ -173,15 +170,15 @@ closekre(WINDOW *w)
#define STATCOL 0
#define MEMROW 2 /* uses 4 rows and 45 cols */
#define MEMCOL 0
-#define PAGEROW 2 /* uses 4 rows and 30 cols */
+#define PAGEROW 1 /* uses 4 rows and 30 cols */
#define PAGECOL 47
-#define INTSROW 6 /* uses all rows to bottom and 16 cols */
+#define INTSROW 5 /* uses all rows to bottom and 16 cols */
#define INTSCOL 64
#define PROCSROW 6 /* uses 3 rows and 19 cols */
#define PROCSCOL 0
#define GENSTATROW 7 /* uses 2 rows and 29 cols */
#define GENSTATCOL 21
-#define VMSTATROW 7 /* uses 17 rows and 12-14 cols */
+#define VMSTATROW 5 /* uses 17 rows and 12-14 cols */
#define VMSTATCOL 49 /* actually 50-51 for some fields */
#define GRAPHROW 10 /* uses 3 rows and 49-51 cols */
#define GRAPHCOL 0
@@ -203,16 +200,7 @@ initkre(void)
int i;
size_t sz;
- if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
- warnx("%s", devstat_errbuf);
- return(0);
- }
-
- cur.dinfo = calloc(1, sizeof(struct devinfo));
- last.dinfo = calloc(1, sizeof(struct devinfo));
- run.dinfo = calloc(1, sizeof(struct devinfo));
-
- if (dsinit(MAXDRIVES, &cur, &last, &run) != 1)
+ if (dsinit(MAXDRIVES) != 1)
return(0);
if (nintr == 0) {
@@ -313,7 +301,7 @@ labelkre(void)
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, MEMCOL, "Mem: REAL VIRTUAL");
mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share");
mvprintw(MEMROW + 2, MEMCOL, "Act");
mvprintw(MEMROW + 3, MEMCOL, "All");
@@ -365,27 +353,7 @@ labelkre(void)
mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache");
mvprintw(NAMEIROW + 1, NAMEICOL,
" Calls hits %% hits %%");
- mvprintw(DISKROW, DISKCOL, "Disks");
- mvprintw(DISKROW + 1, DISKCOL, "KB/t");
- mvprintw(DISKROW + 2, DISKCOL, "tps");
- mvprintw(DISKROW + 3, DISKCOL, "MB/s");
- mvprintw(DISKROW + 4, DISKCOL, "%%busy");
- /*
- * For now, we don't support a fourth disk statistic. So there's
- * no point in providing a label for it. If someone can think of a
- * fourth useful disk statistic, there is room to add it.
- */
- /* mvprintw(DISKROW + 4, DISKCOL, " msps"); */
- j = 0;
- for (i = 0; i < num_devices && j < MAXDRIVES; i++)
- if (dev_select[i].selected) {
- char tmpstr[80];
- sprintf(tmpstr, "%s%d", dev_select[i].device_name,
- dev_select[i].unit_number);
- mvprintw(DISKROW, DISKCOL + 5 + 6 * j,
- " %5.5s", tmpstr);
- j++;
- }
+ dslabel(MAXDRIVES, DISKCOL, DISKROW);
for (i = 0; i < nintr; i++) {
if (intrloc[i] == 0)
@@ -395,14 +363,14 @@ labelkre(void)
}
#define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
-#define Q(fld) {t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;}
+#define Q(fld) {t=cur_dev.fld[i]; cur_dev.fld[i]-=last_dev.fld[i]; if(state==TIME) last_dev.fld[i]=t;}
#define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
#define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
if(state == TIME) s1.nchstats.fld = t;}
#define PUTRATE(fld, l, c, w) \
do { \
Y(fld); \
- putint((int)((float)s.fld/etime + 0.5), l, c, w); \
+ sysputwuint64(wnd, l, c, w, (s.fld/etime + 0.5), 0); \
} while (0)
#define MAXFAIL 5
@@ -483,21 +451,20 @@ showkre(void)
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))
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);
- 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);
+ sysputpage(wnd, MEMROW + 2, MEMCOL + 4, 7, total.t_arm, 0);
+ sysputpage(wnd, MEMROW + 2, MEMCOL + 12, 7, total.t_armshr, 0);
+ sysputpage(wnd, MEMROW + 2, MEMCOL + 20, 8, total.t_avm, 0);
+ sysputpage(wnd, MEMROW + 2, MEMCOL + 29, 8, total.t_avmshr, 0);
+ sysputpage(wnd, MEMROW + 3, MEMCOL + 4, 7, total.t_rm, 0);
+ sysputpage(wnd, MEMROW + 3, MEMCOL + 12, 7, total.t_rmshr, 0);
+ sysputpage(wnd, MEMROW + 3, MEMCOL + 20, 8, total.t_vm, 0);
+ sysputpage(wnd, MEMROW + 3, MEMCOL + 29, 8, total.t_vmshr, 0);
+ sysputpage(wnd, MEMROW + 2, MEMCOL + 38, 7, total.t_free, 0);
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);
@@ -516,13 +483,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);
+ sysputpage(wnd, VMSTATROW + 12, VMSTATCOL + 2, 8 - 2, s.v_wire_count, 0);
+ sysputpage(wnd, VMSTATROW + 13, VMSTATCOL + 2, 8 - 2, s.v_active_count, 0);
+ sysputpage(wnd, VMSTATROW + 14, VMSTATCOL + 2, 8 - 2, s.v_inactive_count, 0);
+ sysputpage(wnd, VMSTATROW + 15, VMSTATCOL + 2, 8 - 2, s.v_laundry_count, 0);
+ sysputpage(wnd, VMSTATROW + 16, VMSTATCOL + 2, 8 - 2, s.v_free_count, 0);
if (LINES - 1 > VMSTATROW + 17)
- putint(s.bufspace / 1024, VMSTATROW + 17, VMSTATCOL, 8);
+ sysputuint64(wnd, VMSTATROW + 17, VMSTATCOL + 2, 8 - 2, s.bufspace, 0);
PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5);
PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5);
PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5);
@@ -537,20 +504,17 @@ showkre(void)
PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4);
PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4);
PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4);
- for (i = 0, lc = 0; i < num_devices && lc < MAXDRIVES; i++)
- if (dev_select[i].selected) {
- switch(state) {
- case TIME:
- dinfo(i, ++lc, &cur, &last);
- break;
- case RUN:
- dinfo(i, ++lc, &cur, &run);
- break;
- case BOOT:
- dinfo(i, ++lc, &cur, NULL);
- break;
- }
- }
+ switch(state) {
+ case TIME:
+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &last_dev);
+ break;
+ case RUN:
+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, &run_dev);
+ break;
+ case BOOT:
+ dsshow(MAXDRIVES, DISKCOL, DISKROW, &cur_dev, NULL);
+ break;
+ }
putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7);
putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7);
putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7);
@@ -576,14 +540,14 @@ cmdkre(const char *cmd, const char *args)
if (prefix(cmd, "run")) {
retval = 1;
copyinfo(&s2, &s1);
- switch (devstat_getdevs(NULL, &run)) {
+ switch (devstat_getdevs(NULL, &run_dev)) {
case -1:
errx(1, "%s", devstat_errbuf);
break;
case 1:
- num_devices = run.dinfo->numdevs;
- generation = run.dinfo->generation;
- retval = dscmd("refresh", NULL, MAXDRIVES, &cur);
+ num_devices = run_dev.dinfo->numdevs;
+ generation = run_dev.dinfo->generation;
+ retval = dscmd("refresh", NULL, MAXDRIVES, &cur_dev);
if (retval == 2)
labelkre();
break;
@@ -606,14 +570,14 @@ cmdkre(const char *cmd, const char *args)
retval = 1;
if (state == RUN) {
getinfo(&s1);
- switch (devstat_getdevs(NULL, &run)) {
+ switch (devstat_getdevs(NULL, &run_dev)) {
case -1:
errx(1, "%s", devstat_errbuf);
break;
case 1:
- num_devices = run.dinfo->numdevs;
- generation = run.dinfo->generation;
- retval = dscmd("refresh",NULL, MAXDRIVES, &cur);
+ num_devices = run_dev.dinfo->numdevs;
+ generation = run_dev.dinfo->generation;
+ retval = dscmd("refresh",NULL, MAXDRIVES, &cur_dev);
if (retval == 2)
labelkre();
break;
@@ -623,7 +587,7 @@ cmdkre(const char *cmd, const char *args)
}
return (retval);
}
- retval = dscmd(cmd, args, MAXDRIVES, &cur);
+ retval = dscmd(cmd, args, MAXDRIVES, &cur_dev);
if (retval == 2)
labelkre();
@@ -661,11 +625,26 @@ cputime(int indx)
return (s.time[indx] * 100.0 / lt);
}
-static void
+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
@@ -678,11 +657,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), "%*ju", 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('*');
@@ -691,7 +671,7 @@ putint(int n, int l, int lc, int w)
addstr(b);
}
-static void
+void
putfloat(double f, int l, int lc, int w, int d, int nz)
{
int snr;
@@ -723,7 +703,7 @@ putfloat(double f, int l, int lc, int w, int d, int nz)
addstr(b);
}
-static void
+void
putlongdouble(long double f, int l, int lc, int w, int d, int nz)
{
int snr;
@@ -763,7 +743,7 @@ getinfo(struct Info *ls)
int mib[2];
GETSYSCTL("kern.cp_time", ls->time);
- GETSYSCTL("kern.cp_time", cur.cp_time);
+ GETSYSCTL("kern.cp_time", cur_dev.cp_time);
GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch);
GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap);
GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall);
@@ -789,7 +769,6 @@ getinfo(struct Info *ls)
GETSYSCTL("vm.stats.vm.v_dfree", ls->v_dfree);
GETSYSCTL("vm.stats.vm.v_pfree", ls->v_pfree);
GETSYSCTL("vm.stats.vm.v_tfree", ls->v_tfree);
- GETSYSCTL("vm.stats.vm.v_page_size", ls->v_page_size);
GETSYSCTL("vm.stats.vm.v_free_count", ls->v_free_count);
GETSYSCTL("vm.stats.vm.v_wire_count", ls->v_wire_count);
GETSYSCTL("vm.stats.vm.v_active_count", ls->v_active_count);
@@ -816,23 +795,12 @@ getinfo(struct Info *ls)
size != sizeof(ncpu))
ncpu = 1;
- tmp_dinfo = last.dinfo;
- last.dinfo = cur.dinfo;
- cur.dinfo = tmp_dinfo;
+ tmp_dinfo = last_dev.dinfo;
+ last_dev.dinfo = cur_dev.dinfo;
+ cur_dev.dinfo = tmp_dinfo;
- last.snap_time = cur.snap_time;
- switch (devstat_getdevs(NULL, &cur)) {
- case -1:
- errx(1, "%s", devstat_errbuf);
- break;
- case 1:
- num_devices = cur.dinfo->numdevs;
- generation = cur.dinfo->generation;
- cmdkre("refresh", NULL);
- break;
- default:
- break;
- }
+ last_dev.snap_time = cur_dev.snap_time;
+ dsgetinfo(&cur_dev);
}
static void
@@ -859,38 +827,3 @@ copyinfo(struct Info *from, struct Info *to)
bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
}
-
-static void
-dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then)
-{
- long double transfers_per_second;
- long double kb_per_transfer, mb_per_second;
- long double elapsed_time, device_busy;
- int di;
-
- di = dev_select[dn].position;
-
- if (then != NULL) {
- /* Calculate relative to previous sample */
- elapsed_time = now->snap_time - then->snap_time;
- } else {
- /* Calculate relative to device creation */
- elapsed_time = now->snap_time - devstat_compute_etime(
- &now->dinfo->devices[di].creation_time, NULL);
- }
-
- if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
- &then->dinfo->devices[di] : NULL, elapsed_time,
- DSM_KB_PER_TRANSFER, &kb_per_transfer,
- DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
- DSM_MB_PER_SECOND, &mb_per_second,
- DSM_BUSY_PCT, &device_busy,
- DSM_NONE) != 0)
- errx(1, "%s", devstat_errbuf);
-
- lc = DISKCOL + lc * 6;
- putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0);
- putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0);
- putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0);
- putlongdouble(device_busy, DISKROW + 4, lc, 5, 0, 0);
-}