BSD 4_4 release
[unix-history] / usr / src / usr.bin / systat / vmstat.c
index 8092977..1e1f197 100644 (file)
-/*
- * Copyright (c) 1983, 1989 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1983, 1989, 1992, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)vmstat.c   5.12 (Berkeley) 6/24/90";
-#endif not lint
+static char sccsid[] = "@(#)vmstat.c   8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 /*
  * Cursed vmstat -- from Robert Elz.
  */
 
 
 /*
  * Cursed vmstat -- from Robert Elz.
  */
 
-#include "systat.h"
-
-#include <ctype.h>
-#include <utmp.h>
-
-#include <sys/vm.h>
+#include <sys/param.h>
+#include <sys/dkstat.h>
 #include <sys/buf.h>
 #include <sys/stat.h>
 #include <sys/buf.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <sys/user.h>
 #include <sys/proc.h>
 #include <sys/namei.h>
 #include <sys/user.h>
 #include <sys/proc.h>
 #include <sys/namei.h>
+#include <sys/sysctl.h>
+#include <vm/vm.h>
 
 
-#include <machine/pte.h>
+#include <signal.h>
+#include <nlist.h>
+#include <ctype.h>
+#include <utmp.h>
 #include <paths.h>
 #include <paths.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "systat.h"
+#include "extern.h"
+
+static struct Info {
+       long    time[CPUSTATES];
+       struct  vmmeter Cnt;
+       struct  vmtotal Total;
+       long    *dk_time;
+       long    *dk_wds;
+       long    *dk_seek;
+       long    *dk_xfer;
+       int     dk_busy;
+       struct  nchstats nchstats;
+       long    nchcount;
+       long    *intrcnt;
+} s, s1, s2, z;
+
+#define        cnt s.Cnt
+#define oldcnt s1.Cnt
+#define        total s.Total
+#define        nchtotal s.nchstats
+#define        oldnchtotal s1.nchstats
+
+static enum state { BOOT, TIME, RUN } state = TIME;
+
+static void allocinfo __P((struct Info *));
+static void copyinfo __P((struct Info *, struct Info *));
+static float cputime __P((int));
+static void dinfo __P((int, int));
+static void getinfo __P((struct Info *, enum state));
+static void putint __P((int, int, int, int));
+static void putfloat __P((double, int, int, int, int, int));
+static int ucount __P((void));
 
 static int ut;
 
 static int ut;
+static char buf[26];
+static time_t t;
+static double etime;
+static float hertz;
+static int nintr;
+static long *intrloc;
+static char **intrname;
+static int nextintsrow;
+
+struct utmp utmp;
+
 
 WINDOW *
 openkre()
 
 WINDOW *
 openkre()
@@ -39,6 +115,7 @@ openkre()
        return (stdscr);
 }
 
        return (stdscr);
 }
 
+void
 closekre(w)
        WINDOW *w;
 {
 closekre(w)
        WINDOW *w;
 {
@@ -50,87 +127,37 @@ closekre(w)
        wrefresh(w);
 }
 
        wrefresh(w);
 }
 
-long   time();
-float  cputime();
-struct utmp utmp;
 
 
-static struct nlist name[] = {
-       { "_cp_time" },
+static struct nlist namelist[] = {
 #define X_CPTIME       0
 #define X_CPTIME       0
-       { "_rate" },
-#define X_RATE         1
-       { "_total" },
+       { "_cp_time" },
+#define X_CNT          1
+       { "_cnt" },
 #define X_TOTAL                2
 #define X_TOTAL                2
-       { "_proc" },
-#define X_PROC         3
-       { "_nproc" },
-#define X_NPROC                4
-       { "_sum" },
-#define X_SUM          5
+       { "_total" },
+#define        X_DK_BUSY       3
        { "_dk_busy" },
        { "_dk_busy" },
-#define        X_DK_BUSY       6
+#define        X_DK_TIME       4
        { "_dk_time" },
        { "_dk_time" },
-#define        X_DK_TIME       7
+#define        X_DK_XFER       5
        { "_dk_xfer" },
        { "_dk_xfer" },
-#define        X_DK_XFER       8
+#define        X_DK_WDS        6
        { "_dk_wds" },
        { "_dk_wds" },
-#define        X_DK_WDS        9
-       { "_tk_nin" },
-#define        X_TK_NIN        10
-       { "_tk_nout" },
-#define        X_TK_NOUT       11
+#define        X_DK_SEEK       7
        { "_dk_seek" },
        { "_dk_seek" },
-#define        X_DK_SEEK       12
+#define        X_NCHSTATS      8
        { "_nchstats" },
        { "_nchstats" },
-#define        X_NCHSTATS      13
+#define        X_INTRNAMES     9
        { "_intrnames" },
        { "_intrnames" },
-#define        X_INTRNAMES     14
+#define        X_EINTRNAMES    10
        { "_eintrnames" },
        { "_eintrnames" },
-#define        X_EINTRNAMES    15
+#define        X_INTRCNT       11
        { "_intrcnt" },
        { "_intrcnt" },
-#define        X_INTRCNT       16
+#define        X_EINTRCNT      12
        { "_eintrcnt" },
        { "_eintrcnt" },
-#define        X_EINTRCNT      17
        { "" },
 };
 
        { "" },
 };
 
-static struct Info {
-       long    time[CPUSTATES];
-       struct  vmmeter Rate;
-       struct  vmtotal Total;
-       struct  vmmeter Sum;
-       struct  forkstat Forkstat;
-       long    *dk_time;
-       long    *dk_wds;
-       long    *dk_seek;
-       long    *dk_xfer;
-       int     dk_busy;
-       long    tk_nin;
-       long    tk_nout;
-       struct  nchstats nchstats;
-       long    nchcount;
-       long    *intrcnt;
-} s, s1, s2, z;
-
-#define total s.Total
-#define sum s.Sum
-#define sumold s1.Sum
-#define rate s.Rate
-#define        nchtotal s.nchstats
-#define        oldnchtotal s1.nchstats
-#define oldrate s1.Rate
-
-static char buf[26];
-static time_t t;
-static double etime;
-static float hertz;
-static int nintr;
-static long *intrloc;
-static char **intrname;
-static int nextintsrow;
-
-static enum state { BOOT, TIME, RUN } state = TIME;
-
 /*
  * These constants define where the major pieces are laid out
  */
 /*
  * These constants define where the major pieces are laid out
  */
@@ -144,16 +171,14 @@ static    enum state { BOOT, TIME, RUN } state = TIME;
 #define INTSCOL                63
 #define PROCSROW        7      /* uses 2 rows and 20 cols */
 #define PROCSCOL        0
 #define INTSCOL                63
 #define PROCSROW        7      /* uses 2 rows and 20 cols */
 #define PROCSCOL        0
-#define VMSTATROW       7      /* uses 2 rows and 26 cols */
-#define VMSTATCOL      25
-#define FILLSTATROW     7      /* uses 6 rows and 10 cols */
-#define FILLSTATCOL    53
+#define GENSTATROW      7      /* uses 2 rows and 30 cols */
+#define GENSTATCOL     20
+#define VMSTATROW       7      /* uses 16 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 GRAPHROW       10      /* uses 3 rows and 51 cols */
 #define GRAPHCOL        0
 #define NAMEIROW       14      /* uses 3 rows and 38 cols */
 #define NAMEICOL        0
-#define GENSTATROW     14      /* uses 9 rows and 11 cols */
-#define GENSTATCOL     52
 #define DISKROW                18      /* uses 5 rows and 50 cols (for 9 drives) */
 #define DISKCOL                 0
 
 #define DISKROW                18      /* uses 5 rows and 50 cols (for 9 drives) */
 #define DISKCOL                 0
 
@@ -165,20 +190,24 @@ static    enum state { BOOT, TIME, RUN } state = TIME;
 #define        MAXDRIVES       DK_NDRIVE        /* max # to display */
 #endif
 
 #define        MAXDRIVES       DK_NDRIVE        /* max # to display */
 #endif
 
+int
 initkre()
 {
        char *intrnamebuf, *cp;
        int i;
        static int once = 0;
 
 initkre()
 {
        char *intrnamebuf, *cp;
        int i;
        static int once = 0;
 
-       if (name[0].n_type == 0) {
-               nlist(_PATH_UNIX,name);
-               if (name[0].n_type == 0) {
+       if (namelist[0].n_type == 0) {
+               if (kvm_nlist(kd, namelist)) {
+                       nlisterr(namelist);
+                       return(0);
+               }
+               if (namelist[0].n_type == 0) {
                        error("No namelist");
                        return(0);
                }
        }
                        error("No namelist");
                        return(0);
                }
        }
-       hertz = phz ? phz : hz;
+       hertz = stathz ? stathz : hz;
        if (! dkinit())
                return(0);
        if (dk_ndrive && !once) {
        if (! dkinit())
                return(0);
        if (dk_ndrive && !once) {
@@ -195,12 +224,12 @@ initkre()
 #undef allocate
        }
        if (nintr == 0) {
 #undef allocate
        }
        if (nintr == 0) {
-               nintr = (name[X_EINTRCNT].n_value -
-                       name[X_INTRCNT].n_value) / sizeof (long);
-               intrloc = (long *) calloc(nintr, sizeof (long));
-               intrname = (char **) calloc(nintr, sizeof (long));
-               intrnamebuf = malloc(name[X_EINTRNAMES].n_value -
-                       name[X_INTRNAMES].n_value);
+               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)
                if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
                        error("Out of memory\n");
                        if (intrnamebuf)
@@ -212,9 +241,8 @@ initkre()
                        nintr = 0;
                        return(0);
                }
                        nintr = 0;
                        return(0);
                }
-               lseek(kmem, (long)name[X_INTRNAMES].n_value, L_SET);
-               read(kmem, intrnamebuf, name[X_EINTRNAMES].n_value -
-                       name[X_INTRNAMES].n_value);
+               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;
                for (cp = intrnamebuf, i = 0; i < nintr; i++) {
                        intrname[i] = cp;
                        cp += strlen(cp) + 1;
@@ -230,6 +258,7 @@ initkre()
        return(1);
 }
 
        return(1);
 }
 
+void
 fetchkre()
 {
        time_t now;
 fetchkre()
 {
        time_t now;
@@ -240,18 +269,19 @@ fetchkre()
        getinfo(&s, state);
 }
 
        getinfo(&s, state);
 }
 
+void
 labelkre()
 {
 labelkre()
 {
-       register i, j;
+       register int i, j;
 
        clear();
        mvprintw(STATROW, STATCOL + 4, "users    Load");
 
        clear();
        mvprintw(STATROW, STATCOL + 4, "users    Load");
-       mvprintw(MEMROW, MEMCOL, "Mem     REAL     VIRTUAL");
-       mvprintw(MEMROW + 1, MEMCOL, "      Tot Text   Tot Text");
+       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 + 2, MEMCOL, "Act");
        mvprintw(MEMROW + 3, MEMCOL, "All");
 
-       mvprintw(MEMROW + 1, MEMCOL + 28, "Free");
+       mvprintw(MEMROW + 1, MEMCOL + 31, "Free");
 
        mvprintw(PAGEROW, PAGECOL,     "        PAGING   SWAPPING ");
        mvprintw(PAGEROW + 1, PAGECOL, "        in  out   in  out ");
 
        mvprintw(PAGEROW, PAGECOL,     "        PAGING   SWAPPING ");
        mvprintw(PAGEROW + 1, PAGECOL, "        in  out   in  out ");
@@ -261,28 +291,32 @@ labelkre()
        mvprintw(INTSROW, INTSCOL + 3, " Interrupts");
        mvprintw(INTSROW + 1, INTSCOL + 9, "total");
 
        mvprintw(INTSROW, INTSCOL + 3, " Interrupts");
        mvprintw(INTSROW + 1, INTSCOL + 9, "total");
 
-       mvprintw(GENSTATROW, GENSTATCOL + 8, "Csw");
-       mvprintw(GENSTATROW + 1, GENSTATCOL + 8, "Trp");
-       mvprintw(GENSTATROW + 2, GENSTATCOL + 8, "Sys");
-       mvprintw(GENSTATROW + 3, GENSTATCOL + 8, "Int");
-       mvprintw(GENSTATROW + 4, GENSTATCOL + 8, "Pdm");
-       mvprintw(GENSTATROW + 5, GENSTATCOL + 8, "Sof");
-       mvprintw(GENSTATROW + 6, GENSTATCOL + 8, "Flt");
-       mvprintw(GENSTATROW + 7, GENSTATCOL + 8, "Scn");
-       mvprintw(GENSTATROW + 8, GENSTATCOL + 8, "Rev");
-
-       mvprintw(VMSTATROW, VMSTATCOL, "Rec It F/S F/F RFL Fre SFr");
-
-       mvprintw(FILLSTATROW, FILLSTATCOL + 7, " zf");
-       mvprintw(FILLSTATROW + 1, FILLSTATCOL + 7, "nzf");
-       mvprintw(FILLSTATROW + 2, FILLSTATCOL + 7, "%%zf");
-       mvprintw(FILLSTATROW + 3, FILLSTATCOL + 7, " xf");
-       mvprintw(FILLSTATROW + 4, FILLSTATCOL + 7, "nxf");
-       mvprintw(FILLSTATROW + 5, FILLSTATCOL + 7, "%%xf");
+       mvprintw(VMSTATROW, VMSTATCOL + 10, "vmflt");
+       mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "cow");
+       mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "objlk");
+       mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "objht");
+       mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "zfod");
+       mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "nzfod");
+       mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "%%zfod");
+       mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "kern");
+       mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "wire");
+       mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "act");
+       mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "inact");
+       mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "free");
+       mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "daefr");
+       mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "prcfr");
+       mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "react");
+       mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "scan");
+       if (LINES - 1 > VMSTATROW + 16)
+               mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "hdrev");
+       if (LINES - 1 > VMSTATROW + 17)
+               mvprintw(VMSTATROW + 17, VMSTATCOL + 10, "intrn");
+
+       mvprintw(GENSTATROW, GENSTATCOL, "  Csw  Trp  Sys  Int  Sof  Flt");
 
        mvprintw(GRAPHROW, GRAPHCOL,
                "    . %% Sys    . %% User    . %% Nice    . %% Idle");
 
        mvprintw(GRAPHROW, GRAPHCOL,
                "    . %% Sys    . %% User    . %% Nice    . %% Idle");
-       mvprintw(PROCSROW, PROCSCOL, "Procs  r  p  d  s  w");
+       mvprintw(PROCSROW, PROCSCOL, "Proc:r  p  d  s  w");
        mvprintw(GRAPHROW + 1, GRAPHCOL,
                "|    |    |    |    |    |    |    |    |    |    |");
 
        mvprintw(GRAPHROW + 1, GRAPHCOL,
                "|    |    |    |    |    |    |    |    |    |    |");
 
@@ -312,11 +346,15 @@ labelkre()
 #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 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) \
+       Y(fld); \
+       putint((int)((float)s.fld/etime + 0.5), l, c, w)
 #define MAXFAIL 5
 
 static char cpuchar[CPUSTATES] = { '=' , '>', '-', ' ' };
 static char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_IDLE };
 
 #define MAXFAIL 5
 
 static char cpuchar[CPUSTATES] = { '=' , '>', '-', ' ' };
 static char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_IDLE };
 
+void
 showkre()
 {
        float f1, f2;
 showkre()
 {
        float f1, f2;
@@ -327,7 +365,6 @@ showkre()
        for (i = 0; i < dk_ndrive; i++) {
                X(dk_xfer); X(dk_seek); X(dk_wds); X(dk_time);
        }
        for (i = 0; i < dk_ndrive; i++) {
                X(dk_xfer); X(dk_seek); X(dk_wds); X(dk_time);
        }
-       Y(tk_nin); Y(tk_nout);
        etime = 0;
        for(i = 0; i < CPUSTATES; i++) {
                X(time);
        etime = 0;
        for(i = 0; i < CPUSTATES; i++) {
                X(time);
@@ -374,7 +411,11 @@ showkre()
 
        psiz = 0;
        f2 = 0.0;
 
        psiz = 0;
        f2 = 0.0;
-       for (c = 0; c < CPUSTATES; c++) {
+
+       /* 
+        * Last CPU state not calculated yet.
+        */
+       for (c = 0; c < CPUSTATES - 1; c++) {
                i = cpuorder[c];
                f1 = cputime(i);
                f2 += f1;
                i = cpuorder[c];
                f1 = cputime(i);
                f2 += f1;
@@ -395,110 +436,57 @@ showkre()
        putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
        putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
        mvaddstr(STATROW, STATCOL + 53, buf);
        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) * NBPG / 1024)
-       putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 5);
-       putint(pgtokb(total.t_armtxt), MEMROW + 2, MEMCOL + 9, 5);
-       putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 14, 6);
-       putint(pgtokb(total.t_avmtxt), MEMROW + 2, MEMCOL + 20, 5);
-       putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 5);
-       putint(pgtokb(total.t_rmtxt), MEMROW + 3, MEMCOL + 9, 5);
-       putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 14, 6);
-       putint(pgtokb(total.t_vmtxt), MEMROW + 3, MEMCOL + 20, 5);
-       putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 27, 5);
-       putint(total.t_rq, PROCSROW + 1, PROCSCOL + 5, 3);
-       putint(total.t_pw, PROCSROW + 1, PROCSCOL + 8, 3);
-       putint(total.t_dw, PROCSROW + 1, PROCSCOL + 11, 3);
-       putint(total.t_sl, PROCSROW + 1, PROCSCOL + 14, 3);
-       putint(total.t_sw, PROCSROW + 1, PROCSCOL + 17, 3);
-       putrate(rate.v_swtch, oldrate.v_swtch, 
-               GENSTATROW, GENSTATCOL, 7);
-       putrate(rate.v_trap, oldrate.v_trap, 
-               GENSTATROW + 1, GENSTATCOL, 7);
-       putrate(rate.v_syscall, oldrate.v_syscall, 
-               GENSTATROW + 2, GENSTATCOL, 7);
-       putrate(rate.v_intr, oldrate.v_intr, 
-               GENSTATROW + 3, GENSTATCOL, 7);
-       putrate(rate.v_pdma, oldrate.v_pdma, 
-               GENSTATROW + 4, GENSTATCOL, 7);
-       putrate(rate.v_soft, oldrate.v_soft, 
-               GENSTATROW + 5, GENSTATCOL, 7);
-       putrate(rate.v_faults, oldrate.v_faults, 
-               GENSTATROW + 6, GENSTATCOL, 7);
-       putrate(rate.v_scan, oldrate.v_scan, 
-               GENSTATROW + 7, GENSTATCOL, 7);
-       putrate(rate.v_rev, oldrate.v_rev, 
-               GENSTATROW + 8, GENSTATCOL, 7);
-       putrate(rate.v_pgin, oldrate.v_pgin, PAGEROW + 2,
-               PAGECOL + 5, 5);
-       putrate(rate.v_pgout, oldrate.v_pgout, PAGEROW + 2,
-               PAGECOL + 10, 5);
-       putrate(rate.v_swpin, oldrate.v_swpin, PAGEROW + 2,
-               PAGECOL + 15, 5);
-       putrate(rate.v_swpout, oldrate.v_swpout, PAGEROW + 2,
-               PAGECOL + 20, 5);
-       putrate(rate.v_pgpgin, oldrate.v_pgpgin, PAGEROW + 3,
-               PAGECOL + 5, 5);
-       putrate(rate.v_pgpgout, oldrate.v_pgpgout, PAGEROW + 3,
-               PAGECOL + 10, 5);
-       putrate(rate.v_pswpin, oldrate.v_pswpin, PAGEROW + 3,
-               PAGECOL + 15, 5);
-       putrate(rate.v_pswpout, oldrate.v_pswpout, PAGEROW + 3,
-               PAGECOL + 20, 5);
-
-       putrate(rate.v_pgrec, oldrate.v_pgrec, VMSTATROW + 1, VMSTATCOL, 3);
-       putrate(rate.v_intrans, oldrate.v_intrans, VMSTATROW + 1,
-               VMSTATCOL + 4, 2);
-       putrate(rate.v_xsfrec, oldrate.v_xsfrec, VMSTATROW + 1,
-               VMSTATCOL + 7, 3);
-       putrate(rate.v_xifrec, oldrate.v_xifrec, VMSTATROW + 1,
-               VMSTATCOL + 11, 3);
-       putrate(rate.v_pgfrec, oldrate.v_pgfrec, VMSTATROW + 1,
-               VMSTATCOL + 15, 3);
-       putrate(rate.v_dfree, oldrate.v_dfree, VMSTATROW + 1,
-               VMSTATCOL + 19, 3);
-       putrate(rate.v_seqfree, oldrate.v_seqfree, VMSTATROW + 1,
-               VMSTATCOL + 23, 3);
-
-       putrate(rate.v_zfod, oldrate.v_zfod, FILLSTATROW, FILLSTATCOL, 6);
-       putrate(rate.v_nzfod, oldrate.v_nzfod, FILLSTATROW + 1, FILLSTATCOL, 6);
-       putrate(rate.v_exfod, oldrate.v_exfod, FILLSTATROW + 3,
-               FILLSTATCOL, 6);
-       putrate(rate.v_nexfod, oldrate.v_nexfod, FILLSTATROW + 4,
-               FILLSTATCOL, 6);
-       putfloat (
-               rate.v_nzfod == 0 ?
-                       0.0
-               : state != RUN ?
-                       ( 100.0 * rate.v_zfod / rate.v_nzfod )
-               : rate.v_nzfod == oldrate.v_nzfod ?
-                       0.0
-               :
-                       ( 100.0 * (rate.v_zfod-oldrate.v_zfod)
-                       / (rate.v_nzfod-oldrate.v_nzfod) )
-               , FILLSTATROW + 2
-               , FILLSTATCOL
-               , 6
-               , 2
-               , 1
-       );
-       putfloat (
-               rate.v_nexfod == 0 ?
-                       0.0
-               : state != RUN ?
-                       ( 100.0 * rate.v_exfod / rate.v_nexfod )
-               : rate.v_nexfod == oldrate.v_nexfod ?
-                       0.0
-               :
-                       ( 100.0 * (rate.v_exfod-oldrate.v_exfod)
-                       / (rate.v_nexfod-oldrate.v_nexfod) )
-               , FILLSTATROW + 5
-               , FILLSTATCOL
-               , 6
-               , 2
-               , 1
-       );
-
-       mvprintw(DISKROW,DISKCOL+5,"                              ");
+#define pgtokb(pg)     ((pg) * cnt.v_page_size / 1024)
+       putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 6);
+       putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 9, 6);
+       putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 15, 7);
+       putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 22, 7);
+       putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 6);
+       putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 9, 6);
+       putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 15, 7);
+       putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 22, 7);
+       putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 29, 6);
+       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);
+       PUTRATE(Cnt.v_vm_faults, VMSTATROW, VMSTATCOL + 3, 6);
+       PUTRATE(Cnt.v_cow_faults, VMSTATROW + 1, VMSTATCOL + 3, 6);
+       PUTRATE(Cnt.v_lookups, VMSTATROW + 2, VMSTATCOL + 3, 6);
+       PUTRATE(Cnt.v_hits, VMSTATROW + 3, VMSTATCOL + 3, 6);
+       PUTRATE(Cnt.v_zfod, VMSTATROW + 4, VMSTATCOL + 4, 5);
+       PUTRATE(Cnt.v_nzfod, VMSTATROW + 5, VMSTATCOL + 3, 6);
+       putfloat(cnt.v_nzfod == 0 ? 0.0 : (100.0 * cnt.v_zfod / cnt.v_nzfod),
+                VMSTATROW + 6, VMSTATCOL + 2, 7, 2, 1);
+       putint(pgtokb(cnt.v_kernel_pages), VMSTATROW + 7, VMSTATCOL, 9);
+       putint(pgtokb(cnt.v_wire_count), VMSTATROW + 8, VMSTATCOL, 9);
+       putint(pgtokb(cnt.v_active_count), VMSTATROW + 9, VMSTATCOL, 9);
+       putint(pgtokb(cnt.v_inactive_count), VMSTATROW + 10, VMSTATCOL, 9);
+       putint(pgtokb(cnt.v_free_count), VMSTATROW + 11, VMSTATCOL, 9);
+       PUTRATE(Cnt.v_dfree, VMSTATROW + 12, VMSTATCOL, 9);
+       PUTRATE(Cnt.v_pfree, VMSTATROW + 13, VMSTATCOL, 9);
+       PUTRATE(Cnt.v_reactivated, VMSTATROW + 14, VMSTATCOL, 9);
+       PUTRATE(Cnt.v_scan, VMSTATROW + 15, VMSTATCOL, 9);
+       if (LINES - 1 > VMSTATROW + 16)
+               PUTRATE(Cnt.v_rev, VMSTATROW + 16, VMSTATCOL, 9);
+       if (LINES - 1 > VMSTATROW + 17)
+               PUTRATE(Cnt.v_intrans, VMSTATROW + 17, VMSTATCOL, 9);
+       PUTRATE(Cnt.v_pageins, PAGEROW + 2, PAGECOL + 5, 5);
+       PUTRATE(Cnt.v_pageouts, PAGEROW + 2, PAGECOL + 10, 5);
+       PUTRATE(Cnt.v_swpin, PAGEROW + 2, PAGECOL + 15, 5);     /* - */
+       PUTRATE(Cnt.v_swpout, PAGEROW + 2, PAGECOL + 20, 5);    /* - */
+       PUTRATE(Cnt.v_pgpgin, PAGEROW + 3, PAGECOL + 5, 5);     /* ? */
+       PUTRATE(Cnt.v_pgpgout, PAGEROW + 3, PAGECOL + 10, 5);   /* ? */
+       PUTRATE(Cnt.v_pswpin, PAGEROW + 3, PAGECOL + 15, 5);    /* - */
+       PUTRATE(Cnt.v_pswpout, PAGEROW + 3, PAGECOL + 20, 5);   /* - */
+       PUTRATE(Cnt.v_swtch, GENSTATROW + 1, GENSTATCOL, 5);
+       PUTRATE(Cnt.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5);
+       PUTRATE(Cnt.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5);
+       PUTRATE(Cnt.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5);
+       PUTRATE(Cnt.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5);
+/*     PUTRATE(Cnt.v_faults, GENSTATROW + 1, GENSTATCOL + 25, 5);*/
+       mvprintw(DISKROW, DISKCOL + 5, "                              ");
        for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++)
                if (dk_select[i]) {
                        mvprintw(DISKROW, DISKCOL + 5 + 5 * c,
        for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++)
                if (dk_select[i]) {
                        mvprintw(DISKROW, DISKCOL + 5 + 5 * c,
@@ -516,6 +504,7 @@ showkre()
 #undef nz
 }
 
 #undef nz
 }
 
+int
 cmdkre(cmd, args)
        char *cmd, *args;
 {
 cmdkre(cmd, args)
        char *cmd, *args;
 {
@@ -543,7 +532,7 @@ cmdkre(cmd, args)
 }
 
 /* calculate number of users on the system */
 }
 
 /* calculate number of users on the system */
-static
+static int
 ucount()
 {
        register int nusers = 0;
 ucount()
 {
        register int nusers = 0;
@@ -563,7 +552,7 @@ cputime(indx)
        int indx;
 {
        double t;
        int indx;
 {
        double t;
-       register i;
+       register int i;
 
        t = 0;
        for (i = 0; i < CPUSTATES; i++)
 
        t = 0;
        for (i = 0; i < CPUSTATES; i++)
@@ -573,20 +562,9 @@ cputime(indx)
        return (s.time[indx] * 100.0 / t);
 }
 
        return (s.time[indx] * 100.0 / t);
 }
 
-static
-putrate(r, or, l, c, w)
-{
-
-       if (state != TIME) {
-               if (state == RUN)
-                       r -= or;
-               putint((int)((float)r/etime + 0.5), l, c, w);
-       } else
-               putint(r, l, c, w);
-}
-
-static
+static void
 putint(n, l, c, w)
 putint(n, l, c, w)
+       int n, l, c, w;
 {
        char b[128];
 
 {
        char b[128];
 
@@ -605,62 +583,55 @@ putint(n, l, c, w)
        addstr(b);
 }
 
        addstr(b);
 }
 
-static
+static void
 putfloat(f, l, c, w, d, nz)
 putfloat(f, l, c, w, d, nz)
-       float f;
+       double f;
+       int l, c, w, d, nz;
 {
        char b[128];
 
        move(l, c);
        if (nz && f == 0.0) {
 {
        char b[128];
 
        move(l, c);
        if (nz && f == 0.0) {
-               while (w-- > 0)
+               while (--w >= 0)
                        addch(' ');
                return;
        }
        sprintf(b, "%*.*f", w, d, f);
        if (strlen(b) > w) {
                        addch(' ');
                return;
        }
        sprintf(b, "%*.*f", w, d, f);
        if (strlen(b) > w) {
-               while (w-- > 0)
+               while (--w >= 0)
                        addch('*');
                return;
        }
        addstr(b);
 }
 
                        addch('*');
                return;
        }
        addstr(b);
 }
 
-static
+static void
 getinfo(s, st)
        struct Info *s;
        enum state st;
 {
 getinfo(s, st)
        struct Info *s;
        enum state st;
 {
-
-       lseek(kmem, (long)name[X_CPTIME].n_value,L_SET);
-       read(kmem, s->time, sizeof s->time);
-       if (st != TIME) {
-               lseek(kmem, (long)name[X_SUM].n_value, L_SET);
-               read(kmem, &s->Rate, sizeof s->Rate);
-       } else {
-               lseek(kmem, (long)name[X_RATE].n_value,L_SET);
-               read(kmem, &s->Rate, sizeof s->Rate);
+       int mib[2], size;
+       extern int errno;
+
+       NREAD(X_CPTIME, s->time, sizeof s->time);
+       NREAD(X_CNT, &s->Cnt, sizeof s->Cnt);
+       NREAD(X_DK_BUSY, &s->dk_busy, LONG);
+       NREAD(X_DK_TIME, s->dk_time, dk_ndrive * LONG);
+       NREAD(X_DK_XFER, s->dk_xfer, dk_ndrive * LONG);
+       NREAD(X_DK_WDS, s->dk_wds, dk_ndrive * LONG);
+       NREAD(X_DK_SEEK, s->dk_seek, dk_ndrive * LONG);
+       NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
+       NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
+       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));
        }
        }
-       lseek(kmem, (long)name[X_TOTAL].n_value, L_SET);
-       read(kmem, &s->Total, sizeof s->Total);
-       s->dk_busy = getw(name[X_DK_BUSY].n_value);
-       lseek(kmem, (long)name[X_DK_TIME].n_value,  L_SET);
-       read(kmem, s->dk_time, dk_ndrive * sizeof (long));
-       lseek(kmem, (long)name[X_DK_XFER].n_value,  L_SET);
-       read(kmem, s->dk_xfer, dk_ndrive * sizeof (long));
-       lseek(kmem, (long)name[X_DK_WDS].n_value,  L_SET);
-       read(kmem, s->dk_wds, dk_ndrive * sizeof (long));
-       lseek(kmem, (long)name[X_DK_SEEK].n_value,  L_SET);
-       read(kmem, s->dk_seek, dk_ndrive * sizeof (long));
-       s->tk_nin = getw(name[X_TK_NIN].n_value);
-       s->tk_nout = getw(name[X_TK_NOUT].n_value);
-       lseek(kmem, (long)name[X_NCHSTATS].n_value,  L_SET);
-       read(kmem, &s->nchstats, sizeof s->nchstats);
-       lseek(kmem, (long)name[X_INTRCNT].n_value,  L_SET);
-       read(kmem, s->intrcnt, nintr * sizeof (long));
 }
 
 }
 
-static
+static void
 allocinfo(s)
        struct Info *s;
 {
 allocinfo(s)
        struct Info *s;
 {
@@ -672,13 +643,18 @@ allocinfo(s)
        }
 }
 
        }
 }
 
-static
+static void
 copyinfo(from, to)
        register struct Info *from, *to;
 {
        long *time, *wds, *seek, *xfer;
        long *intrcnt;
 
 copyinfo(from, to)
        register struct Info *from, *to;
 {
        long *time, *wds, *seek, *xfer;
        long *intrcnt;
 
+       /*
+        * time, wds, seek, and xfer are malloc'd so we have to
+        * save the pointers before the structure copy and then 
+        * copy by hand.
+        */
        time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek;
        xfer = to->dk_xfer; intrcnt = to->intrcnt;
        *to = *from;
        time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek;
        xfer = to->dk_xfer; intrcnt = to->intrcnt;
        *to = *from;
@@ -689,8 +665,9 @@ copyinfo(from, to)
        bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
 }
 
        bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
 }
 
-static
+static void
 dinfo(dn, c)
 dinfo(dn, c)
+       int dn, c;
 {
        double words, atime, itime, xtime;
 
 {
        double words, atime, itime, xtime;