=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/systat/vmstat.c,v retrieving revision 1.29 retrieving revision 1.30 diff -c -r1.29 -r1.30 *** src/usr.bin/systat/vmstat.c 2001/11/23 22:20:06 1.29 --- src/usr.bin/systat/vmstat.c 2001/12/07 07:57:36 1.30 *************** *** 1,4 **** ! /* $OpenBSD: vmstat.c,v 1.29 2001/11/23 22:20:06 deraadt Exp $ */ /* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: vmstat.c,v 1.30 2001/12/07 07:57:36 pvalchev Exp $ */ /* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */ /*- *************** *** 38,44 **** #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; #endif ! static char rcsid[] = "$OpenBSD: vmstat.c,v 1.29 2001/11/23 22:20:06 deraadt Exp $"; #endif /* not lint */ /* --- 38,44 ---- #if 0 static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94"; #endif ! static char rcsid[] = "$OpenBSD: vmstat.c,v 1.30 2001/12/07 07:57:36 pvalchev Exp $"; #endif /* not lint */ /* *************** *** 88,93 **** --- 88,94 ---- #include "dkstats.h" extern struct _disk cur; + #define cnt s.Cnt #define oldcnt s1.Cnt #define total s.Total *************** *** 117,122 **** --- 118,124 ---- struct utmp utmp; + WINDOW * openkre() { *************** *** 141,156 **** static struct nlist namelist[] = { ! #define X_INTRNAMES 0 { "_intrnames" }, ! #define X_EINTRNAMES 1 { "_eintrnames" }, ! #define X_INTRCNT 2 { "_intrcnt" }, ! #define X_EINTRCNT 3 { "_eintrcnt" }, #if defined(__i386__) ! #define X_INTRHAND 4 { "_intrhand" }, #endif { "" }, --- 143,164 ---- static struct nlist namelist[] = { ! #define X_CPTIME 0 ! { "_cp_time" }, ! #define X_UVMEXP 1 ! { "_uvmexp" }, ! #define X_NCHSTATS 2 ! { "_nchstats" }, ! #define X_INTRNAMES 3 { "_intrnames" }, ! #define X_EINTRNAMES 4 { "_eintrnames" }, ! #define X_INTRCNT 5 { "_intrcnt" }, ! #define X_EINTRCNT 6 { "_eintrcnt" }, #if defined(__i386__) ! #define X_INTRHAND 7 { "_intrhand" }, #endif { "" }, *************** *** 193,198 **** --- 201,207 ---- { char *intrnamebuf, *cp; int i, ret; + static int once = 0; if (namelist[0].n_type == 0) { if ((ret = kvm_nlist(kd, namelist)) == -1) *************** *** 205,212 **** } } hertz = stathz ? stathz : hz; ! if (!dkinit(1)) return(0); if (nintr == 0) { #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; --- 214,230 ---- } } hertz = stathz ? stathz : hz; ! if (! dkinit(1)) return(0); + if (dk_ndrive && !once) { + #define allocate(e, t) \ + s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ + s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ + s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \ + z./**/e = (t *)calloc(dk_ndrive, sizeof (t)); + once = 1; + #undef allocate + } if (nintr == 0) { #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; *************** *** 232,238 **** while (ihp) { KREAD(ihp, &ih, sizeof(ih)); KREAD(ih.ih_what, iname, 16); ! /* XXX strcpy is safe, sized & malloc'd buffer */ strcpy(intrname[n++] = intrnamebuf + namelen, iname); namelen += 1 + strlen(iname); ihp = ih.ih_next; --- 250,256 ---- while (ihp) { KREAD(ihp, &ih, sizeof(ih)); KREAD(ih.ih_what, iname, 16); ! /* XXX strcpy is safe, sized & malloc'd buffer */ strcpy(intrname[n++] = intrnamebuf + namelen, iname); namelen += 1 + strlen(iname); ihp = ih.ih_next; *************** *** 240,250 **** } #else nintr = (namelist[X_EINTRCNT].n_value - ! namelist[X_INTRCNT].n_value) / sizeof (long); intrloc = calloc(nintr, sizeof (long)); intrname = calloc(nintr, sizeof (long)); intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value - ! namelist[X_INTRNAMES].n_value); if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) { error("Out of memory\n"); if (intrnamebuf) --- 258,268 ---- } #else nintr = (namelist[X_EINTRCNT].n_value - ! namelist[X_INTRCNT].n_value) / sizeof (long); intrloc = calloc(nintr, sizeof (long)); intrname = calloc(nintr, sizeof (long)); intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value - ! namelist[X_INTRNAMES].n_value); if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) { error("Out of memory\n"); if (intrnamebuf) *************** *** 257,263 **** return(0); } NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) - ! NVAL(X_INTRNAMES)); for (cp = intrnamebuf, i = 0; i < nintr; i++) { intrname[i] = cp; cp += strlen(cp) + 1; --- 275,281 ---- return(0); } NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) - ! NVAL(X_INTRNAMES)); for (cp = intrnamebuf, i = 0; i < nintr; i++) { intrname[i] = cp; cp += strlen(cp) + 1; *************** *** 326,340 **** mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); mvprintw(GRAPHROW, GRAPHCOL, ! " . %% Sys . %% User . %% Nice . %% Idle"); mvprintw(PROCSROW, PROCSCOL, "Proc:r d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, ! "| | | | | | | | | | |"); mvprintw(NAMEIROW, NAMEICOL, ! "Namei Sys-cache Proc-cache No-cache"); mvprintw(NAMEIROW + 1, NAMEICOL, ! " Calls hits %% hits %% miss %%"); mvprintw(DISKROW, DISKCOL, "Discs"); mvprintw(DISKROW + 1, DISKCOL, "seeks"); mvprintw(DISKROW + 2, DISKCOL, "xfers"); --- 344,358 ---- mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); mvprintw(GRAPHROW, GRAPHCOL, ! " . %% Sys . %% User . %% Nice . %% Idle"); mvprintw(PROCSROW, PROCSCOL, "Proc:r d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, ! "| | | | | | | | | | |"); mvprintw(NAMEIROW, NAMEICOL, ! "Namei Sys-cache Proc-cache No-cache"); mvprintw(NAMEIROW + 1, NAMEICOL, ! " Calls hits %% hits %% miss %%"); mvprintw(DISKROW, DISKCOL, "Discs"); mvprintw(DISKROW + 1, DISKCOL, "seeks"); mvprintw(DISKROW + 2, DISKCOL, "xfers"); *************** *** 344,350 **** for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++) if (dk_select[i]) { mvprintw(DISKROW, DISKCOL + 5 + 5 * j, ! " %4.4s", dr_name[j]); j++; } for (i = 0; i < nintr; i++) { --- 362,368 ---- for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++) if (dk_select[i]) { mvprintw(DISKROW, DISKCOL + 5 + 5 * j, ! " %4.4s", dr_name[j]); j++; } for (i = 0; i < nintr; i++) { *************** *** 374,379 **** --- 392,398 ---- int i, l, c; static int failcnt = 0; + if (state == TIME) dkswap(); etime = 0; *************** *** 405,411 **** continue; intrloc[i] = nextintsrow++; mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", ! intrname[i]); } X(intrcnt); l = (int)((float)s.intrcnt[i]/etime + 0.5); --- 424,430 ---- continue; intrloc[i] = nextintsrow++; mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", ! intrname[i]); } X(intrcnt); l = (int)((float)s.intrcnt[i]/etime + 0.5); *************** *** 423,429 **** psiz = 0; f2 = 0.0; ! /* * Last CPU state not calculated yet. */ for (c = 0; c < CPUSTATES - 1; c++) { --- 442,448 ---- psiz = 0; f2 = 0.0; ! /* * Last CPU state not calculated yet. */ for (c = 0; c < CPUSTATES - 1; c++) { *************** *** 435,441 **** putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0); else putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c, ! 5, 1, 0); move(GRAPHROW + 2, psiz); psiz += l; while (l-- > 0) --- 454,460 ---- putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0); else putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c, ! 5, 1, 0); move(GRAPHROW + 2, psiz); psiz += l; while (l-- > 0) *************** *** 457,463 **** putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); mvaddstr(STATROW, STATCOL + 53, buf); ! #define pgtokb(pg) ((pg) * s.uvmexp.pagesize / 1024) putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7); putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse), /* XXX */ --- 476,482 ---- putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); mvaddstr(STATROW, STATCOL + 53, buf); ! #define pgtokb(pg) ((pg) * s.uvmexp.pagesize / 1024) putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7); putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse), /* XXX */ *************** *** 509,529 **** for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++) if (dk_select[i]) { mvprintw(DISKROW, DISKCOL + 5 + 5 * c, ! " %4.4s", dr_name[i]); dinfo(i, ++c); } putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 10, 8); #define nz(x) ((x) ? (x) : 1) putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount), ! NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 24, 7); putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), ! NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); putint(nchtotal.ncs_miss - nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 38, 7); putfloat((nchtotal.ncs_miss - nchtotal.ncs_pass2) * ! 100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 45, 4, 0, 1); #undef nz } --- 528,548 ---- for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++) if (dk_select[i]) { mvprintw(DISKROW, DISKCOL + 5 + 5 * c, ! " %4.4s", dr_name[i]); dinfo(i, ++c); } putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9); putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 10, 8); #define nz(x) ((x) ? (x) : 1) putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount), ! NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1); putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 24, 7); putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount), ! NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1); putint(nchtotal.ncs_miss - nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 38, 7); putfloat((nchtotal.ncs_miss - nchtotal.ncs_pass2) * ! 100.0 / nz(s.nchcount), NAMEIROW + 2, NAMEICOL + 45, 4, 0, 1); #undef nz } *************** *** 633,649 **** struct Info *s; enum state st; { ! static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; ! static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS }; ! static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP }; ! static int vmtotal_mib[2] = { CTL_VM, VM_METER }; size_t size; #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; int i, n; #endif dkreadstats(); #if defined(__i386__) NREAD(X_INTRHAND, intrhand, sizeof(intrhand)); for (i = 0, n = 0; i < 16; i++) { --- 652,669 ---- struct Info *s; enum state st; { ! int mib[2]; size_t size; + extern int errno; #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; int i, n; #endif dkreadstats(); + NREAD(X_CPTIME, s->time, sizeof s->time); + NREAD(X_UVMEXP, &s->uvmexp, sizeof s->uvmexp); + NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats); #if defined(__i386__) NREAD(X_INTRHAND, intrhand, sizeof(intrhand)); for (i = 0, n = 0; i < 16; i++) { *************** *** 655,683 **** } } #else ! NREAD(X_INTRCNT, s->intrcnt, nintr * sizeof(long)); #endif - size = sizeof(s->time); - if (sysctl(cp_time_mib, 2, &s->time, &size, NULL, 0) < 0) { - error("Can't get KERN_CPTIME: %s\n", strerror(errno)); - bzero(&s->time, sizeof(s->time)); - } - - size = sizeof(s->nchstats); - if (sysctl(nchstats_mib, 2, &s->nchstats, &size, NULL, 0) < 0) { - error("Can't get KERN_NCHSTATS: %s\n", strerror(errno)); - bzero(&s->nchstats, sizeof(s->nchstats)); - } - - size = sizeof(s->uvmexp); - if (sysctl(uvmexp_mib, 2, &s->uvmexp, &size, NULL, 0) < 0) { - error("Can't get VM_UVMEXP: %s\n", strerror(errno)); - bzero(&s->uvmexp, sizeof(s->uvmexp)); - } - size = sizeof(s->Total); ! if (sysctl(vmtotal_mib, 2, &s->Total, &size, NULL, 0) < 0) { ! error("Can't get VM_METER: %s\n", strerror(errno)); bzero(&s->Total, sizeof(s->Total)); } } --- 675,687 ---- } } #else ! NREAD(X_INTRCNT, s->intrcnt, nintr * LONG); #endif size = sizeof(s->Total); ! mib[0] = CTL_VM; ! mib[1] = VM_METER; ! if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) { ! error("Can't get kernel info: %s\n", strerror(errno)); bzero(&s->Total, sizeof(s->Total)); } } *************** *** 713,719 **** /* time busy in disk activity */ atime = (double)cur.dk_time[dn].tv_sec + ! ((double)cur.dk_time[dn].tv_usec / (double)1000000); words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */ --- 717,723 ---- /* time busy in disk activity */ atime = (double)cur.dk_time[dn].tv_sec + ! ((double)cur.dk_time[dn].tv_usec / (double)1000000); words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */