Home | History | Annotate | Line # | Download | only in vmstat
vmstat.c revision 1.12
      1   1.1      cgd /*
      2   1.1      cgd  * Copyright (c) 1980, 1986, 1991 The Regents of the University of California.
      3   1.1      cgd  * All rights reserved.
      4   1.1      cgd  *
      5   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      6   1.1      cgd  * modification, are permitted provided that the following conditions
      7   1.1      cgd  * are met:
      8   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
      9   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     10   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     12   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     13   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     14   1.1      cgd  *    must display the following acknowledgement:
     15   1.1      cgd  *	This product includes software developed by the University of
     16   1.1      cgd  *	California, Berkeley and its contributors.
     17   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     18   1.1      cgd  *    may be used to endorse or promote products derived from this software
     19   1.1      cgd  *    without specific prior written permission.
     20   1.1      cgd  *
     21   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31   1.1      cgd  * SUCH DAMAGE.
     32   1.1      cgd  */
     33   1.1      cgd 
     34   1.1      cgd #ifndef lint
     35   1.1      cgd char copyright[] =
     36   1.1      cgd "@(#) Copyright (c) 1980, 1986, 1991 The Regents of the University of California.\n\
     37   1.1      cgd  All rights reserved.\n";
     38   1.1      cgd #endif /* not lint */
     39   1.1      cgd 
     40   1.1      cgd #ifndef lint
     41   1.6  mycroft /*static char sccsid[] = "from: @(#)vmstat.c	5.31 (Berkeley) 7/2/91";*/
     42  1.12      cgd static char rcsid[] = "$Id: vmstat.c,v 1.12 1994/04/15 07:07:27 cgd Exp $";
     43   1.1      cgd #endif /* not lint */
     44   1.1      cgd 
     45   1.1      cgd #include <sys/param.h>
     46   1.1      cgd #include <sys/time.h>
     47   1.1      cgd #include <sys/proc.h>
     48   1.1      cgd #include <sys/user.h>
     49   1.1      cgd #include <sys/dkstat.h>
     50   1.1      cgd #include <sys/buf.h>
     51   1.1      cgd #include <sys/namei.h>
     52   1.1      cgd #include <sys/malloc.h>
     53   1.1      cgd #include <sys/signal.h>
     54   1.1      cgd #include <sys/fcntl.h>
     55   1.1      cgd #include <sys/ioctl.h>
     56   1.1      cgd #include <sys/vmmeter.h>
     57   1.1      cgd #include <time.h>
     58   1.1      cgd #include <nlist.h>
     59   1.1      cgd #include <kvm.h>
     60   1.1      cgd #include <errno.h>
     61   1.1      cgd #include <unistd.h>
     62   1.1      cgd #include <stdio.h>
     63   1.1      cgd #include <ctype.h>
     64   1.1      cgd #include <stdlib.h>
     65   1.1      cgd #include <string.h>
     66   1.1      cgd #include <paths.h>
     67   1.1      cgd 
     68   1.1      cgd #define NEWVM			/* XXX till old has been updated or purged */
     69   1.1      cgd struct nlist nl[] = {
     70   1.1      cgd #define	X_CPTIME	0
     71   1.1      cgd 	{ "_cp_time" },
     72   1.1      cgd #define X_TOTAL		1
     73   1.1      cgd 	{ "_total" },
     74  1.12      cgd #define X_CNT		2
     75  1.12      cgd 	{ "_cnt" },
     76   1.1      cgd #define	X_BOOTTIME	3
     77   1.1      cgd 	{ "_boottime" },
     78   1.1      cgd #define	X_DKXFER	4
     79   1.1      cgd 	{ "_dk_xfer" },
     80   1.1      cgd #define X_HZ		5
     81   1.1      cgd 	{ "_hz" },
     82   1.1      cgd #define X_PHZ		6
     83   1.1      cgd 	{ "_phz" },
     84   1.1      cgd #define X_NCHSTATS	7
     85   1.1      cgd 	{ "_nchstats" },
     86   1.1      cgd #define	X_INTRNAMES	8
     87   1.1      cgd 	{ "_intrnames" },
     88   1.1      cgd #define	X_EINTRNAMES	9
     89   1.1      cgd 	{ "_eintrnames" },
     90   1.1      cgd #define	X_INTRCNT	10
     91   1.1      cgd 	{ "_intrcnt" },
     92   1.1      cgd #define	X_EINTRCNT	11
     93   1.1      cgd 	{ "_eintrcnt" },
     94   1.1      cgd #define	X_DK_NDRIVE	12
     95   1.1      cgd 	{ "_dk_ndrive" },
     96   1.1      cgd #define	X_KMEMSTAT	13
     97   1.1      cgd 	{ "_kmemstats" },
     98   1.1      cgd #define	X_KMEMBUCKETS	14
     99   1.1      cgd 	{ "_bucket" },
    100   1.1      cgd #ifdef notdef
    101  1.12      cgd #define	X_DEFICIT	14
    102   1.1      cgd 	{ "_deficit" },
    103  1.12      cgd #define	X_FORKSTAT	15
    104   1.1      cgd 	{ "_forkstat" },
    105  1.12      cgd #define X_REC		16
    106   1.1      cgd 	{ "_rectime" },
    107  1.12      cgd #define X_PGIN		17
    108   1.1      cgd 	{ "_pgintime" },
    109  1.12      cgd #define	X_XSTATS	18
    110   1.1      cgd 	{ "_xstats" },
    111  1.12      cgd #define X_END		18
    112   1.1      cgd #else
    113  1.12      cgd #define X_END		14
    114   1.1      cgd #endif
    115   1.1      cgd #ifdef hp300
    116   1.1      cgd #define	X_HPDINIT	(X_END+1)
    117   1.1      cgd 	{ "_hp_dinit" },
    118   1.1      cgd #endif
    119   1.1      cgd #ifdef tahoe
    120   1.1      cgd #define	X_VBDINIT	(X_END+1)
    121   1.1      cgd 	{ "_vbdinit" },
    122   1.1      cgd #define	X_CKEYSTATS	(X_END+2)
    123   1.1      cgd 	{ "_ckeystats" },
    124   1.1      cgd #define	X_DKEYSTATS	(X_END+3)
    125   1.1      cgd 	{ "_dkeystats" },
    126   1.1      cgd #endif
    127   1.1      cgd #ifdef vax
    128   1.1      cgd #define X_MBDINIT	(X_END+1)
    129   1.1      cgd 	{ "_mbdinit" },
    130   1.1      cgd #define X_UBDINIT	(X_END+2)
    131   1.1      cgd 	{ "_ubdinit" },
    132   1.1      cgd #endif
    133   1.2  deraadt #ifdef i386
    134  1.11      cgd #define	X_ISADEVTAB	(X_END+1)
    135  1.11      cgd 	{ "_isa_devtab" },
    136   1.2  deraadt #endif i386
    137   1.1      cgd 	{ "" },
    138   1.1      cgd };
    139   1.1      cgd 
    140   1.1      cgd struct _disk {
    141   1.1      cgd 	long time[CPUSTATES];
    142   1.1      cgd 	long *xfer;
    143   1.1      cgd } cur, last;
    144   1.1      cgd 
    145  1.12      cgd struct	vmmeter cnt, ocnt;
    146   1.1      cgd char	*vmunix = _PATH_UNIX;
    147   1.1      cgd char	**dr_name;
    148   1.1      cgd int	*dr_select, dk_ndrive, ndrives;
    149  1.10      cgd #ifdef notdef
    150   1.1      cgd       /* to make up for statistics that don't get updated */
    151   1.1      cgd int	size, free_count, active_count, inactive, wired;
    152   1.1      cgd #endif
    153   1.1      cgd 
    154   1.1      cgd int	winlines = 20;
    155   1.1      cgd 
    156   1.1      cgd #define	FORKSTAT	0x01
    157   1.1      cgd #define	INTRSTAT	0x02
    158   1.1      cgd #define	MEMSTAT		0x04
    159   1.1      cgd #define	SUMSTAT		0x08
    160   1.1      cgd #define	TIMESTAT	0x10
    161   1.1      cgd #define	VMSTAT		0x20
    162   1.1      cgd 
    163   1.1      cgd #include "names.c"			/* disk names -- machine dependent */
    164   1.1      cgd 
    165  1.12      cgd void	cpustats(), dkstats(), dointr(), domem(), docnt();
    166   1.1      cgd void	dovmstat(), kread(), usage();
    167   1.1      cgd #ifdef notdef
    168   1.1      cgd void	dotimes(), doforkst();
    169   1.1      cgd #endif
    170   1.1      cgd 
    171   1.1      cgd main(argc, argv)
    172   1.1      cgd 	register int argc;
    173   1.1      cgd 	register char **argv;
    174   1.1      cgd {
    175   1.1      cgd 	extern int optind;
    176   1.1      cgd 	extern char *optarg;
    177   1.1      cgd 	register int c, todo;
    178   1.1      cgd 	u_int interval;
    179   1.1      cgd 	int reps;
    180   1.1      cgd 	char *kmem;
    181   1.1      cgd 
    182   1.1      cgd 	kmem = NULL;
    183   1.1      cgd 	interval = reps = todo = 0;
    184   1.1      cgd 	while ((c = getopt(argc, argv, "c:fiM:mN:stw:")) != EOF) {
    185   1.1      cgd 		switch (c) {
    186   1.1      cgd 		case 'c':
    187   1.1      cgd 			reps = atoi(optarg);
    188   1.1      cgd 			break;
    189   1.1      cgd #ifndef notdef
    190   1.1      cgd 		case 'f':
    191   1.1      cgd 			todo |= FORKSTAT;
    192   1.1      cgd 			break;
    193   1.1      cgd #endif
    194   1.1      cgd 		case 'i':
    195   1.1      cgd 			todo |= INTRSTAT;
    196   1.1      cgd 			break;
    197   1.1      cgd 		case 'M':
    198   1.1      cgd 			kmem = optarg;
    199   1.1      cgd 			break;
    200   1.1      cgd 		case 'm':
    201   1.1      cgd 			todo |= MEMSTAT;
    202   1.1      cgd 			break;
    203   1.1      cgd 		case 'N':
    204   1.1      cgd 			vmunix = optarg;
    205   1.1      cgd 			break;
    206   1.1      cgd 		case 's':
    207   1.1      cgd 			todo |= SUMSTAT;
    208   1.1      cgd 			break;
    209   1.1      cgd #ifndef notdef
    210   1.1      cgd 		case 't':
    211   1.1      cgd 			todo |= TIMESTAT;
    212   1.1      cgd 			break;
    213   1.1      cgd #endif
    214   1.1      cgd 		case 'w':
    215   1.1      cgd 			interval = atoi(optarg);
    216   1.1      cgd 			break;
    217   1.1      cgd 		case '?':
    218   1.1      cgd 		default:
    219   1.1      cgd 			usage();
    220   1.1      cgd 		}
    221   1.1      cgd 	}
    222   1.1      cgd 	argc -= optind;
    223   1.1      cgd 	argv += optind;
    224   1.1      cgd 
    225   1.1      cgd 	if (todo == 0)
    226   1.1      cgd 		todo = VMSTAT;
    227   1.1      cgd 
    228   1.1      cgd 	if (kvm_openfiles(vmunix, kmem, NULL) < 0) {
    229   1.1      cgd 		(void)fprintf(stderr,
    230   1.1      cgd 		    "vmstat: kvm_openfiles: %s\n", kvm_geterr());
    231   1.1      cgd 		exit(1);
    232   1.1      cgd 	}
    233   1.1      cgd 
    234   1.1      cgd 	if ((c = kvm_nlist(nl)) != 0) {
    235   1.1      cgd 		if (c > 0) {
    236   1.1      cgd 			(void)fprintf(stderr,
    237   1.1      cgd 			    "vmstat: undefined symbols in %s:", vmunix);
    238   1.1      cgd 			for (c = 0; c < sizeof(nl)/sizeof(nl[0]); c++)
    239   1.1      cgd 				if (nl[c].n_type == 0)
    240   1.1      cgd 					fprintf(stderr, " %s", nl[c].n_name);
    241   1.1      cgd 			(void)fputc('\n', stderr);
    242   1.1      cgd 		} else
    243   1.1      cgd 			(void)fprintf(stderr, "vmstat: kvm_nlist: %s\n",
    244   1.1      cgd 			    kvm_geterr());
    245   1.1      cgd 		exit(1);
    246   1.1      cgd 	}
    247   1.1      cgd 
    248   1.1      cgd 	if (todo & VMSTAT) {
    249   1.1      cgd 		char **getdrivedata();
    250   1.1      cgd 		struct winsize winsize;
    251   1.1      cgd 
    252   1.1      cgd 		argv = getdrivedata(argv);
    253   1.1      cgd 		winsize.ws_row = 0;
    254   1.1      cgd 		(void) ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize);
    255   1.1      cgd 		if (winsize.ws_row > 0)
    256   1.1      cgd 			winlines = winsize.ws_row;
    257   1.1      cgd 
    258   1.1      cgd 	}
    259   1.1      cgd 
    260   1.1      cgd #define	BACKWARD_COMPATIBILITY
    261   1.1      cgd #ifdef	BACKWARD_COMPATIBILITY
    262   1.1      cgd 	if (*argv) {
    263   1.1      cgd 		interval = atoi(*argv);
    264   1.1      cgd 		if (*++argv)
    265   1.1      cgd 			reps = atoi(*argv);
    266   1.1      cgd 	}
    267   1.1      cgd #endif
    268   1.1      cgd 
    269   1.1      cgd 	if (interval) {
    270   1.1      cgd 		if (!reps)
    271   1.1      cgd 			reps = -1;
    272   1.1      cgd 	} else if (reps)
    273   1.1      cgd 		interval = 1;
    274   1.1      cgd 
    275   1.1      cgd #ifdef notdef
    276   1.1      cgd 	if (todo & FORKSTAT)
    277   1.1      cgd 		doforkst();
    278   1.1      cgd #endif
    279   1.1      cgd 	if (todo & MEMSTAT)
    280   1.1      cgd 		domem();
    281   1.1      cgd 	if (todo & SUMSTAT)
    282  1.12      cgd 		docnt();
    283   1.1      cgd #ifdef notdef
    284   1.1      cgd 	if (todo & TIMESTAT)
    285   1.1      cgd 		dotimes();
    286   1.1      cgd #endif
    287   1.1      cgd 	if (todo & INTRSTAT)
    288   1.1      cgd 		dointr();
    289   1.1      cgd 	if (todo & VMSTAT)
    290   1.1      cgd 		dovmstat(interval, reps);
    291   1.1      cgd 	exit(0);
    292   1.1      cgd }
    293   1.1      cgd 
    294   1.1      cgd char **
    295   1.1      cgd getdrivedata(argv)
    296   1.1      cgd 	char **argv;
    297   1.1      cgd {
    298   1.1      cgd 	register int i;
    299   1.1      cgd 	register char **cp;
    300   1.1      cgd 	char buf[30];
    301   1.1      cgd 
    302   1.1      cgd 	kread(X_DK_NDRIVE, &dk_ndrive, sizeof(dk_ndrive));
    303   1.1      cgd 	if (dk_ndrive <= 0) {
    304   1.1      cgd 		(void)fprintf(stderr, "vmstat: dk_ndrive %d\n", dk_ndrive);
    305   1.1      cgd 		exit(1);
    306   1.1      cgd 	}
    307   1.1      cgd 	dr_select = calloc((size_t)dk_ndrive, sizeof(int));
    308   1.1      cgd 	dr_name = calloc((size_t)dk_ndrive, sizeof(char *));
    309   1.1      cgd 	for (i = 0; i < dk_ndrive; i++)
    310   1.1      cgd 		dr_name[i] = NULL;
    311   1.1      cgd 	cur.xfer = calloc((size_t)dk_ndrive, sizeof(long));
    312   1.1      cgd 	last.xfer = calloc((size_t)dk_ndrive, sizeof(long));
    313   1.1      cgd 	read_names();
    314   1.1      cgd 	for (i = 0; i < dk_ndrive; i++)
    315   1.1      cgd 		if (dr_name[i] == NULL) {
    316   1.1      cgd 			(void)sprintf(buf, "??%d", i);
    317   1.1      cgd 			dr_name[i] = strdup(buf);
    318   1.1      cgd 		}
    319   1.1      cgd 
    320   1.1      cgd 	/*
    321   1.1      cgd 	 * Choose drives to be displayed.  Priority goes to (in order) drives
    322   1.1      cgd 	 * supplied as arguments, default drives.  If everything isn't filled
    323   1.1      cgd 	 * in and there are drives not taken care of, display the first few
    324   1.1      cgd 	 * that fit.
    325   1.1      cgd 	 */
    326   1.1      cgd #define BACKWARD_COMPATIBILITY
    327   1.1      cgd 	for (ndrives = 0; *argv; ++argv) {
    328   1.1      cgd #ifdef	BACKWARD_COMPATIBILITY
    329   1.1      cgd 		if (isdigit(**argv))
    330   1.1      cgd 			break;
    331   1.1      cgd #endif
    332   1.1      cgd 		for (i = 0; i < dk_ndrive; i++) {
    333   1.1      cgd 			if (strcmp(dr_name[i], *argv))
    334   1.1      cgd 				continue;
    335   1.1      cgd 			dr_select[i] = 1;
    336   1.1      cgd 			++ndrives;
    337   1.1      cgd 			break;
    338   1.1      cgd 		}
    339   1.1      cgd 	}
    340   1.1      cgd 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
    341   1.1      cgd 		if (dr_select[i])
    342   1.1      cgd 			continue;
    343   1.1      cgd 		for (cp = defdrives; *cp; cp++)
    344   1.1      cgd 			if (strcmp(dr_name[i], *cp) == 0) {
    345   1.1      cgd 				dr_select[i] = 1;
    346   1.1      cgd 				++ndrives;
    347   1.1      cgd 				break;
    348   1.1      cgd 			}
    349   1.1      cgd 	}
    350   1.1      cgd 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
    351   1.1      cgd 		if (dr_select[i])
    352   1.1      cgd 			continue;
    353   1.1      cgd 		dr_select[i] = 1;
    354   1.1      cgd 		++ndrives;
    355   1.1      cgd 	}
    356   1.1      cgd 	return(argv);
    357   1.1      cgd }
    358   1.1      cgd 
    359   1.1      cgd long
    360   1.1      cgd getuptime()
    361   1.1      cgd {
    362   1.1      cgd 	static time_t now, boottime;
    363   1.1      cgd 	time_t uptime;
    364   1.1      cgd 
    365   1.1      cgd 	if (boottime == 0)
    366   1.1      cgd 		kread(X_BOOTTIME, &boottime, sizeof(boottime));
    367   1.1      cgd 	(void)time(&now);
    368   1.1      cgd 	uptime = now - boottime;
    369   1.1      cgd 	if (uptime <= 0 || uptime > 60*60*24*365*10) {
    370   1.1      cgd 		(void)fprintf(stderr,
    371   1.1      cgd 		    "vmstat: time makes no sense; namelist must be wrong.\n");
    372   1.1      cgd 		exit(1);
    373   1.1      cgd 	}
    374   1.1      cgd 	return(uptime);
    375   1.1      cgd }
    376   1.1      cgd 
    377   1.1      cgd int	hz, hdrcnt;
    378   1.1      cgd 
    379   1.1      cgd void
    380   1.1      cgd dovmstat(interval, reps)
    381   1.1      cgd 	u_int interval;
    382   1.1      cgd 	int reps;
    383   1.1      cgd {
    384   1.1      cgd 	struct vmtotal total;
    385   1.1      cgd 	time_t uptime, halfuptime;
    386   1.1      cgd 	void needhdr();
    387   1.1      cgd #ifndef notdef
    388   1.1      cgd 	int deficit;
    389   1.1      cgd #endif
    390   1.1      cgd 
    391   1.1      cgd 	uptime = getuptime();
    392   1.1      cgd 	halfuptime = uptime / 2;
    393   1.1      cgd 	(void)signal(SIGCONT, needhdr);
    394   1.1      cgd 
    395   1.1      cgd 	if (nl[X_PHZ].n_type != 0 && nl[X_PHZ].n_value != 0)
    396   1.1      cgd 		kread(X_PHZ, &hz, sizeof(hz));
    397   1.1      cgd 	if (!hz)
    398   1.1      cgd 		kread(X_HZ, &hz, sizeof(hz));
    399   1.1      cgd 
    400   1.1      cgd 	for (hdrcnt = 1;;) {
    401   1.1      cgd 		if (!--hdrcnt)
    402   1.1      cgd 			printhdr();
    403   1.1      cgd 		kread(X_CPTIME, cur.time, sizeof(cur.time));
    404   1.1      cgd 		kread(X_DKXFER, cur.xfer, sizeof(*cur.xfer * dk_ndrive));
    405   1.1      cgd 		kread(X_TOTAL, &total, sizeof(total));
    406  1.12      cgd 		kread(X_CNT, &cnt, sizeof(cnt));
    407   1.1      cgd #ifdef notdef
    408   1.1      cgd 		kread(X_DEFICIT, &deficit, sizeof(deficit));
    409   1.1      cgd #endif
    410   1.1      cgd 		(void)printf("%2d %1d %1d ",
    411   1.1      cgd 		    total.t_rq, total.t_dw + total.t_pw, total.t_sw);
    412   1.1      cgd #define pgtok(a) ((a)*NBPG >> 10)
    413   1.1      cgd #define	rate(x)	(((x) + halfuptime) / uptime)	/* round */
    414   1.1      cgd 		(void)printf("%5ld %5ld ",
    415  1.10      cgd #ifdef __NetBSD__
    416  1.12      cgd 		    pgtok(cnt.v_active_count), pgtok(cnt.v_free_count));
    417   1.1      cgd #else
    418   1.1      cgd 		    pgtok(total.t_avm), pgtok(total.t_free));
    419   1.1      cgd #endif
    420   1.1      cgd #ifdef NEWVM
    421  1.12      cgd 		(void)printf("%4lu ", rate(cnt.v_vm_faults - ocnt.v_vm_faults));
    422   1.1      cgd 		(void)printf("%3lu ",
    423  1.12      cgd 		    rate(cnt.v_reactivated - ocnt.v_reactivated));
    424  1.12      cgd 		(void)printf("%3lu ", rate(cnt.v_pageins - ocnt.v_pageins));
    425   1.1      cgd 		(void)printf("%3lu %3lu ",
    426  1.12      cgd 		    rate(cnt.v_pageouts - ocnt.v_pageouts), 0);
    427   1.1      cgd #else
    428   1.1      cgd 		(void)printf("%3lu %2lu ",
    429  1.12      cgd 		    rate(cnt.v_pgrec - (cnt.v_xsfrec+cnt.v_xifrec) -
    430  1.12      cgd 		    (ocnt.v_pgrec - (ocnt.v_xsfrec+ocnt.v_xifrec))),
    431  1.12      cgd 		    rate(cnt.v_xsfrec + cnt.v_xifrec -
    432  1.12      cgd 		    ocnt.v_xsfrec - ocnt.v_xifrec));
    433   1.1      cgd 		(void)printf("%3lu ",
    434  1.12      cgd 		    rate(pgtok(cnt.v_pgpgin - ocnt.v_pgpgin)));
    435   1.1      cgd 		(void)printf("%3lu %3lu ",
    436  1.12      cgd 		    rate(pgtok(cnt.v_pgpgout - ocnt.v_pgpgout)),
    437  1.12      cgd 		    rate(pgtok(cnt.v_dfree - ocnt.v_dfree)));
    438   1.1      cgd 		(void)printf("%3d ", pgtok(deficit));
    439   1.1      cgd #endif
    440  1.12      cgd 		(void)printf("%3lu ", rate(cnt.v_scan - ocnt.v_scan));
    441   1.1      cgd 		dkstats();
    442   1.1      cgd 		(void)printf("%4lu %4lu %3lu ",
    443  1.12      cgd 		    rate(cnt.v_intr - ocnt.v_intr),
    444  1.12      cgd 		    rate(cnt.v_syscall - ocnt.v_syscall),
    445  1.12      cgd 		    rate(cnt.v_swtch - ocnt.v_swtch));
    446   1.1      cgd 		cpustats();
    447   1.1      cgd 		(void)printf("\n");
    448   1.1      cgd 		(void)fflush(stdout);
    449   1.1      cgd 		if (reps >= 0 && --reps <= 0)
    450   1.1      cgd 			break;
    451  1.12      cgd 		ocnt = cnt;
    452  1.12      cgd 		ocnt = cnt;
    453   1.1      cgd 		uptime = interval;
    454   1.1      cgd 		/*
    455   1.1      cgd 		 * We round upward to avoid losing low-frequency events
    456   1.1      cgd 		 * (i.e., >= 1 per interval but < 1 per second).
    457   1.1      cgd 		 */
    458   1.1      cgd 		halfuptime = (uptime + 1) / 2;
    459   1.1      cgd 		(void)sleep(interval);
    460   1.1      cgd 	}
    461   1.1      cgd }
    462   1.1      cgd 
    463   1.1      cgd printhdr()
    464   1.1      cgd {
    465   1.1      cgd 	register int i;
    466   1.1      cgd 
    467   1.1      cgd 	(void)printf(" procs   memory     page%*s", 20, "");
    468   1.1      cgd 	if (ndrives > 1)
    469   1.1      cgd 		(void)printf("disks %*s  faults      cpu\n",
    470   1.1      cgd 		   ndrives * 3 - 6, "");
    471   1.1      cgd 	else
    472   1.1      cgd 		(void)printf("%*s  faults      cpu\n", ndrives * 3, "");
    473   1.1      cgd #ifndef NEWVM
    474   1.1      cgd 	(void)printf(" r b w   avm   fre  re at  pi  po  fr  de  sr ");
    475   1.1      cgd #else
    476   1.1      cgd 	(void)printf(" r b w   avm   fre  flt  re  pi  po  fr  sr ");
    477   1.1      cgd #endif
    478   1.1      cgd 	for (i = 0; i < dk_ndrive; i++)
    479   1.1      cgd 		if (dr_select[i])
    480   1.1      cgd 			(void)printf("%c%c ", dr_name[i][0],
    481   1.1      cgd 			    dr_name[i][strlen(dr_name[i]) - 1]);
    482   1.1      cgd 	(void)printf("  in   sy  cs us sy id\n");
    483   1.1      cgd 	hdrcnt = winlines - 2;
    484   1.1      cgd }
    485   1.1      cgd 
    486   1.1      cgd /*
    487   1.1      cgd  * Force a header to be prepended to the next output.
    488   1.1      cgd  */
    489   1.1      cgd void
    490   1.1      cgd needhdr()
    491   1.1      cgd {
    492   1.1      cgd 
    493   1.1      cgd 	hdrcnt = 1;
    494   1.1      cgd }
    495   1.1      cgd 
    496   1.1      cgd #ifdef notdef
    497   1.1      cgd void
    498   1.1      cgd dotimes()
    499   1.1      cgd {
    500   1.1      cgd 	u_int pgintime, rectime;
    501   1.1      cgd 
    502   1.1      cgd 	kread(X_REC, &rectime, sizeof(rectime));
    503   1.1      cgd 	kread(X_PGIN, &pgintime, sizeof(pgintime));
    504  1.12      cgd 	kread(X_SUM, &cnt, sizeof(cnt));
    505   1.1      cgd 	(void)printf("%u reclaims, %u total time (usec)\n",
    506  1.12      cgd 	    cnt.v_pgrec, rectime);
    507  1.12      cgd 	(void)printf("average: %u usec / reclaim\n", rectime / cnt.v_pgrec);
    508   1.1      cgd 	(void)printf("\n");
    509   1.1      cgd 	(void)printf("%u page ins, %u total time (msec)\n",
    510  1.12      cgd 	    cnt.v_pgin, pgintime / 10);
    511   1.1      cgd 	(void)printf("average: %8.1f msec / page in\n",
    512  1.12      cgd 	    pgintime / (cnt.v_pgin * 10.0));
    513   1.1      cgd }
    514   1.1      cgd #endif
    515   1.1      cgd 
    516   1.1      cgd pct(top, bot)
    517   1.1      cgd 	long top, bot;
    518   1.1      cgd {
    519   1.1      cgd 	if (bot == 0)
    520   1.1      cgd 		return(0);
    521   1.1      cgd 	return((top * 100) / bot);
    522   1.1      cgd }
    523   1.1      cgd 
    524   1.1      cgd #define	PCT(top, bot) pct((long)(top), (long)(bot))
    525   1.1      cgd 
    526   1.1      cgd #if defined(tahoe)
    527   1.1      cgd #include <machine/cpu.h>
    528   1.1      cgd #endif
    529   1.1      cgd 
    530   1.1      cgd void
    531  1.12      cgd docnt()
    532   1.1      cgd {
    533   1.1      cgd 	struct nchstats nchstats;
    534   1.1      cgd #ifndef NEWVM
    535   1.1      cgd 	struct xstats xstats;
    536   1.1      cgd #endif
    537   1.1      cgd 	long nchtotal;
    538   1.1      cgd #if defined(tahoe)
    539   1.1      cgd 	struct keystats keystats;
    540   1.1      cgd #endif
    541   1.1      cgd 
    542   1.1      cgd #ifdef NEWVM
    543  1.12      cgd 	kread(X_CNT, &cnt, sizeof(cnt));
    544   1.1      cgd #else
    545  1.12      cgd 	(void)printf("%9u swap ins\n", cnt.v_swpin);
    546  1.12      cgd 	(void)printf("%9u swap outs\n", cnt.v_swpout);
    547  1.12      cgd 	(void)printf("%9u pages swapped in\n", cnt.v_pswpin / CLSIZE);
    548  1.12      cgd 	(void)printf("%9u pages swapped out\n", cnt.v_pswpout / CLSIZE);
    549  1.12      cgd 	(void)printf("%9u total address trans. faults taken\n", cnt.v_faults);
    550  1.12      cgd 	(void)printf("%9u page ins\n", cnt.v_pgin);
    551  1.12      cgd 	(void)printf("%9u page outs\n", cnt.v_pgout);
    552  1.12      cgd 	(void)printf("%9u pages paged in\n", cnt.v_pgpgin);
    553  1.12      cgd 	(void)printf("%9u pages paged out\n", cnt.v_pgpgout);
    554  1.12      cgd 	(void)printf("%9u sequential process pages freed\n", cnt.v_seqfree);
    555  1.12      cgd 	(void)printf("%9u total reclaims (%d%% fast)\n", cnt.v_pgrec,
    556  1.12      cgd 	    PCT(cnt.v_fastpgrec, cnt.v_pgrec));
    557  1.12      cgd 	(void)printf("%9u reclaims from free list\n", cnt.v_pgfrec);
    558  1.12      cgd 	(void)printf("%9u intransit blocking page faults\n", cnt.v_intrans);
    559  1.12      cgd 	(void)printf("%9u zero fill pages created\n", cnt.v_nzfod / CLSIZE);
    560  1.12      cgd 	(void)printf("%9u zero fill page faults\n", cnt.v_zfod / CLSIZE);
    561   1.1      cgd 	(void)printf("%9u executable fill pages created\n",
    562  1.12      cgd 	    cnt.v_nexfod / CLSIZE);
    563   1.1      cgd 	(void)printf("%9u executable fill page faults\n",
    564  1.12      cgd 	    cnt.v_exfod / CLSIZE);
    565   1.1      cgd 	(void)printf("%9u swap text pages found in free list\n",
    566  1.12      cgd 	    cnt.v_xsfrec);
    567   1.1      cgd 	(void)printf("%9u inode text pages found in free list\n",
    568  1.12      cgd 	    cnt.v_xifrec);
    569  1.12      cgd 	(void)printf("%9u file fill pages created\n", cnt.v_nvrfod / CLSIZE);
    570  1.12      cgd 	(void)printf("%9u file fill page faults\n", cnt.v_vrfod / CLSIZE);
    571  1.12      cgd 	(void)printf("%9u pages examined by the clock daemon\n", cnt.v_scan);
    572  1.12      cgd 	(void)printf("%9u revolutions of the clock hand\n", cnt.v_rev);
    573   1.1      cgd 	(void)printf("%9u pages freed by the clock daemon\n",
    574  1.12      cgd 	    cnt.v_dfree / CLSIZE);
    575   1.1      cgd #endif
    576  1.12      cgd 	(void)printf("%9u cpu context switches\n", cnt.v_swtch);
    577  1.12      cgd 	(void)printf("%9u device interrupts\n", cnt.v_intr);
    578  1.12      cgd 	(void)printf("%9u software interrupts\n", cnt.v_soft);
    579   1.1      cgd #ifdef vax
    580  1.12      cgd 	(void)printf("%9u pseudo-dma dz interrupts\n", cnt.v_pdma);
    581   1.1      cgd #endif
    582  1.12      cgd 	(void)printf("%9u traps\n", cnt.v_trap);
    583  1.12      cgd 	(void)printf("%9u system calls\n", cnt.v_syscall);
    584   1.1      cgd #ifdef NEWVM
    585  1.12      cgd 	(void)printf("%9u bytes per page\n", cnt.v_page_size);
    586  1.12      cgd 	(void)printf("%9u pages free\n", cnt.v_free_count);
    587  1.12      cgd 	(void)printf("%9u pages active\n", cnt.v_active_count);
    588  1.12      cgd 	(void)printf("%9u pages inactive\n", cnt.v_inactive_count);
    589  1.12      cgd 	(void)printf("%9u pages wired down\n", cnt.v_wire_count);
    590  1.12      cgd /*	(void)printf("%9u zero fill pages created\n", cnt.v_nzfod / CLSIZE);*/
    591  1.12      cgd 	(void)printf("%9u zero fill page faults\n", cnt.v_zfod / CLSIZE);
    592  1.12      cgd 	(void)printf("%9u pages reactivated\n", cnt.v_reactivated);
    593  1.12      cgd 	(void)printf("%9u pageins\n", cnt.v_pageins);
    594  1.12      cgd 	(void)printf("%9u pageouts\n", cnt.v_pageouts);
    595  1.12      cgd 	(void)printf("%9u VM faults\n", cnt.v_vm_faults);
    596  1.12      cgd 	(void)printf("%9u copy-on-write faults\n", cnt.v_cow_faults);
    597  1.12      cgd 	(void)printf("%9u VM object cache lookups\n", cnt.v_lookups);
    598  1.12      cgd 	(void)printf("%9u VM object hits\n", cnt.v_hits);
    599   1.1      cgd #endif
    600   1.1      cgd 
    601   1.1      cgd 	kread(X_NCHSTATS, &nchstats, sizeof(nchstats));
    602   1.1      cgd 	nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits +
    603   1.1      cgd 	    nchstats.ncs_badhits + nchstats.ncs_falsehits +
    604   1.1      cgd 	    nchstats.ncs_miss + nchstats.ncs_long;
    605   1.1      cgd 	(void)printf("%9ld total name lookups\n", nchtotal);
    606   1.1      cgd 	(void)printf(
    607   1.1      cgd 	    "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
    608   1.1      cgd 	    "", PCT(nchstats.ncs_goodhits, nchtotal),
    609   1.1      cgd 	    PCT(nchstats.ncs_neghits, nchtotal),
    610   1.1      cgd 	    PCT(nchstats.ncs_pass2, nchtotal));
    611   1.1      cgd 	(void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "",
    612   1.1      cgd 	    PCT(nchstats.ncs_badhits, nchtotal),
    613   1.1      cgd 	    PCT(nchstats.ncs_falsehits, nchtotal),
    614   1.1      cgd 	    PCT(nchstats.ncs_long, nchtotal));
    615   1.1      cgd #ifndef NEWVM
    616   1.1      cgd 	kread(X_XSTATS, &xstats, sizeof(xstats));
    617   1.1      cgd 	(void)printf("%9lu total calls to xalloc (cache hits %d%%)\n",
    618   1.1      cgd 	    xstats.alloc, PCT(xstats.alloc_cachehit, xstats.alloc));
    619   1.1      cgd 	(void)printf("%9s sticky %lu flushed %lu unused %lu\n", "",
    620   1.1      cgd 	    xstats.alloc_inuse, xstats.alloc_cacheflush, xstats.alloc_unused);
    621   1.1      cgd 	(void)printf("%9lu total calls to xfree", xstats.free);
    622   1.1      cgd 	(void)printf(" (sticky %lu cached %lu swapped %lu)\n",
    623   1.1      cgd 	    xstats.free_inuse, xstats.free_cache, xstats.free_cacheswap);
    624   1.1      cgd #endif
    625   1.1      cgd #if defined(tahoe)
    626   1.1      cgd 	kread(X_CKEYSTATS, &keystats, sizeof(keystats));
    627   1.1      cgd 	(void)printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
    628   1.1      cgd 	    keystats.ks_allocs, "code cache keys allocated",
    629   1.1      cgd 	    PCT(keystats.ks_allocfree, keystats.ks_allocs),
    630   1.1      cgd 	    PCT(keystats.ks_norefs, keystats.ks_allocs),
    631   1.1      cgd 	    PCT(keystats.ks_taken, keystats.ks_allocs),
    632   1.1      cgd 	    PCT(keystats.ks_shared, keystats.ks_allocs));
    633   1.1      cgd 	kread(X_DKEYSTATS, &keystats, sizeof(keystats));
    634   1.1      cgd 	(void)printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
    635   1.1      cgd 	    keystats.ks_allocs, "data cache keys allocated",
    636   1.1      cgd 	    PCT(keystats.ks_allocfree, keystats.ks_allocs),
    637   1.1      cgd 	    PCT(keystats.ks_norefs, keystats.ks_allocs),
    638   1.1      cgd 	    PCT(keystats.ks_taken, keystats.ks_allocs),
    639   1.1      cgd 	    PCT(keystats.ks_shared, keystats.ks_allocs));
    640   1.1      cgd #endif
    641   1.1      cgd }
    642   1.1      cgd 
    643   1.1      cgd #ifdef notdef
    644   1.1      cgd void
    645   1.1      cgd doforkst()
    646   1.1      cgd {
    647   1.1      cgd 	struct forkstat fks;
    648   1.1      cgd 
    649   1.1      cgd 	kread(X_FORKSTAT, &fks, sizeof(struct forkstat));
    650   1.1      cgd 	(void)printf("%d forks, %d pages, average %.2f\n",
    651   1.1      cgd 	    fks.cntfork, fks.sizfork, (double)fks.sizfork / fks.cntfork);
    652   1.1      cgd 	(void)printf("%d vforks, %d pages, average %.2f\n",
    653   1.1      cgd 	    fks.cntvfork, fks.sizvfork, (double)fks.sizvfork / fks.cntvfork);
    654   1.1      cgd }
    655   1.1      cgd #endif
    656   1.1      cgd 
    657   1.1      cgd void
    658   1.1      cgd dkstats()
    659   1.1      cgd {
    660   1.1      cgd 	register int dn, state;
    661   1.1      cgd 	double etime;
    662   1.1      cgd 	long tmp;
    663   1.1      cgd 
    664   1.1      cgd 	for (dn = 0; dn < dk_ndrive; ++dn) {
    665   1.1      cgd 		tmp = cur.xfer[dn];
    666   1.1      cgd 		cur.xfer[dn] -= last.xfer[dn];
    667   1.1      cgd 		last.xfer[dn] = tmp;
    668   1.1      cgd 	}
    669   1.1      cgd 	etime = 0;
    670   1.1      cgd 	for (state = 0; state < CPUSTATES; ++state) {
    671   1.1      cgd 		tmp = cur.time[state];
    672   1.1      cgd 		cur.time[state] -= last.time[state];
    673   1.1      cgd 		last.time[state] = tmp;
    674   1.1      cgd 		etime += cur.time[state];
    675   1.1      cgd 	}
    676   1.1      cgd 	if (etime == 0)
    677   1.1      cgd 		etime = 1;
    678   1.1      cgd 	etime /= hz;
    679   1.1      cgd 	for (dn = 0; dn < dk_ndrive; ++dn) {
    680   1.1      cgd 		if (!dr_select[dn])
    681   1.1      cgd 			continue;
    682   1.1      cgd 		(void)printf("%2.0f ", cur.xfer[dn] / etime);
    683   1.1      cgd 	}
    684   1.1      cgd }
    685   1.1      cgd 
    686   1.1      cgd void
    687   1.1      cgd cpustats()
    688   1.1      cgd {
    689   1.1      cgd 	register int state;
    690   1.1      cgd 	double pct, total;
    691   1.1      cgd 
    692   1.1      cgd 	total = 0;
    693   1.1      cgd 	for (state = 0; state < CPUSTATES; ++state)
    694   1.1      cgd 		total += cur.time[state];
    695   1.1      cgd 	if (total)
    696   1.1      cgd 		pct = 100 / total;
    697   1.1      cgd 	else
    698   1.1      cgd 		pct = 0;
    699   1.1      cgd 	(void)printf("%2.0f ",				/* user + nice */
    700   1.1      cgd 	    (cur.time[0] + cur.time[1]) * pct);
    701   1.1      cgd 	(void)printf("%2.0f ", cur.time[2] * pct);	/* system */
    702   1.1      cgd 	(void)printf("%2.0f", cur.time[3] * pct);	/* idle */
    703   1.1      cgd }
    704   1.1      cgd 
    705   1.1      cgd void
    706   1.1      cgd dointr()
    707   1.1      cgd {
    708   1.5      cgd 	register unsigned long *intrcnt, inttotal, uptime;
    709   1.1      cgd 	register int nintr, inamlen;
    710   1.1      cgd 	register char *intrname;
    711   1.1      cgd 
    712   1.1      cgd 	uptime = getuptime();
    713   1.1      cgd 	nintr = nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value;
    714   1.1      cgd 	inamlen = nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value;
    715   1.1      cgd 	intrcnt = malloc((size_t)nintr);
    716   1.1      cgd 	intrname = malloc((size_t)inamlen);
    717   1.1      cgd 	if (intrcnt == NULL || intrname == NULL) {
    718   1.1      cgd 		(void)fprintf(stderr, "vmstat: %s.\n", strerror(errno));
    719   1.1      cgd 		exit(1);
    720   1.1      cgd 	}
    721   1.1      cgd 	kread(X_INTRCNT, intrcnt, (size_t)nintr);
    722   1.1      cgd 	kread(X_INTRNAMES, intrname, (size_t)inamlen);
    723   1.5      cgd 	(void)printf("%-12s %10s %8s\n", "interrupt", "count", "rate");
    724   1.1      cgd 	inttotal = 0;
    725   1.1      cgd 	nintr /= sizeof(long);
    726   1.1      cgd 	while (--nintr >= 0) {
    727   1.1      cgd 		if (*intrcnt)
    728   1.5      cgd 			(void)printf("%-12s %10lu %8lu\n", intrname,
    729   1.1      cgd 			    *intrcnt, *intrcnt / uptime);
    730   1.1      cgd 		intrname += strlen(intrname) + 1;
    731   1.1      cgd 		inttotal += *intrcnt++;
    732   1.1      cgd 	}
    733   1.5      cgd 	(void)printf("%-12s %10lu %8lu\n", "Total", inttotal, inttotal / uptime);
    734   1.1      cgd }
    735   1.1      cgd 
    736   1.1      cgd /*
    737   1.1      cgd  * These names are defined in <sys/malloc.h>.
    738   1.1      cgd  */
    739   1.1      cgd char *kmemnames[] = INITKMEMNAMES;
    740   1.1      cgd 
    741   1.1      cgd void
    742   1.1      cgd domem()
    743   1.1      cgd {
    744   1.1      cgd 	register struct kmembuckets *kp;
    745   1.1      cgd 	register struct kmemstats *ks;
    746   1.1      cgd 	register int i;
    747   1.1      cgd 	int size;
    748   1.9  deraadt 	long totuse = 0, totfree = 0, totreq = 0, totwaste = 0;
    749   1.4      cgd 	struct kmemstats kmemstats[M_LAST + 1];
    750   1.1      cgd 	struct kmembuckets buckets[MINBUCKET + 16];
    751   1.1      cgd 
    752   1.1      cgd 	kread(X_KMEMBUCKETS, buckets, sizeof(buckets));
    753   1.1      cgd 	(void)printf("Memory statistics by bucket size\n");
    754   1.1      cgd 	(void)printf(
    755   1.1      cgd 	    "    Size   In Use   Free   Requests  HighWater  Couldfree\n");
    756   1.1      cgd 	for (i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16; i++, kp++) {
    757   1.1      cgd 		if (kp->kb_calls == 0)
    758   1.1      cgd 			continue;
    759   1.1      cgd 		size = 1 << i;
    760   1.1      cgd 		(void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size,
    761   1.1      cgd 			kp->kb_total - kp->kb_totalfree,
    762   1.1      cgd 			kp->kb_totalfree, kp->kb_calls,
    763   1.1      cgd 			kp->kb_highwat, kp->kb_couldfree);
    764   1.1      cgd 		totfree += size * kp->kb_totalfree;
    765   1.9  deraadt 		if (kp->kb_highwat < kp->kb_totalfree)
    766   1.9  deraadt 			totwaste += (kp->kb_totalfree - kp->kb_highwat) * size;
    767   1.1      cgd 	}
    768   1.1      cgd 
    769   1.1      cgd 	kread(X_KMEMSTAT, kmemstats, sizeof(kmemstats));
    770   1.1      cgd 	(void)printf("\nMemory statistics by type\n");
    771   1.1      cgd 	(void)printf(
    772   1.8      cgd "        Type  In Use  MemUse   HighUse  Limit Requests  TypeLimit KernLimit\n");
    773   1.4      cgd 	for (i = 0, ks = &kmemstats[0]; i <= M_LAST; i++, ks++) {
    774   1.1      cgd 		if (ks->ks_calls == 0)
    775   1.1      cgd 			continue;
    776   1.8      cgd 		(void)printf("%12s %6ld %7ldK %8ldK %5ldK %8ld %6u %9u\n",
    777   1.1      cgd 		    kmemnames[i] ? kmemnames[i] : "undefined",
    778   1.1      cgd 		    ks->ks_inuse, (ks->ks_memuse + 1023) / 1024,
    779   1.1      cgd 		    (ks->ks_maxused + 1023) / 1024,
    780   1.1      cgd 		    (ks->ks_limit + 1023) / 1024, ks->ks_calls,
    781   1.1      cgd 		    ks->ks_limblocks, ks->ks_mapblocks);
    782   1.1      cgd 		totuse += ks->ks_memuse;
    783   1.1      cgd 		totreq += ks->ks_calls;
    784   1.1      cgd 	}
    785   1.9  deraadt 	(void)printf("\nMemory Totals:  In Use    Free   Wasted   Requests\n");
    786   1.9  deraadt 	(void)printf("              %7ldK %6ldK  %6ldK   %8ld\n",
    787   1.9  deraadt 	     (totuse + 1023) / 1024, (totfree + 1023) / 1024,
    788   1.9  deraadt 	     (totwaste + 1023) / 1024, totreq);
    789   1.1      cgd }
    790   1.1      cgd 
    791   1.1      cgd /*
    792   1.1      cgd  * kread reads something from the kernel, given its nlist index.
    793   1.1      cgd  */
    794   1.1      cgd void
    795   1.1      cgd kread(nlx, addr, size)
    796   1.1      cgd 	int nlx;
    797   1.1      cgd 	void *addr;
    798   1.1      cgd 	size_t size;
    799   1.1      cgd {
    800   1.1      cgd 	char *sym;
    801   1.1      cgd 
    802   1.1      cgd 	if (nl[nlx].n_type == 0 || nl[nlx].n_value == 0) {
    803   1.1      cgd 		sym = nl[nlx].n_name;
    804   1.1      cgd 		if (*sym == '_')
    805   1.1      cgd 			++sym;
    806   1.1      cgd 		(void)fprintf(stderr,
    807   1.1      cgd 		    "vmstat: %s: symbol %s not defined\n", vmunix, sym);
    808   1.1      cgd 		exit(1);
    809   1.1      cgd 	}
    810   1.1      cgd 	if (kvm_read((void *)nl[nlx].n_value, addr, size) != size) {
    811   1.1      cgd 		sym = nl[nlx].n_name;
    812   1.1      cgd 		if (*sym == '_')
    813   1.1      cgd 			++sym;
    814   1.1      cgd 		(void)fprintf(stderr, "vmstat: %s: %s\n", sym, kvm_geterr());
    815   1.1      cgd 		exit(1);
    816   1.1      cgd 	}
    817   1.1      cgd }
    818   1.1      cgd 
    819   1.1      cgd void
    820   1.1      cgd usage()
    821   1.1      cgd {
    822   1.1      cgd 	(void)fprintf(stderr,
    823   1.1      cgd #ifndef NEWVM
    824   1.1      cgd 	    "usage: vmstat [-fimst] [-c count] [-M core] \
    825   1.1      cgd [-N system] [-w wait] [disks]\n");
    826   1.1      cgd #else
    827   1.1      cgd 	    "usage: vmstat [-ims] [-c count] [-M core] \
    828   1.1      cgd [-N system] [-w wait] [disks]\n");
    829   1.1      cgd #endif
    830   1.1      cgd 	exit(1);
    831   1.1      cgd }
    832