Home | History | Annotate | Line # | Download | only in systat
vmstat.c revision 1.17
      1  1.17  drochner /*	$NetBSD: vmstat.c,v 1.17 1998/12/19 14:34:40 drochner Exp $	*/
      2   1.2       jtc 
      3   1.1       jtc /*-
      4   1.1       jtc  * Copyright (c) 1983, 1989, 1992, 1993
      5   1.1       jtc  *	The Regents of the University of California.  All rights reserved.
      6   1.1       jtc  *
      7   1.1       jtc  * Redistribution and use in source and binary forms, with or without
      8   1.1       jtc  * modification, are permitted provided that the following conditions
      9   1.1       jtc  * are met:
     10   1.1       jtc  * 1. Redistributions of source code must retain the above copyright
     11   1.1       jtc  *    notice, this list of conditions and the following disclaimer.
     12   1.1       jtc  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       jtc  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       jtc  *    documentation and/or other materials provided with the distribution.
     15   1.1       jtc  * 3. All advertising materials mentioning features or use of this software
     16   1.1       jtc  *    must display the following acknowledgement:
     17   1.1       jtc  *	This product includes software developed by the University of
     18   1.1       jtc  *	California, Berkeley and its contributors.
     19   1.1       jtc  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       jtc  *    may be used to endorse or promote products derived from this software
     21   1.1       jtc  *    without specific prior written permission.
     22   1.1       jtc  *
     23   1.1       jtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       jtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       jtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       jtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       jtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       jtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       jtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       jtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       jtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       jtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       jtc  * SUCH DAMAGE.
     34   1.1       jtc  */
     35   1.1       jtc 
     36   1.8       mrg #include <sys/cdefs.h>
     37   1.1       jtc #ifndef lint
     38   1.2       jtc #if 0
     39   1.1       jtc static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 1/12/94";
     40   1.2       jtc #endif
     41  1.17  drochner __RCSID("$NetBSD: vmstat.c,v 1.17 1998/12/19 14:34:40 drochner Exp $");
     42   1.1       jtc #endif /* not lint */
     43   1.1       jtc 
     44   1.1       jtc /*
     45   1.1       jtc  * Cursed vmstat -- from Robert Elz.
     46   1.1       jtc  */
     47   1.1       jtc 
     48   1.1       jtc #include <sys/param.h>
     49   1.1       jtc #include <sys/dkstat.h>
     50   1.1       jtc #include <sys/buf.h>
     51   1.1       jtc #include <sys/stat.h>
     52   1.1       jtc #include <sys/time.h>
     53   1.1       jtc #include <sys/user.h>
     54   1.1       jtc #include <sys/proc.h>
     55   1.1       jtc #include <sys/namei.h>
     56   1.1       jtc #include <sys/sysctl.h>
     57   1.1       jtc #include <vm/vm.h>
     58   1.1       jtc 
     59  1.11       mrg #if defined(UVM)
     60  1.11       mrg #include <uvm/uvm_extern.h>
     61  1.11       mrg #endif
     62  1.11       mrg 
     63   1.3   mycroft #include <ctype.h>
     64   1.3   mycroft #include <err.h>
     65   1.1       jtc #include <nlist.h>
     66   1.1       jtc #include <paths.h>
     67   1.3   mycroft #include <signal.h>
     68   1.3   mycroft #include <stdlib.h>
     69   1.1       jtc #include <string.h>
     70   1.3   mycroft #include <utmp.h>
     71   1.1       jtc #include <unistd.h>
     72   1.3   mycroft 
     73   1.1       jtc #include "systat.h"
     74   1.1       jtc #include "extern.h"
     75   1.1       jtc 
     76   1.1       jtc static struct Info {
     77   1.1       jtc 	long	time[CPUSTATES];
     78  1.11       mrg #if defined(UVM)
     79  1.11       mrg 	struct	uvmexp uvmexp;
     80  1.11       mrg #else
     81   1.1       jtc 	struct	vmmeter Cnt;
     82  1.11       mrg #endif
     83   1.1       jtc 	struct	vmtotal Total;
     84   1.1       jtc 	struct	nchstats nchstats;
     85   1.1       jtc 	long	nchcount;
     86   1.1       jtc 	long	*intrcnt;
     87   1.1       jtc } s, s1, s2, z;
     88   1.1       jtc 
     89   1.5   thorpej #include "dkstats.h"
     90   1.5   thorpej extern struct _disk	cur;
     91   1.5   thorpej 
     92   1.5   thorpej 
     93   1.1       jtc #define	cnt s.Cnt
     94   1.1       jtc #define oldcnt s1.Cnt
     95   1.1       jtc #define	total s.Total
     96   1.1       jtc #define	nchtotal s.nchstats
     97   1.1       jtc #define	oldnchtotal s1.nchstats
     98   1.1       jtc 
     99   1.1       jtc static	enum state { BOOT, TIME, RUN } state = TIME;
    100   1.1       jtc 
    101   1.1       jtc static void allocinfo __P((struct Info *));
    102   1.1       jtc static void copyinfo __P((struct Info *, struct Info *));
    103   1.1       jtc static float cputime __P((int));
    104   1.1       jtc static void dinfo __P((int, int));
    105   1.1       jtc static void getinfo __P((struct Info *, enum state));
    106   1.1       jtc static void putint __P((int, int, int, int));
    107   1.1       jtc static void putfloat __P((double, int, int, int, int, int));
    108   1.1       jtc static int ucount __P((void));
    109   1.1       jtc 
    110   1.1       jtc static	int ut;
    111   1.1       jtc static	char buf[26];
    112   1.1       jtc static	time_t t;
    113   1.1       jtc static	double etime;
    114   1.1       jtc static	float hertz;
    115   1.1       jtc static	int nintr;
    116   1.1       jtc static	long *intrloc;
    117   1.1       jtc static	char **intrname;
    118   1.1       jtc static	int nextintsrow;
    119   1.1       jtc 
    120   1.1       jtc struct	utmp utmp;
    121   1.1       jtc 
    122   1.1       jtc WINDOW *
    123   1.1       jtc openkre()
    124   1.1       jtc {
    125   1.1       jtc 
    126   1.1       jtc 	ut = open(_PATH_UTMP, O_RDONLY);
    127   1.1       jtc 	if (ut < 0)
    128   1.1       jtc 		error("No utmp");
    129   1.1       jtc 	return (stdscr);
    130   1.1       jtc }
    131   1.1       jtc 
    132   1.1       jtc void
    133   1.1       jtc closekre(w)
    134   1.1       jtc 	WINDOW *w;
    135   1.1       jtc {
    136   1.1       jtc 
    137   1.1       jtc 	(void) close(ut);
    138   1.1       jtc 	if (w == NULL)
    139   1.1       jtc 		return;
    140   1.1       jtc 	wclear(w);
    141   1.1       jtc 	wrefresh(w);
    142   1.1       jtc }
    143   1.1       jtc 
    144   1.1       jtc 
    145   1.1       jtc static struct nlist namelist[] = {
    146   1.1       jtc #define X_CPTIME	0
    147   1.1       jtc 	{ "_cp_time" },
    148  1.11       mrg #define X_TOTAL		1
    149   1.1       jtc 	{ "_total" },
    150  1.11       mrg #define	X_NCHSTATS	2
    151   1.1       jtc 	{ "_nchstats" },
    152  1.11       mrg #define	X_INTRNAMES	3
    153   1.1       jtc 	{ "_intrnames" },
    154  1.11       mrg #define	X_EINTRNAMES	4
    155   1.1       jtc 	{ "_eintrnames" },
    156  1.11       mrg #define	X_INTRCNT	5
    157   1.1       jtc 	{ "_intrcnt" },
    158  1.11       mrg #define	X_EINTRCNT	6
    159   1.1       jtc 	{ "_eintrcnt" },
    160  1.11       mrg #if !defined(UVM)
    161  1.11       mrg #define X_CNT		7
    162  1.11       mrg 	{ "_cnt" },
    163  1.11       mrg #endif
    164   1.1       jtc 	{ "" },
    165   1.1       jtc };
    166   1.1       jtc 
    167   1.1       jtc /*
    168   1.1       jtc  * These constants define where the major pieces are laid out
    169   1.1       jtc  */
    170   1.1       jtc #define STATROW		 0	/* uses 1 row and 68 cols */
    171   1.1       jtc #define STATCOL		 2
    172   1.1       jtc #define MEMROW		 2	/* uses 4 rows and 31 cols */
    173   1.1       jtc #define MEMCOL		 0
    174   1.1       jtc #define PAGEROW		 2	/* uses 4 rows and 26 cols */
    175   1.1       jtc #define PAGECOL		36
    176   1.1       jtc #define INTSROW		 2	/* uses all rows to bottom and 17 cols */
    177   1.1       jtc #define INTSCOL		63
    178   1.1       jtc #define PROCSROW	 7	/* uses 2 rows and 20 cols */
    179   1.1       jtc #define PROCSCOL	 0
    180   1.1       jtc #define GENSTATROW	 7	/* uses 2 rows and 30 cols */
    181   1.1       jtc #define GENSTATCOL	20
    182   1.1       jtc #define VMSTATROW	 7	/* uses 17 rows and 12 cols */
    183   1.1       jtc #define VMSTATCOL	48
    184   1.1       jtc #define GRAPHROW	10	/* uses 3 rows and 51 cols */
    185   1.1       jtc #define GRAPHCOL	 0
    186   1.1       jtc #define NAMEIROW	14	/* uses 3 rows and 38 cols */
    187   1.1       jtc #define NAMEICOL	 0
    188   1.1       jtc #define DISKROW		18	/* uses 5 rows and 50 cols (for 9 drives) */
    189   1.1       jtc #define DISKCOL		 0
    190   1.1       jtc 
    191   1.1       jtc #define	DRIVESPACE	 9	/* max # for space */
    192   1.1       jtc 
    193   1.1       jtc #if DK_NDRIVE > DRIVESPACE
    194   1.1       jtc #define	MAXDRIVES	DRIVESPACE	 /* max # to display */
    195   1.1       jtc #else
    196   1.1       jtc #define	MAXDRIVES	DK_NDRIVE	 /* max # to display */
    197   1.1       jtc #endif
    198   1.1       jtc 
    199   1.1       jtc int
    200   1.1       jtc initkre()
    201   1.1       jtc {
    202   1.1       jtc 	char *intrnamebuf, *cp;
    203   1.1       jtc 	int i;
    204   1.1       jtc 	static int once = 0;
    205  1.15  drochner 	extern gid_t egid;
    206   1.1       jtc 
    207   1.1       jtc 	if (namelist[0].n_type == 0) {
    208   1.1       jtc 		if (kvm_nlist(kd, namelist)) {
    209   1.1       jtc 			nlisterr(namelist);
    210   1.1       jtc 			return(0);
    211   1.1       jtc 		}
    212   1.1       jtc 		if (namelist[0].n_type == 0) {
    213   1.1       jtc 			error("No namelist");
    214   1.1       jtc 			return(0);
    215   1.1       jtc 		}
    216   1.1       jtc 	}
    217   1.1       jtc 	hertz = stathz ? stathz : hz;
    218  1.15  drochner 	if (! dkinit(1, egid))
    219   1.1       jtc 		return(0);
    220   1.1       jtc 	if (dk_ndrive && !once) {
    221   1.1       jtc #define	allocate(e, t) \
    222   1.7    scottr 	s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
    223   1.7    scottr 	s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
    224   1.7    scottr 	s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
    225   1.7    scottr 	z./**/e = (t *)calloc(dk_ndrive, sizeof (t));
    226   1.1       jtc 		once = 1;
    227   1.1       jtc #undef allocate
    228   1.1       jtc 	}
    229   1.1       jtc 	if (nintr == 0) {
    230   1.1       jtc 		nintr = (namelist[X_EINTRCNT].n_value -
    231   1.1       jtc 			namelist[X_INTRCNT].n_value) / sizeof (long);
    232   1.1       jtc 		intrloc = calloc(nintr, sizeof (long));
    233   1.1       jtc 		intrname = calloc(nintr, sizeof (long));
    234   1.1       jtc 		intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
    235   1.1       jtc 			namelist[X_INTRNAMES].n_value);
    236   1.1       jtc 		if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
    237   1.1       jtc 			error("Out of memory\n");
    238   1.1       jtc 			if (intrnamebuf)
    239   1.1       jtc 				free(intrnamebuf);
    240   1.1       jtc 			if (intrname)
    241   1.1       jtc 				free(intrname);
    242   1.1       jtc 			if (intrloc)
    243   1.1       jtc 				free(intrloc);
    244   1.1       jtc 			nintr = 0;
    245   1.1       jtc 			return(0);
    246   1.1       jtc 		}
    247   1.1       jtc 		NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
    248   1.1       jtc 			NVAL(X_INTRNAMES));
    249   1.1       jtc 		for (cp = intrnamebuf, i = 0; i < nintr; i++) {
    250   1.1       jtc 			intrname[i] = cp;
    251   1.1       jtc 			cp += strlen(cp) + 1;
    252   1.1       jtc 		}
    253   1.1       jtc 		nextintsrow = INTSROW + 2;
    254   1.1       jtc 		allocinfo(&s);
    255   1.1       jtc 		allocinfo(&s1);
    256   1.1       jtc 		allocinfo(&s2);
    257   1.1       jtc 		allocinfo(&z);
    258   1.1       jtc 	}
    259   1.1       jtc 	getinfo(&s2, RUN);
    260   1.1       jtc 	copyinfo(&s2, &s1);
    261   1.1       jtc 	return(1);
    262   1.1       jtc }
    263   1.1       jtc 
    264   1.1       jtc void
    265   1.1       jtc fetchkre()
    266   1.1       jtc {
    267   1.1       jtc 	time_t now;
    268   1.1       jtc 
    269   1.1       jtc 	time(&now);
    270   1.1       jtc 	strcpy(buf, ctime(&now));
    271   1.1       jtc 	buf[16] = '\0';
    272   1.1       jtc 	getinfo(&s, state);
    273   1.1       jtc }
    274   1.1       jtc 
    275   1.1       jtc void
    276   1.1       jtc labelkre()
    277   1.1       jtc {
    278  1.10     lukem 	int i, j;
    279   1.1       jtc 
    280   1.1       jtc 	clear();
    281   1.1       jtc 	mvprintw(STATROW, STATCOL + 4, "users    Load");
    282  1.13       mrg #if defined(UVM)
    283  1.13       mrg 	mvprintw(MEMROW, MEMCOL,     "          memory totals (in KB)");
    284  1.13       mrg 	mvprintw(MEMROW + 1, MEMCOL, "         real   virtual    free");
    285  1.13       mrg 	mvprintw(MEMROW + 2, MEMCOL, "Active");
    286  1.13       mrg 	mvprintw(MEMROW + 3, MEMCOL, "All");
    287  1.13       mrg 
    288  1.13       mrg 	mvprintw(PAGEROW, PAGECOL, "        PAGING   SWAPPING ");
    289  1.13       mrg 	mvprintw(PAGEROW + 1, PAGECOL, "        in  out   in  out ");
    290  1.13       mrg 	mvprintw(PAGEROW + 2, PAGECOL, "ops");
    291  1.13       mrg 	mvprintw(PAGEROW + 3, PAGECOL, "pages");
    292  1.13       mrg #else
    293   1.1       jtc 	mvprintw(MEMROW, MEMCOL, "Mem:KB  REAL        VIRTUAL");
    294   1.1       jtc 	mvprintw(MEMROW + 1, MEMCOL, "      Tot Share    Tot  Share");
    295   1.1       jtc 	mvprintw(MEMROW + 2, MEMCOL, "Act");
    296   1.1       jtc 	mvprintw(MEMROW + 3, MEMCOL, "All");
    297   1.1       jtc 
    298   1.1       jtc 	mvprintw(MEMROW + 1, MEMCOL + 31, "Free");
    299   1.1       jtc 
    300   1.1       jtc 	mvprintw(PAGEROW, PAGECOL,     "        PAGING   SWAPPING ");
    301   1.1       jtc 	mvprintw(PAGEROW + 1, PAGECOL, "        in  out   in  out ");
    302   1.1       jtc 	mvprintw(PAGEROW + 2, PAGECOL, "count");
    303   1.1       jtc 	mvprintw(PAGEROW + 3, PAGECOL, "pages");
    304  1.13       mrg #endif
    305   1.1       jtc 
    306   1.1       jtc 	mvprintw(INTSROW, INTSCOL + 3, " Interrupts");
    307   1.1       jtc 	mvprintw(INTSROW + 1, INTSCOL + 9, "total");
    308   1.1       jtc 
    309  1.12       mrg #if defined(UVM)
    310  1.12       mrg 	mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "forks");
    311  1.12       mrg 	mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "fkppw");
    312  1.12       mrg 	mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "fksvm");
    313  1.12       mrg 	mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "pwait");
    314  1.12       mrg 	mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "relck");
    315  1.12       mrg 	mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "rlkok");
    316  1.12       mrg 	mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "noram");
    317  1.12       mrg 	mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "ndcpy");
    318  1.12       mrg 	mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "fltcp");
    319  1.12       mrg 	mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "zfod");
    320  1.12       mrg 	mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "cow");
    321  1.12       mrg 	mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "fmin");
    322  1.12       mrg 	mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "ftarg");
    323  1.12       mrg 	mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "itarg");
    324  1.12       mrg 	mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "wired");
    325  1.12       mrg 	mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "pdfre");
    326  1.12       mrg 	if (LINES - 1 > VMSTATROW + 16)
    327  1.12       mrg 		mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "pdscn");
    328  1.12       mrg #else
    329   1.1       jtc 	mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "cow");
    330   1.1       jtc 	mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "objlk");
    331   1.1       jtc 	mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "objht");
    332   1.1       jtc 	mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "zfod");
    333   1.1       jtc 	mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "nzfod");
    334   1.1       jtc 	mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "%%zfod");
    335   1.1       jtc 	mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "kern");
    336   1.1       jtc 	mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "wire");
    337   1.1       jtc 	mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "act");
    338   1.1       jtc 	mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "inact");
    339   1.1       jtc 	mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "free");
    340   1.1       jtc 	mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "daefr");
    341   1.1       jtc 	mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "prcfr");
    342   1.1       jtc 	mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "react");
    343   1.1       jtc 	mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "scan");
    344   1.1       jtc 	mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "hdrev");
    345   1.1       jtc 	if (LINES - 1 > VMSTATROW + 16)
    346   1.1       jtc 		mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "intrn");
    347  1.11       mrg #endif
    348   1.1       jtc 
    349   1.1       jtc 	mvprintw(GENSTATROW, GENSTATCOL, "  Csw  Trp  Sys  Int  Sof  Flt");
    350   1.1       jtc 
    351   1.1       jtc 	mvprintw(GRAPHROW, GRAPHCOL,
    352   1.1       jtc 		"    . %% Sys    . %% User    . %% Nice    . %% Idle");
    353  1.13       mrg #if defined(UVM)
    354  1.13       mrg 	mvprintw(PROCSROW, PROCSCOL, "Proc:r  d  s  w");
    355  1.13       mrg #else
    356  1.13       mrg 	mvprintw(PROCSROW, PROCSCOL, "Proc:r  d  s  w  p");
    357  1.13       mrg #endif
    358   1.1       jtc 	mvprintw(GRAPHROW + 1, GRAPHCOL,
    359   1.1       jtc 		"|    |    |    |    |    |    |    |    |    |    |");
    360   1.1       jtc 
    361   1.1       jtc 	mvprintw(NAMEIROW, NAMEICOL, "Namei         Sys-cache     Proc-cache");
    362   1.1       jtc 	mvprintw(NAMEIROW + 1, NAMEICOL,
    363   1.1       jtc 		"    Calls     hits    %%     hits     %%");
    364   1.1       jtc 	mvprintw(DISKROW, DISKCOL, "Discs");
    365   1.1       jtc 	mvprintw(DISKROW + 1, DISKCOL, "seeks");
    366   1.1       jtc 	mvprintw(DISKROW + 2, DISKCOL, "xfers");
    367   1.5   thorpej 	mvprintw(DISKROW + 3, DISKCOL, "Kbyte");
    368   1.5   thorpej 	mvprintw(DISKROW + 4, DISKCOL, "  sec");
    369   1.1       jtc 	j = 0;
    370   1.1       jtc 	for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)
    371   1.1       jtc 		if (dk_select[i]) {
    372   1.1       jtc 			mvprintw(DISKROW, DISKCOL + 5 + 5 * j,
    373   1.1       jtc 				"  %3.3s", dr_name[j]);
    374   1.1       jtc 			j++;
    375   1.1       jtc 		}
    376   1.1       jtc 	for (i = 0; i < nintr; i++) {
    377   1.1       jtc 		if (intrloc[i] == 0)
    378   1.1       jtc 			continue;
    379   1.1       jtc 		mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", intrname[i]);
    380   1.1       jtc 	}
    381   1.1       jtc }
    382   1.1       jtc 
    383   1.1       jtc #define X(fld)	{t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
    384   1.1       jtc #define Y(fld)	{t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
    385   1.1       jtc #define Z(fld)	{t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
    386   1.1       jtc 	if(state == TIME) s1.nchstats.fld = t;}
    387  1.16   mycroft #define PUTRATE(fld, l, c, w) {Y(fld); putint((int)((float)s.fld/etime + 0.5), l, c, w);}
    388   1.1       jtc #define MAXFAIL 5
    389   1.1       jtc 
    390   1.1       jtc static	char cpuchar[CPUSTATES] = { '=' , '>', '-', ' ' };
    391   1.1       jtc static	char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_IDLE };
    392   1.1       jtc 
    393   1.1       jtc void
    394   1.1       jtc showkre()
    395   1.1       jtc {
    396   1.1       jtc 	float f1, f2;
    397   1.1       jtc 	int psiz, inttotal;
    398   1.1       jtc 	int i, l, c;
    399   1.1       jtc 	static int failcnt = 0;
    400   1.5   thorpej 
    401   1.5   thorpej 	if (state == TIME)
    402   1.5   thorpej 		dkswap();
    403   1.1       jtc 	etime = 0;
    404   1.1       jtc 	for(i = 0; i < CPUSTATES; i++) {
    405   1.1       jtc 		X(time);
    406   1.1       jtc 		etime += s.time[i];
    407   1.1       jtc 	}
    408   1.1       jtc 	if (etime < 5.0) {	/* < 5 ticks - ignore this trash */
    409   1.1       jtc 		if (failcnt++ >= MAXFAIL) {
    410   1.1       jtc 			clear();
    411   1.1       jtc 			mvprintw(2, 10, "The alternate system clock has died!");
    412   1.1       jtc 			mvprintw(3, 10, "Reverting to ``pigs'' display.");
    413   1.1       jtc 			move(CMDLINE, 0);
    414   1.1       jtc 			refresh();
    415   1.1       jtc 			failcnt = 0;
    416   1.1       jtc 			sleep(5);
    417   1.1       jtc 			command("pigs");
    418   1.1       jtc 		}
    419   1.1       jtc 		return;
    420   1.1       jtc 	}
    421   1.1       jtc 	failcnt = 0;
    422   1.1       jtc 	etime /= hertz;
    423   1.1       jtc 	inttotal = 0;
    424   1.1       jtc 	for (i = 0; i < nintr; i++) {
    425   1.1       jtc 		if (s.intrcnt[i] == 0)
    426   1.1       jtc 			continue;
    427   1.1       jtc 		if (intrloc[i] == 0) {
    428   1.1       jtc 			if (nextintsrow == LINES)
    429   1.1       jtc 				continue;
    430   1.1       jtc 			intrloc[i] = nextintsrow++;
    431   1.1       jtc 			mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s",
    432   1.1       jtc 				intrname[i]);
    433   1.1       jtc 		}
    434   1.1       jtc 		X(intrcnt);
    435   1.1       jtc 		l = (int)((float)s.intrcnt[i]/etime + 0.5);
    436   1.1       jtc 		inttotal += l;
    437   1.1       jtc 		putint(l, intrloc[i], INTSCOL, 8);
    438   1.1       jtc 	}
    439   1.1       jtc 	putint(inttotal, INTSROW + 1, INTSCOL, 8);
    440   1.1       jtc 	Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss);
    441   1.1       jtc 	Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes);
    442   1.1       jtc 	s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits +
    443   1.1       jtc 	    nchtotal.ncs_miss + nchtotal.ncs_long;
    444   1.1       jtc 	if (state == TIME)
    445   1.1       jtc 		s1.nchcount = s.nchcount;
    446   1.1       jtc 
    447   1.1       jtc 	psiz = 0;
    448   1.1       jtc 	f2 = 0.0;
    449   1.1       jtc 
    450   1.1       jtc 	/*
    451   1.1       jtc 	 * Last CPU state not calculated yet.
    452   1.1       jtc 	 */
    453   1.1       jtc 	for (c = 0; c < CPUSTATES - 1; c++) {
    454   1.1       jtc 		i = cpuorder[c];
    455   1.1       jtc 		f1 = cputime(i);
    456   1.1       jtc 		f2 += f1;
    457   1.1       jtc 		l = (int) ((f2 + 1.0) / 2.0) - psiz;
    458   1.1       jtc 		if (c == 0)
    459   1.1       jtc 			putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);
    460   1.1       jtc 		else
    461   1.1       jtc 			putfloat(f1, GRAPHROW, GRAPHCOL + 12 * c,
    462   1.1       jtc 				5, 1, 0);
    463   1.1       jtc 		move(GRAPHROW + 2, psiz);
    464   1.1       jtc 		psiz += l;
    465   1.1       jtc 		while (l-- > 0)
    466   1.1       jtc 			addch(cpuchar[c]);
    467   1.1       jtc 	}
    468   1.1       jtc 
    469   1.1       jtc 	putint(ucount(), STATROW, STATCOL, 3);
    470   1.1       jtc 	putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
    471   1.1       jtc 	putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
    472   1.1       jtc 	putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
    473   1.1       jtc 	mvaddstr(STATROW, STATCOL + 53, buf);
    474  1.11       mrg #if defined(UVM)
    475  1.17  drochner #define pgtokb(pg)	((pg) * (s.uvmexp.pagesize / 1024))
    476  1.11       mrg #else
    477  1.17  drochner #define pgtokb(pg)	((pg) * (cnt.v_page_size / 1024))
    478  1.11       mrg #endif
    479  1.11       mrg 
    480  1.12       mrg #if defined(UVM)
    481  1.13       mrg 	putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 7);
    482  1.12       mrg 	putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse),	/* XXX */
    483  1.13       mrg 	    MEMROW + 2, MEMCOL + 16, 7);
    484  1.13       mrg 	putint(pgtokb(s.uvmexp.npages - s.uvmexp.free), MEMROW + 3, MEMCOL + 6, 7);
    485  1.12       mrg 	putint(pgtokb(s.uvmexp.npages - s.uvmexp.free + s.uvmexp.swpginuse),
    486  1.13       mrg 	    MEMROW + 3, MEMCOL + 16, 7);
    487  1.13       mrg 	putint(pgtokb(s.uvmexp.free), MEMROW + 2, MEMCOL + 24, 7);
    488  1.12       mrg 	putint(pgtokb(s.uvmexp.free + s.uvmexp.swpages - s.uvmexp.swpginuse),
    489  1.13       mrg 	    MEMROW + 3, MEMCOL + 24, 7);
    490  1.12       mrg #else
    491   1.1       jtc 	putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 6);
    492   1.1       jtc 	putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 9, 6);
    493   1.1       jtc 	putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 15, 7);
    494   1.1       jtc 	putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 22, 7);
    495   1.1       jtc 	putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 6);
    496   1.1       jtc 	putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 9, 6);
    497   1.1       jtc 	putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 15, 7);
    498   1.1       jtc 	putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 22, 7);
    499   1.1       jtc 	putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 29, 6);
    500  1.12       mrg #endif
    501   1.1       jtc 	putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
    502  1.13       mrg 	putint(total.t_dw, PROCSROW + 1, PROCSCOL + 6, 3);
    503  1.13       mrg 	putint(total.t_sl, PROCSROW + 1, PROCSCOL + 9, 3);
    504  1.13       mrg 	putint(total.t_sw, PROCSROW + 1, PROCSCOL + 12, 3);
    505  1.13       mrg #if !defined(UVM)
    506  1.13       mrg 	putint(total.t_pw, PROCSROW + 1, PROCSCOL + 15, 3);
    507  1.13       mrg #endif
    508  1.11       mrg #if defined(UVM)
    509  1.12       mrg 	PUTRATE(uvmexp.forks, VMSTATROW + 0, VMSTATCOL + 3, 6);
    510  1.12       mrg 	PUTRATE(uvmexp.forks_ppwait, VMSTATROW + 1, VMSTATCOL + 3, 6);
    511  1.12       mrg 	PUTRATE(uvmexp.forks_sharevm, VMSTATROW + 2, VMSTATCOL + 3, 6);
    512  1.12       mrg 	PUTRATE(uvmexp.fltpgwait, VMSTATROW + 3, VMSTATCOL + 4, 5);
    513  1.12       mrg 	PUTRATE(uvmexp.fltrelck, VMSTATROW + 4, VMSTATCOL + 3, 6);
    514  1.12       mrg 	PUTRATE(uvmexp.fltrelckok, VMSTATROW + 5, VMSTATCOL + 3, 6);
    515  1.12       mrg 	PUTRATE(uvmexp.fltnoram, VMSTATROW + 6, VMSTATCOL + 3, 6);
    516  1.12       mrg 	PUTRATE(uvmexp.fltamcopy, VMSTATROW + 7, VMSTATCOL + 3, 6);
    517  1.12       mrg 	PUTRATE(uvmexp.flt_prcopy, VMSTATROW + 8, VMSTATCOL + 3, 6);
    518  1.12       mrg 	PUTRATE(uvmexp.flt_przero, VMSTATROW + 9, VMSTATCOL + 3, 6);
    519  1.12       mrg 	PUTRATE(uvmexp.flt_acow, VMSTATROW + 10, VMSTATCOL, 9);
    520  1.12       mrg 	putint(s.uvmexp.freemin, VMSTATROW + 11, VMSTATCOL, 9);
    521  1.12       mrg 	putint(s.uvmexp.freetarg, VMSTATROW + 12, VMSTATCOL, 9);
    522  1.12       mrg 	putint(s.uvmexp.inactarg, VMSTATROW + 13, VMSTATCOL, 9);
    523  1.12       mrg 	putint(s.uvmexp.wired, VMSTATROW + 14, VMSTATCOL, 9);
    524  1.12       mrg 	PUTRATE(uvmexp.pdfreed, VMSTATROW + 15, VMSTATCOL, 9);
    525  1.11       mrg 	if (LINES - 1 > VMSTATROW + 16)
    526  1.12       mrg 		PUTRATE(uvmexp.pdscans, VMSTATROW + 16, VMSTATCOL, 9);
    527  1.12       mrg 
    528  1.12       mrg 	PUTRATE(uvmexp.pageins, PAGEROW + 2, PAGECOL + 5, 5);
    529  1.11       mrg 	PUTRATE(uvmexp.pdpageouts, PAGEROW + 2, PAGECOL + 10, 5);
    530  1.12       mrg 	PUTRATE(uvmexp.swapins, PAGEROW + 2, PAGECOL + 15, 5);
    531  1.12       mrg 	PUTRATE(uvmexp.swapouts, PAGEROW + 2, PAGECOL + 20, 5);
    532  1.12       mrg 	PUTRATE(uvmexp.pgswapin, PAGEROW + 3, PAGECOL + 5, 5);
    533  1.12       mrg 	PUTRATE(uvmexp.pgswapout, PAGEROW + 3, PAGECOL + 10, 5);
    534  1.12       mrg 
    535  1.11       mrg 	PUTRATE(uvmexp.swtch, GENSTATROW + 1, GENSTATCOL, 5);
    536  1.11       mrg 	PUTRATE(uvmexp.traps, GENSTATROW + 1, GENSTATCOL + 5, 5);
    537  1.11       mrg 	PUTRATE(uvmexp.syscalls, GENSTATROW + 1, GENSTATCOL + 10, 5);
    538  1.11       mrg 	PUTRATE(uvmexp.intrs, GENSTATROW + 1, GENSTATCOL + 15, 5);
    539  1.11       mrg 	PUTRATE(uvmexp.softs, GENSTATROW + 1, GENSTATCOL + 20, 5);
    540  1.11       mrg 	PUTRATE(uvmexp.faults, GENSTATROW + 1, GENSTATCOL + 25, 5);
    541  1.11       mrg #else
    542   1.1       jtc 	PUTRATE(Cnt.v_cow_faults, VMSTATROW + 0, VMSTATCOL + 3, 6);
    543   1.1       jtc 	PUTRATE(Cnt.v_lookups, VMSTATROW + 1, VMSTATCOL + 3, 6);
    544   1.1       jtc 	PUTRATE(Cnt.v_hits, VMSTATROW + 2, VMSTATCOL + 3, 6);
    545   1.1       jtc 	PUTRATE(Cnt.v_zfod, VMSTATROW + 3, VMSTATCOL + 4, 5);
    546   1.1       jtc 	PUTRATE(Cnt.v_nzfod, VMSTATROW + 4, VMSTATCOL + 3, 6);
    547   1.1       jtc 	putfloat(cnt.v_nzfod == 0 ? 0.0 : (100.0 * cnt.v_zfod / cnt.v_nzfod),
    548   1.1       jtc 		 VMSTATROW + 5, VMSTATCOL + 2, 7, 2, 1);
    549   1.1       jtc 	putint(pgtokb(cnt.v_kernel_pages), VMSTATROW + 6, VMSTATCOL, 9);
    550   1.1       jtc 	putint(pgtokb(cnt.v_wire_count), VMSTATROW + 7, VMSTATCOL, 9);
    551   1.1       jtc 	putint(pgtokb(cnt.v_active_count), VMSTATROW + 8, VMSTATCOL, 9);
    552   1.1       jtc 	putint(pgtokb(cnt.v_inactive_count), VMSTATROW + 9, VMSTATCOL, 9);
    553   1.1       jtc 	putint(pgtokb(cnt.v_free_count), VMSTATROW + 10, VMSTATCOL, 9);
    554   1.1       jtc 	PUTRATE(Cnt.v_dfree, VMSTATROW + 11, VMSTATCOL, 9);
    555   1.1       jtc 	PUTRATE(Cnt.v_pfree, VMSTATROW + 12, VMSTATCOL, 9);
    556   1.1       jtc 	PUTRATE(Cnt.v_reactivated, VMSTATROW + 13, VMSTATCOL, 9);
    557   1.1       jtc 	PUTRATE(Cnt.v_scan, VMSTATROW + 14, VMSTATCOL, 9);
    558   1.1       jtc 	PUTRATE(Cnt.v_rev, VMSTATROW + 15, VMSTATCOL, 9);
    559   1.1       jtc 	if (LINES - 1 > VMSTATROW + 16)
    560   1.1       jtc 		PUTRATE(Cnt.v_intrans, VMSTATROW + 16, VMSTATCOL, 9);
    561  1.16   mycroft 
    562   1.1       jtc 	PUTRATE(Cnt.v_pageins, PAGEROW + 2, PAGECOL + 5, 5);
    563   1.1       jtc 	PUTRATE(Cnt.v_pageouts, PAGEROW + 2, PAGECOL + 10, 5);
    564   1.1       jtc 	PUTRATE(Cnt.v_swpin, PAGEROW + 2, PAGECOL + 15, 5);	/* - */
    565   1.1       jtc 	PUTRATE(Cnt.v_swpout, PAGEROW + 2, PAGECOL + 20, 5);	/* - */
    566   1.1       jtc 	PUTRATE(Cnt.v_pgpgin, PAGEROW + 3, PAGECOL + 5, 5);	/* ? */
    567   1.1       jtc 	PUTRATE(Cnt.v_pgpgout, PAGEROW + 3, PAGECOL + 10, 5);	/* ? */
    568   1.1       jtc 	PUTRATE(Cnt.v_pswpin, PAGEROW + 3, PAGECOL + 15, 5);	/* - */
    569   1.1       jtc 	PUTRATE(Cnt.v_pswpout, PAGEROW + 3, PAGECOL + 20, 5);	/* - */
    570  1.16   mycroft 
    571   1.1       jtc 	PUTRATE(Cnt.v_swtch, GENSTATROW + 1, GENSTATCOL, 5);
    572   1.1       jtc 	PUTRATE(Cnt.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5);
    573   1.1       jtc 	PUTRATE(Cnt.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5);
    574   1.1       jtc 	PUTRATE(Cnt.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5);
    575   1.1       jtc 	PUTRATE(Cnt.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5);
    576   1.1       jtc 	PUTRATE(Cnt.v_faults, GENSTATROW + 1, GENSTATCOL + 25, 5);
    577  1.11       mrg #endif
    578   1.1       jtc 	mvprintw(DISKROW, DISKCOL + 5, "                              ");
    579   1.1       jtc 	for (i = 0, c = 0; i < dk_ndrive && c < MAXDRIVES; i++)
    580   1.1       jtc 		if (dk_select[i]) {
    581   1.1       jtc 			mvprintw(DISKROW, DISKCOL + 5 + 5 * c,
    582   1.1       jtc 				"  %3.3s", dr_name[i]);
    583   1.1       jtc 			dinfo(i, ++c);
    584   1.1       jtc 		}
    585   1.1       jtc 	putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
    586   1.1       jtc 	putint(nchtotal.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 9, 9);
    587   1.1       jtc #define nz(x)	((x) ? (x) : 1)
    588   1.1       jtc 	putfloat(nchtotal.ncs_goodhits * 100.0 / nz(s.nchcount),
    589   1.1       jtc 	   NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
    590   1.1       jtc 	putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
    591   1.1       jtc 	putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
    592   1.1       jtc 	   NAMEIROW + 2, NAMEICOL + 34, 4, 0, 1);
    593   1.1       jtc #undef nz
    594   1.1       jtc }
    595   1.1       jtc 
    596   1.1       jtc int
    597   1.1       jtc cmdkre(cmd, args)
    598   1.1       jtc 	char *cmd, *args;
    599   1.1       jtc {
    600   1.1       jtc 
    601   1.1       jtc 	if (prefix(cmd, "run")) {
    602   1.1       jtc 		copyinfo(&s2, &s1);
    603   1.1       jtc 		state = RUN;
    604   1.1       jtc 		return (1);
    605   1.1       jtc 	}
    606   1.1       jtc 	if (prefix(cmd, "boot")) {
    607   1.1       jtc 		state = BOOT;
    608   1.1       jtc 		copyinfo(&z, &s1);
    609   1.1       jtc 		return (1);
    610   1.1       jtc 	}
    611   1.1       jtc 	if (prefix(cmd, "time")) {
    612   1.1       jtc 		state = TIME;
    613   1.1       jtc 		return (1);
    614   1.1       jtc 	}
    615   1.1       jtc 	if (prefix(cmd, "zero")) {
    616   1.1       jtc 		if (state == RUN)
    617   1.1       jtc 			getinfo(&s1, RUN);
    618   1.1       jtc 		return (1);
    619   1.1       jtc 	}
    620   1.1       jtc 	return (dkcmd(cmd, args));
    621   1.1       jtc }
    622   1.1       jtc 
    623   1.1       jtc /* calculate number of users on the system */
    624   1.1       jtc static int
    625   1.1       jtc ucount()
    626   1.1       jtc {
    627  1.10     lukem 	int nusers = 0;
    628   1.1       jtc 
    629   1.1       jtc 	if (ut < 0)
    630   1.1       jtc 		return (0);
    631   1.1       jtc 	while (read(ut, &utmp, sizeof(utmp)))
    632   1.1       jtc 		if (utmp.ut_name[0] != '\0')
    633   1.1       jtc 			nusers++;
    634   1.1       jtc 
    635   1.9    kleink 	lseek(ut, (off_t)0, SEEK_SET);
    636   1.1       jtc 	return (nusers);
    637   1.1       jtc }
    638   1.1       jtc 
    639   1.1       jtc static float
    640   1.1       jtc cputime(indx)
    641   1.1       jtc 	int indx;
    642   1.1       jtc {
    643   1.1       jtc 	double t;
    644  1.10     lukem 	int i;
    645   1.1       jtc 
    646   1.1       jtc 	t = 0;
    647   1.1       jtc 	for (i = 0; i < CPUSTATES; i++)
    648   1.1       jtc 		t += s.time[i];
    649   1.1       jtc 	if (t == 0.0)
    650   1.1       jtc 		t = 1.0;
    651   1.1       jtc 	return (s.time[indx] * 100.0 / t);
    652   1.1       jtc }
    653   1.1       jtc 
    654   1.1       jtc static void
    655   1.1       jtc putint(n, l, c, w)
    656   1.1       jtc 	int n, l, c, w;
    657   1.1       jtc {
    658   1.1       jtc 	char b[128];
    659   1.1       jtc 
    660   1.1       jtc 	move(l, c);
    661   1.1       jtc 	if (n == 0) {
    662   1.1       jtc 		while (w-- > 0)
    663   1.1       jtc 			addch(' ');
    664   1.1       jtc 		return;
    665   1.1       jtc 	}
    666  1.14       mrg 	(void)snprintf(b, sizeof b, "%*d", w, n);
    667   1.1       jtc 	if (strlen(b) > w) {
    668   1.1       jtc 		while (w-- > 0)
    669   1.1       jtc 			addch('*');
    670   1.1       jtc 		return;
    671   1.1       jtc 	}
    672   1.1       jtc 	addstr(b);
    673   1.1       jtc }
    674   1.1       jtc 
    675   1.1       jtc static void
    676   1.1       jtc putfloat(f, l, c, w, d, nz)
    677   1.1       jtc 	double f;
    678   1.1       jtc 	int l, c, w, d, nz;
    679   1.1       jtc {
    680   1.1       jtc 	char b[128];
    681   1.1       jtc 
    682   1.1       jtc 	move(l, c);
    683   1.1       jtc 	if (nz && f == 0.0) {
    684   1.1       jtc 		while (--w >= 0)
    685   1.1       jtc 			addch(' ');
    686   1.1       jtc 		return;
    687   1.1       jtc 	}
    688  1.14       mrg 	(void)snprintf(b, sizeof b, "%*.*f", w, d, f);
    689   1.1       jtc 	if (strlen(b) > w) {
    690   1.1       jtc 		while (--w >= 0)
    691   1.1       jtc 			addch('*');
    692   1.1       jtc 		return;
    693   1.1       jtc 	}
    694   1.1       jtc 	addstr(b);
    695   1.1       jtc }
    696   1.1       jtc 
    697   1.1       jtc static void
    698   1.1       jtc getinfo(s, st)
    699   1.1       jtc 	struct Info *s;
    700   1.1       jtc 	enum state st;
    701   1.1       jtc {
    702   1.4       cgd 	int mib[2];
    703   1.4       cgd 	size_t size;
    704   1.1       jtc 	extern int errno;
    705   1.1       jtc 
    706   1.5   thorpej 	dkreadstats();
    707   1.1       jtc 	NREAD(X_CPTIME, s->time, sizeof s->time);
    708   1.1       jtc 	NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
    709   1.1       jtc 	NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
    710  1.11       mrg #if defined(UVM)
    711  1.11       mrg 	size = sizeof(s->uvmexp);
    712  1.11       mrg 	mib[0] = CTL_VM;
    713  1.11       mrg 	mib[1] = VM_UVMEXP;
    714  1.11       mrg 	if (sysctl(mib, 2, &s->uvmexp, &size, NULL, 0) < 0) {
    715  1.11       mrg 		error("can't get uvmexp: %s\n", strerror(errno));
    716  1.11       mrg 		memset(&s->uvmexp, 0, sizeof(s->uvmexp));
    717  1.11       mrg 	}
    718  1.11       mrg #else
    719  1.11       mrg 	NREAD(X_CNT, &s->Cnt, sizeof s->Cnt);
    720  1.11       mrg #endif
    721   1.1       jtc 	size = sizeof(s->Total);
    722   1.1       jtc 	mib[0] = CTL_VM;
    723   1.1       jtc 	mib[1] = VM_METER;
    724   1.1       jtc 	if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) {
    725   1.1       jtc 		error("Can't get kernel info: %s\n", strerror(errno));
    726  1.10     lukem 		memset(&s->Total, 0, sizeof(s->Total));
    727   1.1       jtc 	}
    728   1.1       jtc }
    729   1.1       jtc 
    730   1.1       jtc static void
    731   1.1       jtc allocinfo(s)
    732   1.1       jtc 	struct Info *s;
    733   1.1       jtc {
    734   1.1       jtc 
    735   1.1       jtc 	s->intrcnt = (long *) malloc(nintr * sizeof(long));
    736   1.3   mycroft 	if (s->intrcnt == NULL)
    737   1.3   mycroft 		errx(2, "out of memory");
    738   1.1       jtc }
    739   1.1       jtc 
    740   1.1       jtc static void
    741   1.1       jtc copyinfo(from, to)
    742  1.10     lukem 	struct Info *from, *to;
    743   1.1       jtc {
    744   1.1       jtc 	long *intrcnt;
    745   1.1       jtc 
    746   1.5   thorpej 	intrcnt = to->intrcnt;
    747   1.1       jtc 	*to = *from;
    748  1.10     lukem 	memmove(to->intrcnt = intrcnt, from->intrcnt, nintr * sizeof (int));
    749   1.1       jtc }
    750   1.1       jtc 
    751   1.1       jtc static void
    752   1.1       jtc dinfo(dn, c)
    753   1.1       jtc 	int dn, c;
    754   1.1       jtc {
    755   1.5   thorpej 	double words, atime;
    756   1.1       jtc 
    757   1.1       jtc 	c = DISKCOL + c * 5;
    758   1.5   thorpej 
    759   1.5   thorpej 	/* time busy in disk activity */
    760   1.5   thorpej 	atime = (double)cur.dk_time[dn].tv_sec +
    761   1.5   thorpej 		((double)cur.dk_time[dn].tv_usec / (double)1000000);
    762   1.5   thorpej 
    763   1.5   thorpej 	words = cur.dk_bytes[dn] / 1024.0;	/* # of K transferred */
    764   1.5   thorpej 
    765   1.5   thorpej 	putint((int)((float)cur.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5);
    766   1.5   thorpej 	putint((int)((float)cur.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5);
    767   1.5   thorpej 	putint((int)(words/etime + 0.5), DISKROW + 3, c, 5);
    768   1.5   thorpej 	putfloat(atime/etime, DISKROW + 4, c, 5, 1, 1);
    769   1.1       jtc }
    770