Home | History | Annotate | Line # | Download | only in vmstat
vmstat.c revision 1.42
      1  1.42      mrg /*	$NetBSD: vmstat.c,v 1.42 1998/02/07 16:18:14 mrg Exp $	*/
      2  1.21      cgd 
      3   1.1      cgd /*
      4  1.13      cgd  * Copyright (c) 1980, 1986, 1991, 1993
      5  1.13      cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1      cgd  *
      7   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1      cgd  * modification, are permitted provided that the following conditions
      9   1.1      cgd  * are met:
     10   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1      cgd  *    must display the following acknowledgement:
     17   1.1      cgd  *	This product includes software developed by the University of
     18   1.1      cgd  *	California, Berkeley and its contributors.
     19   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1      cgd  *    may be used to endorse or promote products derived from this software
     21   1.1      cgd  *    without specific prior written permission.
     22   1.1      cgd  *
     23   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1      cgd  * SUCH DAMAGE.
     34   1.1      cgd  */
     35   1.1      cgd 
     36  1.38      mrg #include <sys/cdefs.h>
     37   1.1      cgd #ifndef lint
     38  1.38      mrg __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
     39  1.38      mrg 	The Regents of the University of California.  All rights reserved.\n");
     40   1.1      cgd #endif /* not lint */
     41   1.1      cgd 
     42   1.1      cgd #ifndef lint
     43  1.21      cgd #if 0
     44  1.37      mrg static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 3/1/95";
     45  1.21      cgd #else
     46  1.42      mrg __RCSID("$NetBSD: vmstat.c,v 1.42 1998/02/07 16:18:14 mrg Exp $");
     47  1.21      cgd #endif
     48   1.1      cgd #endif /* not lint */
     49   1.1      cgd 
     50   1.1      cgd #include <sys/param.h>
     51   1.1      cgd #include <sys/time.h>
     52   1.1      cgd #include <sys/proc.h>
     53   1.1      cgd #include <sys/user.h>
     54   1.1      cgd #include <sys/dkstat.h>
     55   1.1      cgd #include <sys/buf.h>
     56   1.1      cgd #include <sys/namei.h>
     57   1.1      cgd #include <sys/malloc.h>
     58   1.1      cgd #include <sys/fcntl.h>
     59   1.1      cgd #include <sys/ioctl.h>
     60  1.13      cgd #include <sys/sysctl.h>
     61  1.18       pk #include <sys/device.h>
     62  1.13      cgd #include <vm/vm.h>
     63   1.1      cgd #include <time.h>
     64   1.1      cgd #include <nlist.h>
     65   1.1      cgd #include <kvm.h>
     66   1.1      cgd #include <errno.h>
     67   1.1      cgd #include <unistd.h>
     68  1.22      jtc #include <signal.h>
     69   1.1      cgd #include <stdio.h>
     70   1.1      cgd #include <ctype.h>
     71   1.1      cgd #include <stdlib.h>
     72   1.1      cgd #include <string.h>
     73   1.1      cgd #include <paths.h>
     74  1.13      cgd #include <limits.h>
     75  1.29  thorpej #include "dkstats.h"
     76   1.1      cgd 
     77  1.13      cgd struct nlist namelist[] = {
     78   1.1      cgd #define	X_CPTIME	0
     79   1.1      cgd 	{ "_cp_time" },
     80  1.41      mrg #define	X_BOOTTIME	1
     81   1.1      cgd 	{ "_boottime" },
     82  1.41      mrg #define X_HZ		2
     83   1.1      cgd 	{ "_hz" },
     84  1.41      mrg #define X_STATHZ	3
     85  1.13      cgd 	{ "_stathz" },
     86  1.41      mrg #define X_NCHSTATS	4
     87   1.1      cgd 	{ "_nchstats" },
     88  1.41      mrg #define	X_INTRNAMES	5
     89   1.1      cgd 	{ "_intrnames" },
     90  1.41      mrg #define	X_EINTRNAMES	6
     91   1.1      cgd 	{ "_eintrnames" },
     92  1.41      mrg #define	X_INTRCNT	7
     93   1.1      cgd 	{ "_intrcnt" },
     94  1.41      mrg #define	X_EINTRCNT	8
     95   1.1      cgd 	{ "_eintrcnt" },
     96  1.41      mrg #define	X_KMEMSTAT	9
     97   1.1      cgd 	{ "_kmemstats" },
     98  1.41      mrg #define	X_KMEMBUCKETS	10
     99   1.1      cgd 	{ "_bucket" },
    100  1.41      mrg #define X_ALLEVENTS	11
    101  1.18       pk 	{ "_allevents" },
    102  1.41      mrg #if defined(UVM)
    103  1.41      mrg #define X_END		12
    104   1.1      cgd #else
    105  1.41      mrg #define X_SUM		12
    106  1.41      mrg 	{ "_cnt" },
    107  1.31  mycroft #define X_END		13
    108   1.1      cgd #endif
    109  1.23     phil #if defined(pc532)
    110  1.23     phil #define	X_IVT		(X_END)
    111  1.23     phil 	{ "_ivt" },
    112  1.23     phil #endif
    113   1.1      cgd 	{ "" },
    114   1.1      cgd };
    115   1.1      cgd 
    116  1.29  thorpej /* Objects defined in dkstats.c */
    117  1.29  thorpej extern struct _disk	cur;
    118  1.29  thorpej extern char	**dr_name;
    119  1.29  thorpej extern int	*dk_select, dk_ndrive;
    120   1.1      cgd 
    121  1.41      mrg #if defined(UVM)
    122  1.41      mrg struct	uvmexp uvmexp, ouvmexp;
    123  1.41      mrg #else
    124  1.13      cgd struct	vmmeter sum, osum;
    125  1.41      mrg #endif
    126  1.29  thorpej int		ndrives;
    127   1.1      cgd 
    128   1.1      cgd int	winlines = 20;
    129   1.1      cgd 
    130  1.13      cgd kvm_t *kd;
    131  1.13      cgd 
    132   1.1      cgd #define	FORKSTAT	0x01
    133   1.1      cgd #define	INTRSTAT	0x02
    134   1.1      cgd #define	MEMSTAT		0x04
    135   1.1      cgd #define	SUMSTAT		0x08
    136   1.1      cgd #define	VMSTAT		0x20
    137   1.1      cgd 
    138  1.29  thorpej void	cpustats __P((void));
    139  1.29  thorpej void	dkstats __P((void));
    140  1.29  thorpej void	dointr __P((void));
    141  1.29  thorpej void	domem __P((void));
    142  1.29  thorpej void	dosum __P((void));
    143  1.29  thorpej void	dovmstat __P((u_int, int));
    144  1.29  thorpej void	kread __P((int, void *, size_t));
    145  1.38      mrg void	needhdr __P((int));
    146  1.38      mrg long	getuptime __P((void));
    147  1.38      mrg void	printhdr __P((void));
    148  1.38      mrg long	pct __P((long, long));
    149  1.29  thorpej void	usage __P((void));
    150  1.40  thorpej void	doforkst __P((void));
    151   1.1      cgd 
    152  1.38      mrg int	main __P((int, char **));
    153  1.29  thorpej char	**choosedrives __P((char **));
    154  1.29  thorpej 
    155  1.38      mrg extern int dkinit __P((int));
    156  1.38      mrg extern void dkreadstats __P((void));
    157  1.38      mrg extern void dkswap __P((void));
    158  1.38      mrg 
    159  1.29  thorpej /* Namelist and memory file names. */
    160  1.29  thorpej char	*nlistf, *memf;
    161  1.29  thorpej 
    162  1.38      mrg int
    163   1.1      cgd main(argc, argv)
    164  1.38      mrg 	int argc;
    165  1.38      mrg 	char **argv;
    166   1.1      cgd {
    167   1.1      cgd 	extern int optind;
    168   1.1      cgd 	extern char *optarg;
    169  1.38      mrg 	int c, todo;
    170   1.1      cgd 	u_int interval;
    171   1.1      cgd 	int reps;
    172  1.13      cgd         char errbuf[_POSIX2_LINE_MAX];
    173   1.1      cgd 
    174  1.13      cgd 	memf = nlistf = NULL;
    175   1.1      cgd 	interval = reps = todo = 0;
    176  1.39    lukem 	while ((c = getopt(argc, argv, "c:fiM:mN:stw:")) != -1) {
    177   1.1      cgd 		switch (c) {
    178   1.1      cgd 		case 'c':
    179   1.1      cgd 			reps = atoi(optarg);
    180   1.1      cgd 			break;
    181   1.1      cgd 		case 'f':
    182   1.1      cgd 			todo |= FORKSTAT;
    183   1.1      cgd 			break;
    184   1.1      cgd 		case 'i':
    185   1.1      cgd 			todo |= INTRSTAT;
    186   1.1      cgd 			break;
    187   1.1      cgd 		case 'M':
    188  1.13      cgd 			memf = optarg;
    189   1.1      cgd 			break;
    190   1.1      cgd 		case 'm':
    191   1.1      cgd 			todo |= MEMSTAT;
    192   1.1      cgd 			break;
    193   1.1      cgd 		case 'N':
    194  1.13      cgd 			nlistf = optarg;
    195   1.1      cgd 			break;
    196   1.1      cgd 		case 's':
    197   1.1      cgd 			todo |= SUMSTAT;
    198   1.1      cgd 			break;
    199   1.1      cgd 		case 'w':
    200   1.1      cgd 			interval = atoi(optarg);
    201   1.1      cgd 			break;
    202   1.1      cgd 		case '?':
    203   1.1      cgd 		default:
    204   1.1      cgd 			usage();
    205   1.1      cgd 		}
    206   1.1      cgd 	}
    207   1.1      cgd 	argc -= optind;
    208   1.1      cgd 	argv += optind;
    209   1.1      cgd 
    210   1.1      cgd 	if (todo == 0)
    211   1.1      cgd 		todo = VMSTAT;
    212   1.1      cgd 
    213  1.13      cgd 	/*
    214  1.13      cgd 	 * Discard setgid privileges if not the running kernel so that bad
    215  1.13      cgd 	 * guys can't print interesting stuff from kernel memory.
    216  1.13      cgd 	 */
    217  1.13      cgd 	if (nlistf != NULL || memf != NULL)
    218  1.13      cgd 		setgid(getgid());
    219  1.13      cgd 
    220  1.13      cgd         kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
    221  1.13      cgd 	if (kd == 0) {
    222   1.1      cgd 		(void)fprintf(stderr,
    223  1.13      cgd 		    "vmstat: kvm_openfiles: %s\n", errbuf);
    224   1.1      cgd 		exit(1);
    225   1.1      cgd 	}
    226   1.1      cgd 
    227  1.13      cgd 	if ((c = kvm_nlist(kd, namelist)) != 0) {
    228   1.1      cgd 		if (c > 0) {
    229   1.1      cgd 			(void)fprintf(stderr,
    230  1.13      cgd 			    "vmstat: undefined symbols:");
    231  1.13      cgd 			for (c = 0;
    232  1.13      cgd 			    c < sizeof(namelist)/sizeof(namelist[0]); c++)
    233  1.13      cgd 				if (namelist[c].n_type == 0)
    234  1.13      cgd 					fprintf(stderr, " %s",
    235  1.13      cgd 					    namelist[c].n_name);
    236   1.1      cgd 			(void)fputc('\n', stderr);
    237   1.1      cgd 		} else
    238   1.1      cgd 			(void)fprintf(stderr, "vmstat: kvm_nlist: %s\n",
    239  1.13      cgd 			    kvm_geterr(kd));
    240   1.1      cgd 		exit(1);
    241   1.1      cgd 	}
    242   1.1      cgd 
    243   1.1      cgd 	if (todo & VMSTAT) {
    244   1.1      cgd 		struct winsize winsize;
    245   1.1      cgd 
    246  1.29  thorpej 		dkinit(0);	/* Initialize disk stats, no disks selected. */
    247  1.29  thorpej 		argv = choosedrives(argv);	/* Select disks. */
    248   1.1      cgd 		winsize.ws_row = 0;
    249   1.1      cgd 		(void) ioctl(STDOUT_FILENO, TIOCGWINSZ, (char *)&winsize);
    250   1.1      cgd 		if (winsize.ws_row > 0)
    251   1.1      cgd 			winlines = winsize.ws_row;
    252   1.1      cgd 
    253   1.1      cgd 	}
    254   1.1      cgd 
    255   1.1      cgd #define	BACKWARD_COMPATIBILITY
    256   1.1      cgd #ifdef	BACKWARD_COMPATIBILITY
    257   1.1      cgd 	if (*argv) {
    258   1.1      cgd 		interval = atoi(*argv);
    259   1.1      cgd 		if (*++argv)
    260   1.1      cgd 			reps = atoi(*argv);
    261   1.1      cgd 	}
    262   1.1      cgd #endif
    263   1.1      cgd 
    264   1.1      cgd 	if (interval) {
    265   1.1      cgd 		if (!reps)
    266   1.1      cgd 			reps = -1;
    267   1.1      cgd 	} else if (reps)
    268   1.1      cgd 		interval = 1;
    269   1.1      cgd 
    270   1.1      cgd 	if (todo & FORKSTAT)
    271   1.1      cgd 		doforkst();
    272   1.1      cgd 	if (todo & MEMSTAT)
    273   1.1      cgd 		domem();
    274   1.1      cgd 	if (todo & SUMSTAT)
    275  1.13      cgd 		dosum();
    276   1.1      cgd 	if (todo & INTRSTAT)
    277   1.1      cgd 		dointr();
    278   1.1      cgd 	if (todo & VMSTAT)
    279   1.1      cgd 		dovmstat(interval, reps);
    280   1.1      cgd 	exit(0);
    281   1.1      cgd }
    282   1.1      cgd 
    283   1.1      cgd char **
    284  1.29  thorpej choosedrives(argv)
    285   1.1      cgd 	char **argv;
    286   1.1      cgd {
    287  1.38      mrg 	int i;
    288   1.1      cgd 
    289   1.1      cgd 	/*
    290   1.1      cgd 	 * Choose drives to be displayed.  Priority goes to (in order) drives
    291   1.1      cgd 	 * supplied as arguments, default drives.  If everything isn't filled
    292   1.1      cgd 	 * in and there are drives not taken care of, display the first few
    293   1.1      cgd 	 * that fit.
    294   1.1      cgd 	 */
    295   1.1      cgd #define BACKWARD_COMPATIBILITY
    296   1.1      cgd 	for (ndrives = 0; *argv; ++argv) {
    297   1.1      cgd #ifdef	BACKWARD_COMPATIBILITY
    298   1.1      cgd 		if (isdigit(**argv))
    299   1.1      cgd 			break;
    300   1.1      cgd #endif
    301   1.1      cgd 		for (i = 0; i < dk_ndrive; i++) {
    302   1.1      cgd 			if (strcmp(dr_name[i], *argv))
    303   1.1      cgd 				continue;
    304  1.29  thorpej 			dk_select[i] = 1;
    305   1.1      cgd 			++ndrives;
    306   1.1      cgd 			break;
    307   1.1      cgd 		}
    308   1.1      cgd 	}
    309   1.1      cgd 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
    310  1.29  thorpej 		if (dk_select[i])
    311   1.1      cgd 			continue;
    312  1.29  thorpej 		dk_select[i] = 1;
    313   1.1      cgd 		++ndrives;
    314   1.1      cgd 	}
    315   1.1      cgd 	return(argv);
    316   1.1      cgd }
    317   1.1      cgd 
    318   1.1      cgd long
    319   1.1      cgd getuptime()
    320   1.1      cgd {
    321  1.30      cgd 	static time_t now;
    322  1.30      cgd 	static struct timeval boottime;
    323   1.1      cgd 	time_t uptime;
    324   1.1      cgd 
    325  1.30      cgd 	if (boottime.tv_sec == 0)
    326   1.1      cgd 		kread(X_BOOTTIME, &boottime, sizeof(boottime));
    327   1.1      cgd 	(void)time(&now);
    328  1.30      cgd 	uptime = now - boottime.tv_sec;
    329   1.1      cgd 	if (uptime <= 0 || uptime > 60*60*24*365*10) {
    330   1.1      cgd 		(void)fprintf(stderr,
    331   1.1      cgd 		    "vmstat: time makes no sense; namelist must be wrong.\n");
    332   1.1      cgd 		exit(1);
    333   1.1      cgd 	}
    334   1.1      cgd 	return(uptime);
    335   1.1      cgd }
    336   1.1      cgd 
    337   1.1      cgd int	hz, hdrcnt;
    338   1.1      cgd 
    339   1.1      cgd void
    340   1.1      cgd dovmstat(interval, reps)
    341   1.1      cgd 	u_int interval;
    342   1.1      cgd 	int reps;
    343   1.1      cgd {
    344   1.1      cgd 	struct vmtotal total;
    345   1.1      cgd 	time_t uptime, halfuptime;
    346  1.17      cgd 	int mib[2];
    347  1.17      cgd 	size_t size;
    348  1.41      mrg 	int pagesize = getpagesize();
    349   1.1      cgd 
    350   1.1      cgd 	uptime = getuptime();
    351   1.1      cgd 	halfuptime = uptime / 2;
    352   1.1      cgd 	(void)signal(SIGCONT, needhdr);
    353   1.1      cgd 
    354  1.13      cgd 	if (namelist[X_STATHZ].n_type != 0 && namelist[X_STATHZ].n_value != 0)
    355  1.13      cgd 		kread(X_STATHZ, &hz, sizeof(hz));
    356   1.1      cgd 	if (!hz)
    357   1.1      cgd 		kread(X_HZ, &hz, sizeof(hz));
    358   1.1      cgd 
    359   1.1      cgd 	for (hdrcnt = 1;;) {
    360   1.1      cgd 		if (!--hdrcnt)
    361   1.1      cgd 			printhdr();
    362  1.29  thorpej 		/* Read new disk statistics */
    363  1.29  thorpej 		dkreadstats();
    364  1.41      mrg #if defined(UVM)
    365  1.41      mrg 		size = sizeof(uvmexp);
    366  1.41      mrg 		mib[0] = CTL_VM;
    367  1.41      mrg 		mib[1] = VM_UVMEXP;
    368  1.41      mrg 		if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
    369  1.41      mrg 			printf("can't get uvmexp: %s\n", strerror(errno));
    370  1.41      mrg 			bzero(&uvmexp, sizeof(uvmexp));
    371  1.41      mrg 		}
    372  1.41      mrg #else
    373  1.13      cgd 		kread(X_SUM, &sum, sizeof(sum));
    374  1.41      mrg #endif
    375  1.13      cgd 		size = sizeof(total);
    376  1.13      cgd 		mib[0] = CTL_VM;
    377  1.13      cgd 		mib[1] = VM_METER;
    378  1.13      cgd 		if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
    379  1.13      cgd 			printf("Can't get kerninfo: %s\n", strerror(errno));
    380  1.13      cgd 			bzero(&total, sizeof(total));
    381  1.13      cgd 		}
    382  1.13      cgd 		(void)printf("%2d%2d%2d",
    383  1.13      cgd 		    total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
    384  1.41      mrg #define pgtok(a) (long)((a) * (pagesize >> 10))
    385  1.38      mrg #define	rate(x)	(u_long)(((x) + halfuptime) / uptime)	/* round */
    386  1.13      cgd 		(void)printf("%6ld%6ld ",
    387   1.1      cgd 		    pgtok(total.t_avm), pgtok(total.t_free));
    388  1.41      mrg #if defined(UVM)
    389  1.42      mrg 		(void)printf("%4lu ", rate(uvmexp.faults - ouvmexp.faults));
    390  1.42      mrg 		(void)printf("%3lu ", rate(uvmexp.pdreact - ouvmexp.pdreact));
    391  1.42      mrg 		(void)printf("%3lu ", rate(uvmexp.pageins - ouvmexp.pageins));
    392  1.42      mrg 		(void)printf("%3lu %3lu ",
    393  1.42      mrg 		    rate(uvmexp.pageouts - ouvmexp.pageouts), (u_long)0);	/* XXX */
    394  1.42      mrg 		(void)printf("%3lu ", rate(uvmexp.pdscans - ouvmexp.pdscans));
    395  1.42      mrg 		dkstats();
    396  1.42      mrg 		(void)printf("%4lu %4lu %3lu ",
    397  1.42      mrg 		    rate(uvmexp.intrs - ouvmexp.intrs),
    398  1.42      mrg 		    rate(uvmexp.syscalls - ouvmexp.syscalls),
    399  1.42      mrg 		    rate(uvmexp.swtch - ouvmexp.swtch));
    400  1.42      mrg 		cpustats();
    401  1.42      mrg 		(void)printf("\n");
    402  1.42      mrg 		(void)fflush(stdout);
    403  1.42      mrg 		if (reps >= 0 && --reps <= 0)
    404  1.42      mrg 			break;
    405  1.42      mrg 		ouvmexp = uvmexp;
    406  1.41      mrg #else
    407  1.13      cgd 		(void)printf("%4lu ", rate(sum.v_faults - osum.v_faults));
    408   1.1      cgd 		(void)printf("%3lu ",
    409  1.13      cgd 		    rate(sum.v_reactivated - osum.v_reactivated));
    410  1.13      cgd 		(void)printf("%3lu ", rate(sum.v_pageins - osum.v_pageins));
    411   1.1      cgd 		(void)printf("%3lu %3lu ",
    412  1.38      mrg 		    rate(sum.v_pageouts - osum.v_pageouts), (u_long)0);
    413  1.13      cgd 		(void)printf("%3lu ", rate(sum.v_scan - osum.v_scan));
    414   1.1      cgd 		dkstats();
    415   1.1      cgd 		(void)printf("%4lu %4lu %3lu ",
    416  1.13      cgd 		    rate(sum.v_intr - osum.v_intr),
    417  1.13      cgd 		    rate(sum.v_syscall - osum.v_syscall),
    418  1.13      cgd 		    rate(sum.v_swtch - osum.v_swtch));
    419   1.1      cgd 		cpustats();
    420   1.1      cgd 		(void)printf("\n");
    421   1.1      cgd 		(void)fflush(stdout);
    422   1.1      cgd 		if (reps >= 0 && --reps <= 0)
    423   1.1      cgd 			break;
    424  1.13      cgd 		osum = sum;
    425  1.41      mrg #endif
    426   1.1      cgd 		uptime = interval;
    427   1.1      cgd 		/*
    428   1.1      cgd 		 * We round upward to avoid losing low-frequency events
    429   1.1      cgd 		 * (i.e., >= 1 per interval but < 1 per second).
    430   1.1      cgd 		 */
    431  1.33  thorpej 		halfuptime = uptime == 1 ? 0 : (uptime + 1) / 2;
    432   1.1      cgd 		(void)sleep(interval);
    433   1.1      cgd 	}
    434   1.1      cgd }
    435   1.1      cgd 
    436  1.38      mrg void
    437   1.1      cgd printhdr()
    438   1.1      cgd {
    439  1.38      mrg 	int i;
    440   1.1      cgd 
    441   1.1      cgd 	(void)printf(" procs   memory     page%*s", 20, "");
    442  1.29  thorpej 	if (ndrives > 0)
    443  1.29  thorpej 		(void)printf("%s %*sfaults   cpu\n",
    444  1.29  thorpej 		   ((ndrives > 1) ? "disks" : "disk"),
    445  1.29  thorpej 		   ((ndrives > 1) ? ndrives * 3 - 4 : 0), "");
    446   1.1      cgd 	else
    447  1.29  thorpej 		(void)printf("%*s  faults   cpu\n",
    448  1.29  thorpej 		   ndrives * 3, "");
    449  1.29  thorpej 
    450   1.1      cgd 	(void)printf(" r b w   avm   fre  flt  re  pi  po  fr  sr ");
    451   1.1      cgd 	for (i = 0; i < dk_ndrive; i++)
    452  1.29  thorpej 		if (dk_select[i])
    453   1.1      cgd 			(void)printf("%c%c ", dr_name[i][0],
    454   1.1      cgd 			    dr_name[i][strlen(dr_name[i]) - 1]);
    455   1.1      cgd 	(void)printf("  in   sy  cs us sy id\n");
    456   1.1      cgd 	hdrcnt = winlines - 2;
    457   1.1      cgd }
    458   1.1      cgd 
    459   1.1      cgd /*
    460   1.1      cgd  * Force a header to be prepended to the next output.
    461   1.1      cgd  */
    462   1.1      cgd void
    463  1.38      mrg needhdr(dummy)
    464  1.38      mrg 	int dummy;
    465   1.1      cgd {
    466   1.1      cgd 
    467   1.1      cgd 	hdrcnt = 1;
    468   1.1      cgd }
    469   1.1      cgd 
    470  1.38      mrg long
    471   1.1      cgd pct(top, bot)
    472   1.1      cgd 	long top, bot;
    473   1.1      cgd {
    474  1.13      cgd 	long ans;
    475  1.13      cgd 
    476   1.1      cgd 	if (bot == 0)
    477   1.1      cgd 		return(0);
    478  1.13      cgd 	ans = (quad_t)top * 100 / bot;
    479  1.13      cgd 	return (ans);
    480   1.1      cgd }
    481   1.1      cgd 
    482  1.38      mrg #define	PCT(top, bot) (int)pct((long)(top), (long)(bot))
    483   1.1      cgd 
    484   1.1      cgd void
    485  1.13      cgd dosum()
    486   1.1      cgd {
    487   1.1      cgd 	struct nchstats nchstats;
    488   1.1      cgd 	long nchtotal;
    489   1.1      cgd 
    490  1.41      mrg #if defined(UVM)
    491  1.41      mrg 	int	mib[2];
    492  1.41      mrg 	size_t	size;
    493  1.41      mrg 
    494  1.41      mrg 	size = sizeof(uvmexp);
    495  1.41      mrg 	mib[0] = CTL_VM;
    496  1.41      mrg 	mib[1] = VM_UVMEXP;
    497  1.41      mrg 	if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
    498  1.41      mrg 		printf("can't get uvmexp: %s\n", strerror(errno));
    499  1.41      mrg 		bzero(&uvmexp, sizeof(uvmexp));
    500  1.41      mrg 	}
    501  1.41      mrg 
    502  1.41      mrg 	/* XXX fill me in! */
    503  1.41      mrg #else
    504  1.13      cgd 	kread(X_SUM, &sum, sizeof(sum));
    505  1.13      cgd 	(void)printf("%9u cpu context switches\n", sum.v_swtch);
    506  1.13      cgd 	(void)printf("%9u device interrupts\n", sum.v_intr);
    507  1.13      cgd 	(void)printf("%9u software interrupts\n", sum.v_soft);
    508  1.13      cgd 	(void)printf("%9u traps\n", sum.v_trap);
    509  1.13      cgd 	(void)printf("%9u system calls\n", sum.v_syscall);
    510  1.13      cgd 	(void)printf("%9u total faults taken\n", sum.v_faults);
    511  1.13      cgd 	(void)printf("%9u swap ins\n", sum.v_swpin);
    512  1.13      cgd 	(void)printf("%9u swap outs\n", sum.v_swpout);
    513  1.13      cgd 	(void)printf("%9u pages swapped in\n", sum.v_pswpin / CLSIZE);
    514  1.13      cgd 	(void)printf("%9u pages swapped out\n", sum.v_pswpout / CLSIZE);
    515  1.13      cgd 	(void)printf("%9u page ins\n", sum.v_pageins);
    516  1.13      cgd 	(void)printf("%9u page outs\n", sum.v_pageouts);
    517  1.13      cgd 	(void)printf("%9u pages paged in\n", sum.v_pgpgin);
    518  1.13      cgd 	(void)printf("%9u pages paged out\n", sum.v_pgpgout);
    519  1.13      cgd 	(void)printf("%9u pages reactivated\n", sum.v_reactivated);
    520  1.13      cgd 	(void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
    521  1.13      cgd 	(void)printf("%9u zero fill pages created\n", sum.v_nzfod / CLSIZE);
    522  1.13      cgd 	(void)printf("%9u zero fill page faults\n", sum.v_zfod / CLSIZE);
    523  1.13      cgd 	(void)printf("%9u pages examined by the clock daemon\n", sum.v_scan);
    524  1.13      cgd 	(void)printf("%9u revolutions of the clock hand\n", sum.v_rev);
    525  1.13      cgd 	(void)printf("%9u VM object cache lookups\n", sum.v_lookups);
    526  1.13      cgd 	(void)printf("%9u VM object hits\n", sum.v_hits);
    527  1.13      cgd 	(void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
    528  1.13      cgd 	(void)printf("%9u copy-on-write faults\n", sum.v_cow_faults);
    529  1.13      cgd 	(void)printf("%9u pages freed by daemon\n", sum.v_dfree);
    530  1.13      cgd 	(void)printf("%9u pages freed by exiting processes\n", sum.v_pfree);
    531  1.13      cgd 	(void)printf("%9u pages free\n", sum.v_free_count);
    532  1.13      cgd 	(void)printf("%9u pages wired down\n", sum.v_wire_count);
    533  1.13      cgd 	(void)printf("%9u pages active\n", sum.v_active_count);
    534  1.13      cgd 	(void)printf("%9u pages inactive\n", sum.v_inactive_count);
    535  1.13      cgd 	(void)printf("%9u bytes per page\n", sum.v_page_size);
    536  1.37      mrg 	(void)printf("%9u target inactive pages\n", sum.v_inactive_target);
    537  1.37      mrg 	(void)printf("%9u target free pages\n", sum.v_free_target);
    538  1.37      mrg 	(void)printf("%9u minimum free pages\n", sum.v_free_min);
    539   1.1      cgd #endif
    540   1.1      cgd 	kread(X_NCHSTATS, &nchstats, sizeof(nchstats));
    541   1.1      cgd 	nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits +
    542   1.1      cgd 	    nchstats.ncs_badhits + nchstats.ncs_falsehits +
    543   1.1      cgd 	    nchstats.ncs_miss + nchstats.ncs_long;
    544   1.1      cgd 	(void)printf("%9ld total name lookups\n", nchtotal);
    545   1.1      cgd 	(void)printf(
    546   1.1      cgd 	    "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
    547   1.1      cgd 	    "", PCT(nchstats.ncs_goodhits, nchtotal),
    548   1.1      cgd 	    PCT(nchstats.ncs_neghits, nchtotal),
    549   1.1      cgd 	    PCT(nchstats.ncs_pass2, nchtotal));
    550   1.1      cgd 	(void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "",
    551   1.1      cgd 	    PCT(nchstats.ncs_badhits, nchtotal),
    552   1.1      cgd 	    PCT(nchstats.ncs_falsehits, nchtotal),
    553   1.1      cgd 	    PCT(nchstats.ncs_long, nchtotal));
    554   1.1      cgd }
    555   1.1      cgd 
    556   1.1      cgd void
    557   1.1      cgd doforkst()
    558   1.1      cgd {
    559  1.41      mrg #if defined(UVM)
    560  1.41      mrg 	int	mib[2];
    561  1.41      mrg 	size_t	size;
    562  1.41      mrg 
    563  1.41      mrg 	size = sizeof(uvmexp);
    564  1.41      mrg 	mib[0] = CTL_VM;
    565  1.41      mrg 	mib[1] = VM_UVMEXP;
    566  1.41      mrg 	if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
    567  1.41      mrg 		printf("can't get uvmexp: %s\n", strerror(errno));
    568  1.41      mrg 		bzero(&uvmexp, sizeof(uvmexp));
    569  1.41      mrg 	}
    570  1.41      mrg 	(void)printf("%u forks total\n", uvmexp.forks);
    571  1.41      mrg 	(void)printf("%u forks blocked parent\n", uvmexp.forks_ppwait);
    572  1.41      mrg 	(void)printf("%u forks shared address space with parent\n",
    573  1.41      mrg 	    uvmexp.forks_sharevm);
    574  1.41      mrg #else
    575   1.1      cgd 
    576  1.40  thorpej 	kread(X_SUM, &sum, sizeof(sum));
    577  1.40  thorpej 	(void)printf("%u forks total\n", sum.v_forks);
    578  1.40  thorpej 	(void)printf("%u forks blocked parent\n", sum.v_forks_ppwait);
    579  1.40  thorpej 	(void)printf("%u forks shared address space with parent\n",
    580  1.40  thorpej 	    sum.v_forks_sharevm);
    581  1.41      mrg #endif
    582   1.1      cgd }
    583   1.1      cgd 
    584   1.1      cgd void
    585   1.1      cgd dkstats()
    586   1.1      cgd {
    587  1.38      mrg 	int dn, state;
    588   1.1      cgd 	double etime;
    589   1.1      cgd 
    590  1.29  thorpej 	/* Calculate disk stat deltas. */
    591  1.29  thorpej 	dkswap();
    592   1.1      cgd 	etime = 0;
    593   1.1      cgd 	for (state = 0; state < CPUSTATES; ++state) {
    594  1.29  thorpej 		etime += cur.cp_time[state];
    595   1.1      cgd 	}
    596   1.1      cgd 	if (etime == 0)
    597   1.1      cgd 		etime = 1;
    598   1.1      cgd 	etime /= hz;
    599   1.1      cgd 	for (dn = 0; dn < dk_ndrive; ++dn) {
    600  1.29  thorpej 		if (!dk_select[dn])
    601   1.1      cgd 			continue;
    602  1.29  thorpej 		(void)printf("%2.0f ", cur.dk_xfer[dn] / etime);
    603   1.1      cgd 	}
    604   1.1      cgd }
    605   1.1      cgd 
    606   1.1      cgd void
    607   1.1      cgd cpustats()
    608   1.1      cgd {
    609  1.38      mrg 	int state;
    610   1.1      cgd 	double pct, total;
    611   1.1      cgd 
    612   1.1      cgd 	total = 0;
    613   1.1      cgd 	for (state = 0; state < CPUSTATES; ++state)
    614  1.29  thorpej 		total += cur.cp_time[state];
    615   1.1      cgd 	if (total)
    616   1.1      cgd 		pct = 100 / total;
    617   1.1      cgd 	else
    618   1.1      cgd 		pct = 0;
    619  1.29  thorpej 	(void)printf("%2.0f ", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * pct);
    620  1.29  thorpej 	(void)printf("%2.0f ", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * pct);
    621  1.29  thorpej 	(void)printf("%2.0f", cur.cp_time[CP_IDLE] * pct);
    622   1.1      cgd }
    623   1.1      cgd 
    624  1.23     phil #if defined(pc532)
    625  1.24     phil /* To get struct iv ...*/
    626  1.24     phil #define _KERNEL
    627  1.23     phil #include <machine/psl.h>
    628  1.24     phil #undef _KERNEL
    629  1.23     phil void
    630  1.23     phil dointr()
    631  1.23     phil {
    632  1.38      mrg 	long i, j, inttotal, uptime;
    633  1.23     phil 	static char iname[64];
    634  1.23     phil 	struct iv ivt[32], *ivp = ivt;
    635  1.23     phil 
    636  1.23     phil 	iname[63] = '\0';
    637  1.23     phil 	uptime = getuptime();
    638  1.23     phil 	kread(X_IVT, ivp, sizeof(ivt));
    639  1.23     phil 
    640  1.23     phil 	for (i = 0; i < 2; i++) {
    641  1.23     phil 		(void)printf("%sware interrupts:\n", i ? "\nsoft" : "hard");
    642  1.23     phil 		(void)printf("interrupt       total     rate\n");
    643  1.23     phil 		inttotal = 0;
    644  1.23     phil 		for (j = 0; j < 16; j++, ivp++) {
    645  1.23     phil 			if (ivp->iv_vec && ivp->iv_use && ivp->iv_cnt) {
    646  1.23     phil 				if (kvm_read(kd, (u_long)ivp->iv_use, iname, 63) != 63) {
    647  1.23     phil 					(void)fprintf(stderr, "vmstat: iv_use: %s\n",
    648  1.23     phil 					    kvm_geterr(kd));
    649  1.23     phil 					exit(1);
    650  1.23     phil 				}
    651  1.23     phil 				(void)printf("%-12s %8ld %8ld\n", iname,
    652  1.23     phil 				    ivp->iv_cnt, ivp->iv_cnt / uptime);
    653  1.23     phil 				inttotal += ivp->iv_cnt;
    654  1.23     phil 			}
    655  1.23     phil 		}
    656  1.23     phil 		(void)printf("Total        %8ld %8ld\n",
    657  1.23     phil 		    inttotal, inttotal / uptime);
    658  1.23     phil 	}
    659  1.23     phil }
    660  1.23     phil #else
    661   1.1      cgd void
    662   1.1      cgd dointr()
    663   1.1      cgd {
    664  1.38      mrg 	long *intrcnt, inttotal, uptime;
    665  1.38      mrg 	int nintr, inamlen;
    666  1.38      mrg 	char *intrname;
    667  1.28      cgd 	struct evcntlist allevents;
    668  1.28      cgd 	struct evcnt evcnt, *evptr;
    669  1.18       pk 	struct device dev;
    670   1.1      cgd 
    671   1.1      cgd 	uptime = getuptime();
    672  1.13      cgd 	nintr = namelist[X_EINTRCNT].n_value - namelist[X_INTRCNT].n_value;
    673  1.13      cgd 	inamlen =
    674  1.13      cgd 	    namelist[X_EINTRNAMES].n_value - namelist[X_INTRNAMES].n_value;
    675   1.1      cgd 	intrcnt = malloc((size_t)nintr);
    676   1.1      cgd 	intrname = malloc((size_t)inamlen);
    677   1.1      cgd 	if (intrcnt == NULL || intrname == NULL) {
    678   1.1      cgd 		(void)fprintf(stderr, "vmstat: %s.\n", strerror(errno));
    679   1.1      cgd 		exit(1);
    680   1.1      cgd 	}
    681   1.1      cgd 	kread(X_INTRCNT, intrcnt, (size_t)nintr);
    682   1.1      cgd 	kread(X_INTRNAMES, intrname, (size_t)inamlen);
    683  1.27      cgd 	(void)printf("interrupt         total     rate\n");
    684   1.1      cgd 	inttotal = 0;
    685   1.1      cgd 	nintr /= sizeof(long);
    686   1.1      cgd 	while (--nintr >= 0) {
    687   1.1      cgd 		if (*intrcnt)
    688  1.27      cgd 			(void)printf("%-14s %8ld %8ld\n", intrname,
    689   1.1      cgd 			    *intrcnt, *intrcnt / uptime);
    690   1.1      cgd 		intrname += strlen(intrname) + 1;
    691   1.1      cgd 		inttotal += *intrcnt++;
    692   1.1      cgd 	}
    693  1.18       pk 	kread(X_ALLEVENTS, &allevents, sizeof allevents);
    694  1.28      cgd 	evptr = allevents.tqh_first;
    695  1.28      cgd 	while (evptr) {
    696  1.28      cgd 		if (kvm_read(kd, (long)evptr, (void *)&evcnt,
    697  1.18       pk 		    sizeof evcnt) != sizeof evcnt) {
    698  1.38      mrg 			(void)fprintf(stderr, "vmstat: event chain trashed: %s\n",
    699  1.18       pk 			    kvm_geterr(kd));
    700  1.18       pk 			exit(1);
    701  1.18       pk 		}
    702  1.32      cgd 		if (kvm_read(kd, (long)evcnt.ev_dev, (void *)&dev,
    703  1.32      cgd 		    sizeof dev) != sizeof dev) {
    704  1.38      mrg 			(void)fprintf(stderr, "vmstat: event chain trashed: %s\n",
    705  1.32      cgd 			    kvm_geterr(kd));
    706  1.32      cgd 			exit(1);
    707  1.18       pk 		}
    708  1.32      cgd 		if (evcnt.ev_count)
    709  1.32      cgd 			(void)printf("%-14s %8ld %8ld\n", dev.dv_xname,
    710  1.38      mrg 			    (long)evcnt.ev_count, evcnt.ev_count / uptime);
    711  1.32      cgd 		inttotal += evcnt.ev_count++;
    712  1.32      cgd 
    713  1.28      cgd 		evptr = evcnt.ev_list.tqe_next;
    714  1.18       pk 	}
    715  1.27      cgd 	(void)printf("Total          %8ld %8ld\n", inttotal, inttotal / uptime);
    716   1.1      cgd }
    717  1.23     phil #endif
    718   1.1      cgd 
    719   1.1      cgd /*
    720   1.1      cgd  * These names are defined in <sys/malloc.h>.
    721   1.1      cgd  */
    722   1.1      cgd char *kmemnames[] = INITKMEMNAMES;
    723   1.1      cgd 
    724   1.1      cgd void
    725   1.1      cgd domem()
    726   1.1      cgd {
    727  1.38      mrg 	struct kmembuckets *kp;
    728  1.38      mrg 	struct kmemstats *ks;
    729  1.38      mrg 	int i, j;
    730  1.13      cgd 	int len, size, first;
    731  1.13      cgd 	long totuse = 0, totfree = 0, totreq = 0;
    732  1.13      cgd 	char *name;
    733  1.13      cgd 	struct kmemstats kmemstats[M_LAST];
    734   1.1      cgd 	struct kmembuckets buckets[MINBUCKET + 16];
    735   1.1      cgd 
    736   1.1      cgd 	kread(X_KMEMBUCKETS, buckets, sizeof(buckets));
    737  1.34  thorpej 	for (first = 1, i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16;
    738  1.34  thorpej 	    i++, kp++) {
    739   1.1      cgd 		if (kp->kb_calls == 0)
    740   1.1      cgd 			continue;
    741  1.34  thorpej 		if (first) {
    742  1.34  thorpej 			(void)printf("Memory statistics by bucket size\n");
    743  1.34  thorpej 			(void)printf(
    744  1.34  thorpej 		 "    Size   In Use   Free   Requests  HighWater  Couldfree\n");
    745  1.34  thorpej 			first = 0;
    746  1.34  thorpej 		}
    747   1.1      cgd 		size = 1 << i;
    748   1.1      cgd 		(void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size,
    749   1.1      cgd 			kp->kb_total - kp->kb_totalfree,
    750   1.1      cgd 			kp->kb_totalfree, kp->kb_calls,
    751   1.1      cgd 			kp->kb_highwat, kp->kb_couldfree);
    752   1.1      cgd 		totfree += size * kp->kb_totalfree;
    753  1.34  thorpej 	}
    754  1.34  thorpej 
    755  1.34  thorpej 	/*
    756  1.34  thorpej 	 * If kmem statistics are not being gathered by the kernel,
    757  1.34  thorpej 	 * first will still be 1.
    758  1.34  thorpej 	 */
    759  1.34  thorpej 	if (first) {
    760  1.34  thorpej 		printf(
    761  1.34  thorpej 		    "Kmem statistics are not being gathered by the kernel.\n");
    762  1.34  thorpej 		return;
    763   1.1      cgd 	}
    764   1.1      cgd 
    765   1.1      cgd 	kread(X_KMEMSTAT, kmemstats, sizeof(kmemstats));
    766  1.13      cgd 	(void)printf("\nMemory usage type by bucket size\n");
    767  1.13      cgd 	(void)printf("    Size  Type(s)\n");
    768  1.13      cgd 	kp = &buckets[MINBUCKET];
    769  1.13      cgd 	for (j =  1 << MINBUCKET; j < 1 << (MINBUCKET + 16); j <<= 1, kp++) {
    770  1.13      cgd 		if (kp->kb_calls == 0)
    771  1.13      cgd 			continue;
    772  1.13      cgd 		first = 1;
    773  1.13      cgd 		len = 8;
    774  1.13      cgd 		for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) {
    775  1.13      cgd 			if (ks->ks_calls == 0)
    776  1.13      cgd 				continue;
    777  1.13      cgd 			if ((ks->ks_size & j) == 0)
    778  1.13      cgd 				continue;
    779  1.35       is 			if (kmemnames[i] == 0) {
    780  1.35       is 				kmemnames[i] = malloc(10);
    781  1.35       is 						/* strlen("undef/")+3+1);*/
    782  1.35       is 				snprintf(kmemnames[i], 10, "undef/%d", i);
    783  1.35       is 						/* same 10 as above!!! */
    784  1.35       is 			}
    785  1.35       is 			name = kmemnames[i];
    786  1.13      cgd 			len += 2 + strlen(name);
    787  1.13      cgd 			if (first)
    788  1.13      cgd 				printf("%8d  %s", j, name);
    789  1.13      cgd 			else
    790  1.13      cgd 				printf(",");
    791  1.13      cgd 			if (len >= 80) {
    792  1.13      cgd 				printf("\n\t ");
    793  1.13      cgd 				len = 10 + strlen(name);
    794  1.13      cgd 			}
    795  1.13      cgd 			if (!first)
    796  1.13      cgd 				printf(" %s", name);
    797  1.13      cgd 			first = 0;
    798  1.13      cgd 		}
    799  1.13      cgd 		printf("\n");
    800  1.13      cgd 	}
    801  1.13      cgd 
    802   1.1      cgd 	(void)printf(
    803  1.13      cgd 	    "\nMemory statistics by type                        Type  Kern\n");
    804  1.13      cgd 	(void)printf(
    805  1.36       is "         Type  InUse MemUse HighUse  Limit Requests Limit Limit Size(s)\n");
    806  1.13      cgd 	for (i = 0, ks = &kmemstats[0]; i < M_LAST; i++, ks++) {
    807   1.1      cgd 		if (ks->ks_calls == 0)
    808   1.1      cgd 			continue;
    809  1.36       is 		(void)printf("%14s%6ld%6ldK%7ldK%6ldK%9ld%5u%6u",
    810   1.1      cgd 		    kmemnames[i] ? kmemnames[i] : "undefined",
    811   1.1      cgd 		    ks->ks_inuse, (ks->ks_memuse + 1023) / 1024,
    812   1.1      cgd 		    (ks->ks_maxused + 1023) / 1024,
    813   1.1      cgd 		    (ks->ks_limit + 1023) / 1024, ks->ks_calls,
    814   1.1      cgd 		    ks->ks_limblocks, ks->ks_mapblocks);
    815  1.13      cgd 		first = 1;
    816  1.13      cgd 		for (j =  1 << MINBUCKET; j < 1 << (MINBUCKET + 16); j <<= 1) {
    817  1.13      cgd 			if ((ks->ks_size & j) == 0)
    818  1.13      cgd 				continue;
    819  1.13      cgd 			if (first)
    820  1.13      cgd 				printf("  %d", j);
    821  1.13      cgd 			else
    822  1.13      cgd 				printf(",%d", j);
    823  1.13      cgd 			first = 0;
    824  1.13      cgd 		}
    825  1.13      cgd 		printf("\n");
    826   1.1      cgd 		totuse += ks->ks_memuse;
    827   1.1      cgd 		totreq += ks->ks_calls;
    828   1.1      cgd 	}
    829  1.13      cgd 	(void)printf("\nMemory Totals:  In Use    Free    Requests\n");
    830  1.13      cgd 	(void)printf("              %7ldK %6ldK    %8ld\n",
    831  1.13      cgd 	     (totuse + 1023) / 1024, (totfree + 1023) / 1024, totreq);
    832   1.1      cgd }
    833   1.1      cgd 
    834   1.1      cgd /*
    835   1.1      cgd  * kread reads something from the kernel, given its nlist index.
    836   1.1      cgd  */
    837   1.1      cgd void
    838   1.1      cgd kread(nlx, addr, size)
    839   1.1      cgd 	int nlx;
    840   1.1      cgd 	void *addr;
    841   1.1      cgd 	size_t size;
    842   1.1      cgd {
    843   1.1      cgd 	char *sym;
    844   1.1      cgd 
    845  1.13      cgd 	if (namelist[nlx].n_type == 0 || namelist[nlx].n_value == 0) {
    846  1.13      cgd 		sym = namelist[nlx].n_name;
    847   1.1      cgd 		if (*sym == '_')
    848   1.1      cgd 			++sym;
    849   1.1      cgd 		(void)fprintf(stderr,
    850  1.13      cgd 		    "vmstat: symbol %s not defined\n", sym);
    851   1.1      cgd 		exit(1);
    852   1.1      cgd 	}
    853  1.13      cgd 	if (kvm_read(kd, namelist[nlx].n_value, addr, size) != size) {
    854  1.13      cgd 		sym = namelist[nlx].n_name;
    855   1.1      cgd 		if (*sym == '_')
    856   1.1      cgd 			++sym;
    857  1.13      cgd 		(void)fprintf(stderr, "vmstat: %s: %s\n", sym, kvm_geterr(kd));
    858   1.1      cgd 		exit(1);
    859   1.1      cgd 	}
    860   1.1      cgd }
    861   1.1      cgd 
    862   1.1      cgd void
    863   1.1      cgd usage()
    864   1.1      cgd {
    865   1.1      cgd 	(void)fprintf(stderr,
    866   1.1      cgd 	    "usage: vmstat [-ims] [-c count] [-M core] \
    867   1.1      cgd [-N system] [-w wait] [disks]\n");
    868   1.1      cgd 	exit(1);
    869   1.1      cgd }
    870  1.18       pk 
    871