=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/systat/vmstat.c,v retrieving revision 1.30 retrieving revision 1.31 diff -c -r1.30 -r1.31 *** src/usr.bin/systat/vmstat.c 2001/12/07 07:57:36 1.30 --- src/usr.bin/systat/vmstat.c 2001/12/07 09:18:08 1.31 *************** *** 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 $ */ /*- --- 1,4 ---- ! /* $OpenBSD: vmstat.c,v 1.31 2001/12/07 09:18:08 deraadt 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.30 2001/12/07 07:57:36 pvalchev 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.31 2001/12/07 09:18:08 deraadt Exp $"; #endif /* not lint */ /* *************** *** 88,94 **** #include "dkstats.h" extern struct _disk cur; - #define cnt s.Cnt #define oldcnt s1.Cnt #define total s.Total --- 88,93 ---- *************** *** 118,124 **** struct utmp utmp; - WINDOW * openkre() { --- 117,122 ---- *************** *** 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 { "" }, --- 141,158 ---- static struct nlist namelist[] = { ! #define X_HZ 0 ! { "_hz" }, ! #define X_INTRNAMES 1 { "_intrnames" }, ! #define X_EINTRNAMES 2 { "_eintrnames" }, ! #define X_INTRCNT 3 { "_intrcnt" }, ! #define X_EINTRCNT 4 { "_eintrcnt" }, #if defined(__i386__) ! #define X_INTRHAND 5 { "_intrhand" }, #endif { "" }, *************** *** 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) --- 195,200 ---- *************** *** 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; --- 207,214 ---- } } hertz = stathz ? stathz : hz; ! if (!dkinit(1)) return(0); if (nintr == 0) { #if defined(__i386__) struct intrhand *intrhand[16], *ihp, ih; *************** *** 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; --- 234,240 ---- 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; *************** *** 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) --- 242,252 ---- } #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) *************** *** 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; --- 259,265 ---- 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; *************** *** 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"); --- 328,342 ---- 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"); *************** *** 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++) { --- 346,352 ---- 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++) { *************** *** 392,398 **** int i, l, c; static int failcnt = 0; - if (state == TIME) dkswap(); etime = 0; --- 376,381 ---- *************** *** 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); --- 407,413 ---- continue; intrloc[i] = nextintsrow++; mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", ! intrname[i]); } X(intrcnt); l = (int)((float)s.intrcnt[i]/etime + 0.5); *************** *** 442,448 **** psiz = 0; f2 = 0.0; ! /* * Last CPU state not calculated yet. */ for (c = 0; c < CPUSTATES - 1; c++) { --- 425,431 ---- psiz = 0; f2 = 0.0; ! /* * Last CPU state not calculated yet. */ for (c = 0; c < CPUSTATES - 1; c++) { *************** *** 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) --- 437,443 ---- 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) *************** *** 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 */ --- 459,465 ---- 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 */ *************** *** 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 } --- 511,531 ---- 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 } *************** *** 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++) { --- 635,651 ---- 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++) { *************** *** 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)); } } --- 657,685 ---- } } #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)); } } *************** *** 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 */ --- 715,721 ---- /* 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 */