X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/868d24aff239806e4f5ba78c9dbea2ddff57773a..7b5a2bb58f5a8a8d9dcf875f52bcd265af2f51dc:/usr.bin/systat/vmstat.c diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c index 90046d584e..87e1e5a845 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -32,18 +32,17 @@ * * @(#)vmstat.c 8.2 (Berkeley) 1/12/94 * $FreeBSD: src/usr.bin/systat/vmstat.c,v 1.38.2.4 2002/03/12 19:50:23 phantom Exp $ - * $DragonFly: src/usr.bin/systat/vmstat.c,v 1.10 2008/06/28 23:45:20 dillon Exp $ + * $DragonFly: src/usr.bin/systat/vmstat.c,v 1.12 2008/11/10 04:59:45 swildner Exp $ */ /* * Cursed vmstat -- from Robert Elz. */ -#define _KERNEL_STRUCTURES +#include #include #include #include -#include #include #include #include @@ -77,12 +76,13 @@ static struct Info { struct vmstats Vms; struct nchstats nchstats; long nchcount; + long nchpathcount; long *intrcnt; int bufspace; int desiredvnodes; - long numvnodes; - long freevnodes; - long dirtybufspace; + int numvnodes; + int freevnodes; + int dirtybufspace; } s, s1, s2, z; struct kinfo_cputime cp_time, old_cp_time; @@ -101,10 +101,11 @@ static enum state { BOOT, TIME, RUN } state = TIME; static void allocinfo(struct Info *); static void copyinfo(struct Info *, struct Info *); static void dinfo(int, int, struct statinfo *, struct statinfo *); -static void getinfo(struct Info *, enum state); -static void putint(int, int, int, int); +static void getinfo(struct Info *); +static void putlong(long, 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 putlongdoublez(long double, int, int, int, int, int); static int ucount(void); static int ncpu; @@ -145,18 +146,18 @@ closekre(WINDOW *w) static struct nlist namelist[] = { #define X_BUFFERSPACE 0 - { "_bufspace" }, + { .n_name = "_bufspace" }, #define X_NCHSTATS 1 - { "_nchstats" }, + { .n_name = "_nchstats" }, #define X_DESIREDVNODES 2 - { "_desiredvnodes" }, + { .n_name = "_desiredvnodes" }, #define X_NUMVNODES 3 - { "_numvnodes" }, + { .n_name = "_numvnodes" }, #define X_FREEVNODES 4 - { "_freevnodes" }, + { .n_name = "_freevnodes" }, #define X_NUMDIRTYBUFFERS 5 - { "_dirtybufspace" }, - { "" }, + { .n_name = "_dirtybufspace" }, + { .n_name = "" }, }; /* @@ -173,14 +174,14 @@ static struct nlist namelist[] = { #define PROCSROW 7 /* uses 2 rows and 20 cols */ #define PROCSCOL 0 #define GENSTATROW 7 /* uses 2 rows and 30 cols */ -#define GENSTATCOL 20 +#define GENSTATCOL 16 #define VMSTATROW 6 /* uses 17 rows and 12 cols */ #define VMSTATCOL 48 #define GRAPHROW 10 /* uses 3 rows and 51 cols */ #define GRAPHCOL 0 #define NAMEIROW 14 /* uses 3 rows and 38 cols */ #define NAMEICOL 0 -#define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */ +#define DISKROW 17 /* uses 6 rows and 50 cols (for 9 drives) */ #define DISKCOL 0 #define DRIVESPACE 7 /* max # for space */ @@ -224,22 +225,22 @@ initkre(void) if (nintr == 0) { if (sysctlbyname("hw.intrnames", NULL, &bytes, NULL, 0) == 0) { intrnamebuf = malloc(bytes); - sysctlbyname("hw.intrnames", intrnamebuf, &bytes, + sysctlbyname("hw.intrnames", intrnamebuf, &bytes, NULL, 0); for (i = 0; i < bytes; ++i) { - if (intrnamebuf[i] == 0) - ++nintr; + if (intrnamebuf[i] == 0) + ++nintr; } intrname = malloc(nintr * sizeof(char *)); intrloc = malloc(nintr * sizeof(*intrloc)); nintr = 0; for (b = i = 0; i < bytes; ++i) { - if (intrnamebuf[i] == 0) { - intrname[nintr] = intrnamebuf + b; - intrloc[nintr] = 0; - b = i + 1; - ++nintr; - } + if (intrnamebuf[i] == 0) { + intrname[nintr] = intrnamebuf + b; + intrloc[nintr] = 0; + b = i + 1; + ++nintr; + } } } nextintsrow = INTSROW + 2; @@ -248,7 +249,7 @@ initkre(void) allocinfo(&s2); allocinfo(&z); } - getinfo(&s2, RUN); + getinfo(&s2); copyinfo(&s2, &s1); return(1); } @@ -267,17 +268,17 @@ fetchkre(void) tp = localtime(&now); (void) strftime(buf, sizeof(buf), d_first ? "%e %b %R" : "%b %e %R", tp); - getinfo(&s, state); + getinfo(&s); } void labelkre(void) { - register int i, j; + int i, j; clear(); mvprintw(STATROW, STATCOL + 4, "users Load"); - mvprintw(MEMROW, MEMCOL, "Mem:KB REAL VIRTUAL"); + mvprintw(MEMROW, MEMCOL, "Mem:MB REAL VIRTUAL"); mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share"); mvprintw(MEMROW + 2, MEMCOL, "Act"); mvprintw(MEMROW + 3, MEMCOL, "All"); @@ -311,28 +312,27 @@ labelkre(void) mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "numvnodes"); mvprintw(VMSTATROW + 17, VMSTATCOL + 10, "freevnodes"); - mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); + mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); mvprintw(GRAPHROW, GRAPHCOL, " . %%Sys . %%Intr . %%User . %%Nice . %%Idle"); - mvprintw(PROCSROW, PROCSCOL, "Proc:r p d s w"); + mvprintw(PROCSROW, PROCSCOL, " r p d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, "| | | | | | | | | | |"); - mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache"); - mvprintw(NAMEIROW + 1, NAMEICOL, - " Calls hits %% hits %%"); + mvprintw(NAMEIROW, NAMEICOL, "Path-lookups hits %% Components"); 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"); + mvprintw(DISKROW + 2, DISKCOL, "tpr/s"); + mvprintw(DISKROW + 3, DISKCOL, "MBr/s"); + mvprintw(DISKROW + 4, DISKCOL, "tpw/s"); + mvprintw(DISKROW + 5, DISKCOL, "MBw/s"); + mvprintw(DISKROW + 6, 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) { @@ -349,7 +349,7 @@ labelkre(void) * room for extended VM stats */ mvprintw(VMSTATROW + 11, VMSTATCOL - 6, "zfod"); - mvprintw(VMSTATROW + 12, VMSTATCOL - 6, "ofod"); + mvprintw(VMSTATROW + 12, VMSTATCOL - 6, "ozfod"); mvprintw(VMSTATROW + 13, VMSTATCOL - 6, "%%slo-z"); mvprintw(VMSTATROW + 14, VMSTATCOL - 6, "tfree"); extended_vm_stats = 1; @@ -366,15 +366,15 @@ labelkre(void) } #define CP_UPDATE(fld) do { \ - uint64_t t; \ - t=s.fld; \ + uint64_t lt; \ + lt=s.fld; \ s.fld-=s1.fld; \ if(state==TIME) \ - s1.fld=t; \ - t=fld; \ + s1.fld=lt; \ + lt=fld; \ fld-=old_##fld; \ if(state==TIME) \ - old_##fld=t; \ + old_##fld=lt; \ etime += s.fld; \ } while(0) #define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;} @@ -383,7 +383,7 @@ labelkre(void) if(state == TIME) s1.nchstats.fld = t;} #define PUTRATE(fld, l, c, w) \ Y(fld); \ - putint((int)((float)s.fld/etime + 0.5), l, c, w) + putlong((long)((float)s.fld/etime + 0.5), l, c, w, 'D') #define MAXFAIL 5 #define CPUSTATES 5 @@ -401,8 +401,10 @@ void showkre(void) { float f1, f2; - int psiz, inttotal; - int i, l, c; + int psiz; + int i, lc; + long inttotal; + long l; static int failcnt = 0; double total_time; @@ -447,64 +449,68 @@ showkre(void) intrname[i]); } X(intrcnt); - l = (int)((float)s.intrcnt[i]/etime + 0.5); + l = (long)((float)s.intrcnt[i]/etime + 0.5); inttotal += l; - putint(l, intrloc[i], INTSCOL + 2, 6); + putlong(l, intrloc[i], INTSCOL + 2, 6, 'D'); } - putint(inttotal, INTSROW + 1, INTSCOL + 2, 6); + putlong(inttotal, INTSROW + 1, INTSCOL + 2, 6, 'D'); Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss); - Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes); Z(ncs_neghits); + Z(ncs_longhits); Z(ncs_longmiss); Z(ncs_neghits); s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits + - nchtotal.ncs_miss + nchtotal.ncs_long + nchtotal.ncs_neghits; - if (state == TIME) + nchtotal.ncs_miss + nchtotal.ncs_neghits; + s.nchpathcount = nchtotal.ncs_longhits + nchtotal.ncs_longmiss; + if (state == TIME) { s1.nchcount = s.nchcount; + s1.nchpathcount = s.nchpathcount; + } psiz = 0; f2 = 0.0; - for (c = 0; c < CPUSTATES; c++) { + for (lc = 0; lc < CPUSTATES; lc++) { uint64_t val = *(uint64_t *)(((uint8_t *)&s.cp_time) + - cpuoffsets[c]); + cpuoffsets[lc]); f1 = 100.0 * val / total_time; f2 += f1; l = (int) ((f2 + 1.0) / 2.0) - psiz; if (f1 > 99.9) f1 = 99.9; /* no room to display 100.0 */ - putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c, 4, 1, 0); + putfloat(f1, GRAPHROW, GRAPHCOL + 10 * lc, 4, 1, 0); move(GRAPHROW + 2, psiz); psiz += l; while (l-- > 0) - addch(cpuchar[c]); + addch(cpuchar[lc]); } - putint(ucount(), STATROW, STATCOL, 3); - putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0); - putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); - putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); + putlong(ucount(), STATROW, STATCOL, 3, 'D'); + putfloat(avenrun[0], STATROW, STATCOL + 18, 6, 2, 0); + putfloat(avenrun[1], STATROW, STATCOL + 25, 6, 2, 0); + putfloat(avenrun[2], STATROW, STATCOL + 32, 6, 2, 0); mvaddstr(STATROW, STATCOL + 53, buf); -#define pgtokb(pg) ((pg) * vms.v_page_size / 1024) - putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 8); - putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 11, 8); - putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 19, 9); - putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 28, 9); - putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 8); - putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 11, 8); - putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 19, 9); - putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 28, 9); - putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 37, 8); - putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3); - putint(total.t_pw, PROCSROW + 1, PROCSCOL + 6, 3); - putint(total.t_dw, PROCSROW + 1, PROCSCOL + 9, 3); - putint(total.t_sl, PROCSROW + 1, PROCSCOL + 12, 3); - putint(total.t_sw, PROCSROW + 1, PROCSCOL + 15, 3); +#define pgtokb(pg) (long)((intmax_t)(pg) * vms.v_page_size / 1024) +#define pgtomb(pg) (long)((intmax_t)(pg) * vms.v_page_size / (1024 * 1024)) + putlong(pgtomb(total.t_arm), MEMROW + 2, MEMCOL + 3, 8, 'M'); + putlong(pgtomb(total.t_armshr), MEMROW + 2, MEMCOL + 11, 8, 'M'); + putlong(pgtomb(total.t_avm), MEMROW + 2, MEMCOL + 19, 9, 'M'); + putlong(pgtomb(total.t_avmshr), MEMROW + 2, MEMCOL + 28, 9, 'M'); + putlong(pgtomb(total.t_rm), MEMROW + 3, MEMCOL + 3, 8, 'M'); + putlong(pgtomb(total.t_rmshr), MEMROW + 3, MEMCOL + 11, 8, 'M'); + putlong(pgtomb(total.t_vm), MEMROW + 3, MEMCOL + 19, 9, 'M'); + putlong(pgtomb(total.t_vmshr), MEMROW + 3, MEMCOL + 28, 9, 'M'); + putlong(pgtomb(total.t_free), MEMROW + 2, MEMCOL + 37, 8, 'M'); + putlong(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 0, 3, 'D'); + putlong(total.t_pw, PROCSROW + 1, PROCSCOL + 3, 3, 'D'); + putlong(total.t_dw, PROCSROW + 1, PROCSCOL + 6, 3, 'D'); + putlong(total.t_sl, PROCSROW + 1, PROCSCOL + 9, 3, 'D'); + putlong(total.t_sw, PROCSROW + 1, PROCSCOL + 12, 3, 'D'); if (extended_vm_stats == 0) { PUTRATE(Vmm.v_zfod, VMSTATROW + 0, VMSTATCOL + 4, 5); } PUTRATE(Vmm.v_cow_faults, VMSTATROW + 1, VMSTATCOL + 3, 6); - putint(pgtokb(vms.v_wire_count), VMSTATROW + 2, VMSTATCOL, 9); - putint(pgtokb(vms.v_active_count), VMSTATROW + 3, VMSTATCOL, 9); - putint(pgtokb(vms.v_inactive_count), VMSTATROW + 4, VMSTATCOL, 9); - putint(pgtokb(vms.v_cache_count), VMSTATROW + 5, VMSTATCOL, 9); - putint(pgtokb(vms.v_free_count), VMSTATROW + 6, VMSTATCOL, 9); + putlong(pgtokb(vms.v_wire_count), VMSTATROW + 2, VMSTATCOL, 9, 'K'); + putlong(pgtokb(vms.v_active_count), VMSTATROW + 3, VMSTATCOL, 9, 'K'); + putlong(pgtokb(vms.v_inactive_count), VMSTATROW + 4, VMSTATCOL, 9, 'K'); + putlong(pgtokb(vms.v_cache_count), VMSTATROW + 5, VMSTATCOL, 9, 'K'); + putlong(pgtokb(vms.v_free_count), VMSTATROW + 6, VMSTATCOL, 9, 'K'); PUTRATE(Vmm.v_dfree, VMSTATROW + 7, VMSTATCOL, 9); PUTRATE(Vmm.v_pfree, VMSTATROW + 8, VMSTATCOL, 9); PUTRATE(Vmm.v_reactivated, VMSTATROW + 9, VMSTATCOL, 9); @@ -513,25 +519,20 @@ showkre(void) PUTRATE(Vmm.v_intrans, VMSTATROW + 12, VMSTATCOL, 9); if (extended_vm_stats) { - PUTRATE(Vmm.v_zfod, VMSTATROW + 11, VMSTATCOL - 16, 9); - PUTRATE(Vmm.v_ozfod, VMSTATROW + 12, VMSTATCOL - 16, 9); - putint( - ((s.Vmm.v_ozfod < s.Vmm.v_zfod) ? - s.Vmm.v_ozfod * 100 / s.Vmm.v_zfod : - 0 - ), - VMSTATROW + 13, - VMSTATCOL - 16, - 9 - ); - PUTRATE(Vmm.v_tfree, VMSTATROW + 14, VMSTATCOL - 16, 9); + PUTRATE(Vmm.v_zfod, VMSTATROW + 11, VMSTATCOL - 16, 9); + PUTRATE(Vmm.v_ozfod, VMSTATROW + 12, VMSTATCOL - 16, 9); +#define nz(x) ((x) ? (x) : 1) + putlong((s.Vmm.v_zfod - s.Vmm.v_ozfod) * 100 / nz(s.Vmm.v_zfod), + VMSTATROW + 13, VMSTATCOL - 16, 9, 'D'); +#undef nz + PUTRATE(Vmm.v_tfree, VMSTATROW + 14, VMSTATCOL - 16, 9); } - putint(s.bufspace/1024, VMSTATROW + 13, VMSTATCOL, 9); - putint(s.dirtybufspace/1024, VMSTATROW + 14, VMSTATCOL, 9); - putint(s.desiredvnodes, VMSTATROW + 15, VMSTATCOL, 9); - putint(s.numvnodes, VMSTATROW + 16, VMSTATCOL, 9); - putint(s.freevnodes, VMSTATROW + 17, VMSTATCOL, 9); + putlong(s.bufspace/1024, VMSTATROW + 13, VMSTATCOL, 9, 'K'); + putlong(s.dirtybufspace/1024, VMSTATROW + 14, VMSTATCOL, 9, 'K'); + putlong(s.desiredvnodes, VMSTATROW + 15, VMSTATCOL, 9, 'D'); + putlong(s.numvnodes, VMSTATROW + 16, VMSTATCOL, 9, 'D'); + putlong(s.freevnodes, VMSTATROW + 17, VMSTATCOL, 9, 'D'); PUTRATE(Vmm.v_vnodein, PAGEROW + 2, PAGECOL + 5, 5); PUTRATE(Vmm.v_vnodeout, PAGEROW + 2, PAGECOL + 10, 5); PUTRATE(Vmm.v_swapin, PAGEROW + 2, PAGECOL + 17, 5); @@ -541,46 +542,45 @@ showkre(void) PUTRATE(Vmm.v_swappgsin, PAGEROW + 3, PAGECOL + 17, 5); PUTRATE(Vmm.v_swappgsout, PAGEROW + 3, PAGECOL + 22, 5); PUTRATE(Vmm.v_swtch, GENSTATROW + 1, GENSTATCOL, 5); - PUTRATE(Vmm.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5); - PUTRATE(Vmm.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5); - PUTRATE(Vmm.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5); - PUTRATE(Vmm.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5); - PUTRATE(Vmm.v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 5); + PUTRATE(Vmm.v_trap, GENSTATROW + 1, GENSTATCOL + 6, 5); + PUTRATE(Vmm.v_syscall, GENSTATROW + 1, GENSTATCOL + 12, 5); + PUTRATE(Vmm.v_intr, GENSTATROW + 1, GENSTATCOL + 18, 5); + PUTRATE(Vmm.v_soft, GENSTATROW + 1, GENSTATCOL + 23, 5); + PUTRATE(Vmm.v_vm_faults, GENSTATROW + 1, GENSTATCOL + 29, 5); mvprintw(DISKROW, DISKCOL + 5, " "); - for (i = 0, c = 0; i < num_devices && c < MAXDRIVES; i++) + for (i = 0, lc = 0; i < num_devices && lc < 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 * c, + mvprintw(DISKROW, DISKCOL + 5 + 6 * lc, " %5.5s", tmpstr); switch(state) { case TIME: - dinfo(i, ++c, &cur, &last); + dinfo(i, ++lc, &cur, &last); break; case RUN: - dinfo(i, ++c, &cur, &run); + dinfo(i, ++lc, &cur, &run); break; case BOOT: - dinfo(i, ++c, &cur, NULL); + dinfo(i, ++lc, &cur, NULL); break; } } - putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); - putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits), - NAMEIROW + 2, NAMEICOL + 9, 9); #define nz(x) ((x) ? (x) : 1) - putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) * - 100.0 / nz(s.nchcount), - NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); - putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9); - putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), - NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); + putlong(s.nchpathcount, NAMEIROW + 1, NAMEICOL + 3, 9, 'D'); + + putlong(nchtotal.ncs_longhits, NAMEIROW + 1, NAMEICOL + 12, 7, 'D'); + putfloat(nchtotal.ncs_longhits * 100.0 / nz(s.nchpathcount), + NAMEIROW + 1, NAMEICOL + 19, 4, 0, 0); + + putfloat((double)s.nchcount / nz(s.nchpathcount), + NAMEIROW + 1, NAMEICOL + 27, 5, 2, 1); #undef nz } int -cmdkre(char *cmd, char *args) +cmdkre(const char *cmd, char *args) { int retval; @@ -616,7 +616,7 @@ cmdkre(char *cmd, char *args) if (prefix(cmd, "zero")) { retval = 1; if (state == RUN) { - getinfo(&s1, RUN); + getinfo(&s1); switch (getdevs(&run)) { case -1: errx(1, "%s", devstat_errbuf); @@ -646,7 +646,7 @@ cmdkre(char *cmd, char *args) static int ucount(void) { - register int nusers = 0; + int nusers = 0; if (ut < 0) return (0); @@ -659,40 +659,61 @@ ucount(void) } static void -putint(int n, int l, int c, int w) +putlong(long n, int l, int lc, int w, int type) { char b[128]; + int xtype; - move(l, c); + move(l, lc); if (n == 0) { while (w-- > 0) addch(' '); return; } - snprintf(b, sizeof(b), "%*d", w, n); - if (strlen(b) > w) { - while (w-- > 0) - addch('*'); - return; + snprintf(b, sizeof(b), "%*ld", w, n); + if (strlen(b) > (size_t)w) { + if (type == 'D') { + n /= 1000; + xtype = 'K'; + } else { + n /= 1024; + xtype = 'M'; + } + snprintf(b, sizeof(b), "%*ld%c", w - 1, n, xtype); + if (strlen(b) > (size_t)w) { + if (type == 'D') { + n /= 1000; + xtype = 'M'; + } else { + n /= 1024; + xtype = 'G'; + } + snprintf(b, sizeof(b), "%*ld%c", w - 1, n, xtype); + if (strlen(b) > (size_t)w) { + while (w-- > 0) + addch('*'); + return; + } + } } addstr(b); } static void -putfloat(double f, int l, int c, int w, int d, int nz) +putfloat(double f, int l, int lc, int w, int d, int nz) { char b[128]; - move(l, c); + move(l, lc); if (nz && f == 0.0) { while (--w >= 0) addch(' '); return; } snprintf(b, sizeof(b), "%*.*f", w, d, f); - if (strlen(b) > w) + if (strlen(b) > (size_t)w) snprintf(b, sizeof(b), "%*.0f", w, f); - if (strlen(b) > w) { + if (strlen(b) > (size_t)w) { while (--w >= 0) addch('*'); return; @@ -701,20 +722,20 @@ putfloat(double f, int l, int c, int w, int d, int nz) } static void -putlongdouble(long double f, int l, int c, int w, int d, int nz) +putlongdouble(long double f, int l, int lc, int w, int d, int nz) { char b[128]; - move(l, c); + move(l, lc); if (nz && f == 0.0) { while (--w >= 0) addch(' '); return; } sprintf(b, "%*.*Lf", w, d, f); - if (strlen(b) > w) + if (strlen(b) > (size_t)w) sprintf(b, "%*.0Lf", w, f); - if (strlen(b) > w) { + if (strlen(b) > (size_t)w) { while (--w >= 0) addch('*'); return; @@ -723,44 +744,58 @@ putlongdouble(long double f, int l, int c, int w, int d, int nz) } static void -getinfo(struct Info *s, enum state st) +putlongdoublez(long double f, int l, int lc, int w, int d, int nz) +{ + char b[128]; + + if (f == 0.0) { + move(l, lc); + sprintf(b, "%*.*s", w, w, ""); + addstr(b); + } else { + putlongdouble(f, l, lc, w, d, nz); + } +} + +static void +getinfo(struct Info *ls) { struct devinfo *tmp_dinfo; struct nchstats *nch_tmp; size_t size; - int vms_size = sizeof(s->Vms); - int vmm_size = sizeof(s->Vmm); - size_t nch_size = sizeof(s->nchstats) * SMP_MAXCPU; + size_t vms_size = sizeof(ls->Vms); + size_t vmm_size = sizeof(ls->Vmm); + size_t nch_size = sizeof(ls->nchstats) * SMP_MAXCPU; - if (sysctlbyname("vm.vmstats", &s->Vms, &vms_size, NULL, 0)) { + if (sysctlbyname("vm.vmstats", &ls->Vms, &vms_size, NULL, 0)) { perror("sysctlbyname: vm.vmstats"); exit(1); } - if (sysctlbyname("vm.vmmeter", &s->Vmm, &vmm_size, NULL, 0)) { + if (sysctlbyname("vm.vmmeter", &ls->Vmm, &vmm_size, NULL, 0)) { perror("sysctlbyname: vm.vmstats"); exit(1); } - if (kinfo_get_sched_cputime(&s->cp_time)) + if (kinfo_get_sched_cputime(&ls->cp_time)) err(1, "kinfo_get_sched_cputime"); if (kinfo_get_sched_cputime(&cp_time)) err(1, "kinfo_get_sched_cputime"); - NREAD(X_BUFFERSPACE, &s->bufspace, sizeof(s->bufspace)); - NREAD(X_DESIREDVNODES, &s->desiredvnodes, sizeof(s->desiredvnodes)); - NREAD(X_NUMVNODES, &s->numvnodes, LONG); - NREAD(X_FREEVNODES, &s->freevnodes, LONG); - NREAD(X_NUMDIRTYBUFFERS, &s->dirtybufspace, sizeof(s->dirtybufspace)); + NREAD(X_BUFFERSPACE, &ls->bufspace, sizeof(ls->bufspace)); + NREAD(X_DESIREDVNODES, &ls->desiredvnodes, sizeof(ls->desiredvnodes)); + NREAD(X_NUMVNODES, &ls->numvnodes, sizeof(ls->numvnodes)); + NREAD(X_FREEVNODES, &ls->freevnodes, sizeof(ls->freevnodes)); + NREAD(X_NUMDIRTYBUFFERS, &ls->dirtybufspace, sizeof(ls->dirtybufspace)); if (nintr) { - size = nintr * sizeof(s->intrcnt[0]); - sysctlbyname("hw.intrcnt", s->intrcnt, &size, NULL, 0); + size = nintr * sizeof(ls->intrcnt[0]); + sysctlbyname("hw.intrcnt", ls->intrcnt, &size, NULL, 0); } - size = sizeof(s->Total); - if (sysctlbyname("vm.vmtotal", &s->Total, &size, NULL, 0) < 0) { + size = sizeof(ls->Total); + if (sysctlbyname("vm.vmtotal", &ls->Total, &size, NULL, 0) < 0) { error("Can't get kernel info: %s\n", strerror(errno)); - bzero(&s->Total, sizeof(s->Total)); + bzero(&ls->Total, sizeof(ls->Total)); } - + if ((nch_tmp = malloc(nch_size)) == NULL) { perror("malloc"); exit(1); @@ -779,7 +814,7 @@ getinfo(struct Info *s, enum state st) if (kinfo_get_cpus(&ncpu)) err(1, "kinfo_get_cpus"); - kvm_nch_cpuagg(nch_tmp, &s->nchstats, ncpu); + kvm_nch_cpuagg(nch_tmp, &ls->nchstats, ncpu); free(nch_tmp); tmp_dinfo = last.dinfo; @@ -802,15 +837,15 @@ getinfo(struct Info *s, enum state st) } static void -allocinfo(struct Info *s) +allocinfo(struct Info *ls) { - s->intrcnt = (long *) calloc(nintr, sizeof(long)); - if (s->intrcnt == NULL) + ls->intrcnt = (long *) calloc(nintr, sizeof(long)); + if (ls->intrcnt == NULL) errx(2, "out of memory"); } static void -copyinfo(register struct Info *from, register struct Info *to) +copyinfo(struct Info *from, struct Info *to) { long *intrcnt; @@ -826,10 +861,13 @@ copyinfo(register struct Info *from, register struct Info *to) } static void -dinfo(int dn, int c, struct statinfo *now, struct statinfo *then) +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 kb_per_transfer; + long double transfers_per_secondr; + long double transfers_per_secondw; + long double mb_per_secondr; + long double mb_per_secondw; long double elapsed_time, device_busy; int di; @@ -843,26 +881,58 @@ dinfo(int dn, int c, struct statinfo *now, struct statinfo *then) then->dinfo->devices[di].busy_time : now->dinfo->devices[di].dev_creation_time); - if (compute_stats(&now->dinfo->devices[di], then ? - &then->dinfo->devices[di] : NULL, elapsed_time, + if (compute_stats( + &now->dinfo->devices[di], + (then ? &then->dinfo->devices[di] : NULL), + elapsed_time, NULL, NULL, NULL, - &kb_per_transfer, &transfers_per_second, - &mb_per_second, NULL, NULL) != 0) + &kb_per_transfer, + NULL, + NULL, + NULL, NULL) != 0) errx(1, "%s", devstat_errbuf); - if ((device_busy == 0) && (transfers_per_second > 5)) + if (compute_stats_read( + &now->dinfo->devices[di], + (then ? &then->dinfo->devices[di] : NULL), + elapsed_time, + NULL, NULL, NULL, + NULL, + &transfers_per_secondr, + &mb_per_secondr, + NULL, NULL) != 0) + errx(1, "%s", devstat_errbuf); + + if (compute_stats_write( + &now->dinfo->devices[di], + (then ? &then->dinfo->devices[di] : NULL), + elapsed_time, + NULL, NULL, NULL, + NULL, + &transfers_per_secondw, + &mb_per_secondw, + NULL, NULL) != 0) + errx(1, "%s", devstat_errbuf); + + if ((device_busy == 0) && + (transfers_per_secondr > 5 || transfers_per_secondw > 5)) { /* the device has been 100% busy, fake it because * as long as the device is 100% busy the busy_time * field in the devstat struct is not updated */ device_busy = elapsed_time; - if (device_busy > elapsed_time) + } + if (device_busy > elapsed_time) { /* this normally happens after one or more periods * where the device has been 100% busy, correct it */ device_busy = elapsed_time; + } - c = DISKCOL + c * 6; - putlongdouble(kb_per_transfer, DISKROW + 1, c, 5, 2, 0); - putlongdouble(transfers_per_second, DISKROW + 2, c, 5, 0, 0); - putlongdouble(mb_per_second, DISKROW + 3, c, 5, 2, 0); - putlongdouble(device_busy * 100 / elapsed_time, DISKROW + 4, c, 5, 0, 0); + lc = DISKCOL + lc * 6; + putlongdoublez(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0); + putlongdoublez(transfers_per_secondr, DISKROW + 2, lc, 5, 0, 0); + putlongdoublez(mb_per_secondr, DISKROW + 3, lc, 5, 2, 0); + putlongdoublez(transfers_per_secondw, DISKROW + 4, lc, 5, 0, 0); + putlongdoublez(mb_per_secondw, DISKROW + 5, lc, 5, 2, 0); + putlongdouble(device_busy * 100 / elapsed_time, + DISKROW + 6, lc, 5, 0, 0); }