xref: /csrg-svn/usr.bin/vmstat/vmstat.c (revision 29664)
121585Sdist /*
221585Sdist  * Copyright (c) 1980 Regents of the University of California.
321585Sdist  * All rights reserved.  The Berkeley software License Agreement
421585Sdist  * specifies the terms and conditions for redistribution.
521585Sdist  */
621585Sdist 
710826Ssam #ifndef lint
821585Sdist char copyright[] =
921585Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1021585Sdist  All rights reserved.\n";
1121585Sdist #endif not lint
1210826Ssam 
1321585Sdist #ifndef lint
14*29664Ssam static char sccsid[] = "@(#)vmstat.c	5.6 (Berkeley) 07/25/86";
1521585Sdist #endif not lint
1621585Sdist 
171155Sbill #include <stdio.h>
1818761Ssam #include <ctype.h>
1918761Ssam #include <nlist.h>
2018761Ssam 
211155Sbill #include <sys/param.h>
2218761Ssam #include <sys/file.h>
231155Sbill #include <sys/vm.h>
24*29664Ssam #include <sys/dkstat.h>
253162Stoy #include <sys/buf.h>
2615807Smckusick #include <sys/dir.h>
2718761Ssam #include <sys/inode.h>
2817262Smckusick #include <sys/namei.h>
2925708Ssam #include <sys/text.h>
301155Sbill 
311155Sbill struct nlist nl[] = {
321448Sbill #define	X_CPTIME	0
331448Sbill 	{ "_cp_time" },
341448Sbill #define	X_RATE		1
351155Sbill 	{ "_rate" },
361448Sbill #define X_TOTAL		2
371155Sbill 	{ "_total" },
381448Sbill #define	X_DEFICIT	3
391155Sbill 	{ "_deficit" },
401448Sbill #define	X_FORKSTAT	4
411155Sbill 	{ "_forkstat" },
421448Sbill #define X_SUM		5
431155Sbill 	{ "_sum" },
441448Sbill #define	X_FIRSTFREE	6
451155Sbill 	{ "_firstfree" },
461448Sbill #define	X_MAXFREE	7
471155Sbill 	{ "_maxfree" },
489249Ssam #define	X_BOOTTIME	8
499249Ssam 	{ "_boottime" },
501448Sbill #define	X_DKXFER	9
511448Sbill 	{ "_dk_xfer" },
5210826Ssam #define X_REC		10
531155Sbill 	{ "_rectime" },
5410826Ssam #define X_PGIN		11
551155Sbill 	{ "_pgintime" },
5610826Ssam #define X_HZ		12
573162Stoy 	{ "_hz" },
5818761Ssam #define X_PHZ		13
5915266Ssam 	{ "_phz" },
6015807Smckusick #define X_NCHSTATS	14
6115807Smckusick 	{ "_nchstats" },
6217262Smckusick #define	X_INTRNAMES	15
6317262Smckusick 	{ "_intrnames" },
6417262Smckusick #define	X_EINTRNAMES	16
6517262Smckusick 	{ "_eintrnames" },
6617262Smckusick #define	X_INTRCNT	17
6717262Smckusick 	{ "_intrcnt" },
6817262Smckusick #define	X_EINTRCNT	18
6917262Smckusick 	{ "_eintrcnt" },
7018761Ssam #define	X_DK_NDRIVE	19
7118761Ssam 	{ "_dk_ndrive" },
7225512Ssam #define	X_XSTATS	20
7325512Ssam 	{ "_xstats" },
7410826Ssam #ifdef vax
7525708Ssam #define X_MBDINIT	(X_XSTATS+1)
7610826Ssam 	{ "_mbdinit" },
7725708Ssam #define X_UBDINIT	(X_XSTATS+2)
7810826Ssam 	{ "_ubdinit" },
7910826Ssam #endif
8025708Ssam #ifdef tahoe
8125708Ssam #define	X_VBDINIT	(X_XSTATS+1)
8225708Ssam 	{ "_vbdinit" },
8325960Ssam #define	X_CKEYSTATS	(X_XSTATS+2)
8425960Ssam 	{ "_ckeystats" },
8525960Ssam #define	X_DKEYSTATS	(X_XSTATS+3)
8625960Ssam 	{ "_dkeystats" },
8725708Ssam #endif
8810826Ssam 	{ "" },
891155Sbill };
901155Sbill 
9118761Ssam char	**dr_name;
9218761Ssam int	*dr_select;
9318761Ssam int	dk_ndrive;
9418761Ssam int	ndrives = 0;
9518761Ssam #ifdef vax
9618761Ssam char	*defdrives[] = { "hp0", "hp1", "hp2",  0 };
9718761Ssam #else
9818761Ssam char	*defdrives[] = { 0 };
9918761Ssam #endif
1001155Sbill double	stat1();
1011155Sbill int	firstfree, maxfree;
1023162Stoy int	hz;
10315266Ssam int	phz;
10415266Ssam int	HZ;
10518761Ssam 
10618761Ssam struct {
1071155Sbill 	int	busy;
1081448Sbill 	long	time[CPUSTATES];
10918761Ssam 	long	*xfer;
1101155Sbill 	struct	vmmeter Rate;
1111155Sbill 	struct	vmtotal	Total;
1121155Sbill 	struct	vmmeter Sum;
1131155Sbill 	struct	forkstat Forkstat;
1141155Sbill 	unsigned rectime;
1151155Sbill 	unsigned pgintime;
1161155Sbill } s, s1, z;
1171155Sbill #define	rate		s.Rate
1181155Sbill #define	total		s.Total
1191155Sbill #define	sum		s.Sum
1201155Sbill #define	forkstat	s.Forkstat
1211155Sbill 
12210826Ssam struct	vmmeter osum;
1231155Sbill int	deficit;
1241155Sbill double	etime;
1251155Sbill int 	mf;
12617262Smckusick time_t	now, boottime;
12717262Smckusick int	printhdr();
12818768Ssam int	lines = 1;
1291155Sbill 
130*29664Ssam #define	INTS(x)	((x) - (hz + phz))
131*29664Ssam 
1321155Sbill main(argc, argv)
13310826Ssam 	int argc;
13410826Ssam 	char **argv;
1351155Sbill {
1361155Sbill 	extern char *ctime();
137*29664Ssam 	register i;
13817262Smckusick 	int iter, nintv, iflag = 0;
1391155Sbill 	long t;
140*29664Ssam 	char *arg, **cp, buf[BUFSIZ];
1411155Sbill 
1421155Sbill 	nlist("/vmunix", nl);
1431155Sbill 	if(nl[0].n_type == 0) {
144*29664Ssam 		fprintf(stderr, "no /vmunix namelist\n");
1451155Sbill 		exit(1);
1461155Sbill 	}
1471155Sbill 	mf = open("/dev/kmem", 0);
1481155Sbill 	if(mf < 0) {
149*29664Ssam 		fprintf(stderr, "cannot open /dev/kmem\n");
1501155Sbill 		exit(1);
1511155Sbill 	}
1521155Sbill 	iter = 0;
1531155Sbill 	argc--, argv++;
1541155Sbill 	while (argc>0 && argv[0][0]=='-') {
1551155Sbill 		char *cp = *argv++;
1561155Sbill 		argc--;
1571155Sbill 		while (*++cp) switch (*cp) {
1581155Sbill 
1591155Sbill 		case 't':
1601155Sbill 			dotimes();
1611155Sbill 			exit(0);
16210826Ssam 
1631155Sbill 		case 'z':
1641155Sbill 			close(mf);
1651155Sbill 			mf = open("/dev/kmem", 2);
16618761Ssam 			lseek(mf, (long)nl[X_SUM].n_value, L_SET);
1671155Sbill 			write(mf, &z.Sum, sizeof z.Sum);
1681155Sbill 			exit(0);
1691155Sbill 
1701155Sbill 		case 'f':
1711155Sbill 			doforkst();
1721155Sbill 			exit(0);
1731155Sbill 
1741155Sbill 		case 's':
1751155Sbill 			dosum();
1761155Sbill 			exit(0);
1771155Sbill 
17817262Smckusick 		case 'i':
17917262Smckusick 			iflag++;
18017262Smckusick 			break;
18117262Smckusick 
1821155Sbill 		default:
18318761Ssam 			fprintf(stderr,
18418761Ssam 			    "usage: vmstat [ -fsi ] [ interval ] [ count]\n");
1851155Sbill 			exit(1);
1861155Sbill 		}
1871155Sbill 	}
18818761Ssam 	lseek(mf, (long)nl[X_FIRSTFREE].n_value, L_SET);
1891155Sbill 	read(mf, &firstfree, sizeof firstfree);
19018761Ssam 	lseek(mf, (long)nl[X_MAXFREE].n_value, L_SET);
1911155Sbill 	read(mf, &maxfree, sizeof maxfree);
19218761Ssam 	lseek(mf, (long)nl[X_BOOTTIME].n_value, L_SET);
1939249Ssam 	read(mf, &boottime, sizeof boottime);
19418761Ssam 	lseek(mf, (long)nl[X_HZ].n_value, L_SET);
1953162Stoy 	read(mf, &hz, sizeof hz);
19618761Ssam 	if (nl[X_PHZ].n_value != 0) {
19718761Ssam 		lseek(mf, (long)nl[X_PHZ].n_value, L_SET);
19818761Ssam 		read(mf, &phz, sizeof phz);
19918761Ssam 	}
20015266Ssam 	HZ = phz ? phz : hz;
20118761Ssam 	if (nl[DK_NDRIVE].n_value == 0) {
202*29664Ssam 		fprintf(stderr, "dk_ndrive undefined in system\n");
20318761Ssam 		exit(1);
2043162Stoy 	}
20518761Ssam 	lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET);
20618761Ssam 	read(mf, &dk_ndrive, sizeof (dk_ndrive));
20718761Ssam 	if (dk_ndrive <= 0) {
208*29664Ssam 		fprintf(stderr, "dk_ndrive %d\n", dk_ndrive);
20918761Ssam 		exit(1);
21018761Ssam 	}
21118761Ssam 	dr_select = (int *)calloc(dk_ndrive, sizeof (int));
21218761Ssam 	dr_name = (char **)calloc(dk_ndrive, sizeof (char *));
21318761Ssam #define	allocate(e, t) \
21418761Ssam     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
21518761Ssam     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t));
21618761Ssam 	allocate(xfer, long);
21718761Ssam 	for (arg = buf, i = 0; i < dk_ndrive; i++) {
21818761Ssam 		dr_name[i] = arg;
21918761Ssam 		sprintf(dr_name[i], "dk%d", i);
22018761Ssam 		arg += strlen(dr_name[i]) + 1;
22118761Ssam 	}
2223162Stoy 	read_names();
2231155Sbill 	time(&now);
2249249Ssam 	nintv = now - boottime;
2251155Sbill 	if (nintv <= 0 || nintv > 60*60*24*365*10) {
226*29664Ssam 		fprintf(stderr,
227*29664Ssam 		    "Time makes no sense... namelist must be wrong.\n");
2281155Sbill 		exit(1);
2291155Sbill 	}
23017262Smckusick 	if (iflag) {
23117262Smckusick 		dointr(nintv);
23217262Smckusick 		exit(0);
23317262Smckusick 	}
23418761Ssam 	/*
23518761Ssam 	 * Choose drives to be displayed.  Priority
23618761Ssam 	 * goes to (in order) drives supplied as arguments,
23718761Ssam 	 * default drives.  If everything isn't filled
23818761Ssam 	 * in and there are drives not taken care of,
23918761Ssam 	 * display the first few that fit.
24018761Ssam 	 */
24118761Ssam 	ndrives = 0;
24218761Ssam 	while (argc > 0 && !isdigit(argv[0][0])) {
24318761Ssam 		for (i = 0; i < dk_ndrive; i++) {
24418761Ssam 			if (strcmp(dr_name[i], argv[0]))
24518761Ssam 				continue;
24618761Ssam 			dr_select[i] = 1;
24718761Ssam 			ndrives++;
24818761Ssam 		}
24918761Ssam 		argc--, argv++;
25018761Ssam 	}
25118761Ssam 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
25218761Ssam 		if (dr_select[i])
25318761Ssam 			continue;
25418761Ssam 		for (cp = defdrives; *cp; cp++)
25518761Ssam 			if (strcmp(dr_name[i], *cp) == 0) {
25618761Ssam 				dr_select[i] = 1;
25718761Ssam 				ndrives++;
25818761Ssam 				break;
25918761Ssam 			}
26018761Ssam 	}
26118761Ssam 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
26218761Ssam 		if (dr_select[i])
26318761Ssam 			continue;
26418761Ssam 		dr_select[i] = 1;
26518761Ssam 		ndrives++;
26618761Ssam 	}
26718761Ssam 	if (argc > 1)
26818761Ssam 		iter = atoi(argv[1]);
26917262Smckusick 	signal(SIGCONT, printhdr);
2701155Sbill loop:
27118768Ssam 	if (--lines == 0)
27218768Ssam 		printhdr();
27318761Ssam 	lseek(mf, (long)nl[X_CPTIME].n_value, L_SET);
2741448Sbill  	read(mf, s.time, sizeof s.time);
27518761Ssam 	lseek(mf, (long)nl[X_DKXFER].n_value, L_SET);
27618761Ssam 	read(mf, s.xfer, dk_ndrive * sizeof (long));
27718761Ssam 	if (nintv != 1)
27818761Ssam 		lseek(mf, (long)nl[X_SUM].n_value, L_SET);
27918761Ssam 	else
28018761Ssam 		lseek(mf, (long)nl[X_RATE].n_value, L_SET);
28118761Ssam 	read(mf, &rate, sizeof rate);
28218761Ssam 	lseek(mf, (long)nl[X_TOTAL].n_value, L_SET);
2831155Sbill 	read(mf, &total, sizeof total);
28410826Ssam 	osum = sum;
28518761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
28610826Ssam 	read(mf, &sum, sizeof sum);
28718761Ssam 	lseek(mf, (long)nl[X_DEFICIT].n_value, L_SET);
2881155Sbill 	read(mf, &deficit, sizeof deficit);
2891448Sbill 	etime = 0;
29018761Ssam 	for (i=0; i < dk_ndrive; i++) {
2911448Sbill 		t = s.xfer[i];
2921448Sbill 		s.xfer[i] -= s1.xfer[i];
2931448Sbill 		s1.xfer[i] = t;
2941155Sbill 	}
2951155Sbill 	for (i=0; i < CPUSTATES; i++) {
2961448Sbill 		t = s.time[i];
2971448Sbill 		s.time[i] -= s1.time[i];
2981448Sbill 		s1.time[i] = t;
2991448Sbill 		etime += s.time[i];
3001155Sbill 	}
3011155Sbill 	if(etime == 0.)
3021155Sbill 		etime = 1.;
3033162Stoy 	printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw);
30410826Ssam #define pgtok(a) ((a)*NBPG/1024)
305*29664Ssam 	printf("%6d%6d", pgtok(total.t_avm), pgtok(total.t_free));
30615266Ssam 	printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv,
30715266Ssam 	    (rate.v_xsfrec+rate.v_xifrec)/nintv);
30810826Ssam 	printf("%4d", pgtok(rate.v_pgpgin)/nintv);
30910826Ssam 	printf("%4d%4d%4d%4d", pgtok(rate.v_pgpgout)/nintv,
31010826Ssam 	    pgtok(rate.v_dfree)/nintv, pgtok(deficit), rate.v_scan/nintv);
31118761Ssam 	etime /= (float)HZ;
31218761Ssam 	for (i = 0; i < dk_ndrive; i++)
31318761Ssam 		if (dr_select[i])
31418761Ssam 			stats(i);
31515266Ssam 	printf("%4d%4d%4d", INTS(rate.v_intr/nintv), rate.v_syscall/nintv,
31615266Ssam 	    rate.v_swtch/nintv);
3171155Sbill 	for(i=0; i<CPUSTATES; i++) {
3181155Sbill 		float f = stat1(i);
3191155Sbill 		if (i == 0) {		/* US+NI */
3201155Sbill 			i++;
3211155Sbill 			f += stat1(i);
3221155Sbill 		}
3231155Sbill 		printf("%3.0f", f);
3241155Sbill 	}
3251155Sbill 	printf("\n");
3261155Sbill 	fflush(stdout);
3271155Sbill 	nintv = 1;
32818768Ssam 	if (--iter &&argc > 0) {
3291155Sbill 		sleep(atoi(argv[0]));
3301155Sbill 		goto loop;
3311155Sbill 	}
3321155Sbill }
3331155Sbill 
33417262Smckusick printhdr()
33517262Smckusick {
33618761Ssam 	register int i, j;
33718761Ssam 
338*29664Ssam 	printf(" procs     memory              page           ");
33918761Ssam 	i = (ndrives * 3 - 6) / 2;
34018761Ssam 	if (i < 0)
34118761Ssam 		i = 0;
34218761Ssam 	for (j = 0; j < i; j++)
34318761Ssam 		putchar(' ');
34418761Ssam 	printf("faults");
34518761Ssam 	i = ndrives * 3 - 6 - i;
34618761Ssam 	for (j = 0; j < i; j++)
34718761Ssam 		putchar(' ');
34818761Ssam 	printf("               cpu\n");
349*29664Ssam 	printf(" r b w   avm   fre  re at  pi  po  fr  de  sr ");
35018761Ssam 	for (i = 0; i < dk_ndrive; i++)
35118761Ssam 		if (dr_select[i])
35218761Ssam 			printf("%c%c ", dr_name[i][0], dr_name[i][2]);
35318761Ssam 	printf(" in  sy  cs us sy id\n");
35418768Ssam 	lines = 19;
35517262Smckusick }
35617262Smckusick 
3571155Sbill dotimes()
3581155Sbill {
3591155Sbill 
36018761Ssam 	lseek(mf, (long)nl[X_REC].n_value, L_SET);
3611155Sbill 	read(mf, &s.rectime, sizeof s.rectime);
36218761Ssam 	lseek(mf, (long)nl[X_PGIN].n_value, L_SET);
3631155Sbill 	read(mf, &s.pgintime, sizeof s.pgintime);
36418761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
3651155Sbill 	read(mf, &sum, sizeof sum);
3661155Sbill 	printf("%d reclaims, %d total time (usec)\n", sum.v_pgrec, s.rectime);
3671155Sbill 	printf("average: %d usec / reclaim\n", s.rectime/sum.v_pgrec);
3681155Sbill 	printf("\n");
3691155Sbill 	printf("%d page ins, %d total time (msec)\n",sum.v_pgin, s.pgintime/10);
3701155Sbill 	printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0));
3711155Sbill }
3721155Sbill 
3731155Sbill dosum()
3741155Sbill {
37518761Ssam 	struct nchstats nchstats;
37625960Ssam 	struct xstats xstats;
37715807Smckusick 	long nchtotal;
37825960Ssam #if defined(tahoe)
37925960Ssam 	struct keystats keystats;
38025960Ssam #endif
3811155Sbill 
38218761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
3831155Sbill 	read(mf, &sum, sizeof sum);
3841155Sbill 	printf("%9d swap ins\n", sum.v_swpin);
3851155Sbill 	printf("%9d swap outs\n", sum.v_swpout);
3861155Sbill 	printf("%9d pages swapped in\n", sum.v_pswpin / CLSIZE);
3871155Sbill 	printf("%9d pages swapped out\n", sum.v_pswpout / CLSIZE);
3881155Sbill 	printf("%9d total address trans. faults taken\n", sum.v_faults);
3891155Sbill 	printf("%9d page ins\n", sum.v_pgin);
3901155Sbill 	printf("%9d page outs\n", sum.v_pgout);
3913612Sroot 	printf("%9d pages paged in\n", sum.v_pgpgin);
3923612Sroot 	printf("%9d pages paged out\n", sum.v_pgpgout);
3933612Sroot 	printf("%9d sequential process pages freed\n", sum.v_seqfree);
39412830Ssam 	printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec,
395*29664Ssam 	    pct(sum.v_fastpgrec, sum.v_pgrec));
3961155Sbill 	printf("%9d reclaims from free list\n", sum.v_pgfrec);
3971155Sbill 	printf("%9d intransit blocking page faults\n", sum.v_intrans);
3981155Sbill 	printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE);
3991155Sbill 	printf("%9d zero fill page faults\n", sum.v_zfod / CLSIZE);
4001155Sbill 	printf("%9d executable fill pages created\n", sum.v_nexfod / CLSIZE);
4011155Sbill 	printf("%9d executable fill page faults\n", sum.v_exfod / CLSIZE);
4021155Sbill 	printf("%9d swap text pages found in free list\n", sum.v_xsfrec);
4031155Sbill 	printf("%9d inode text pages found in free list\n", sum.v_xifrec);
4041155Sbill 	printf("%9d file fill pages created\n", sum.v_nvrfod / CLSIZE);
4051155Sbill 	printf("%9d file fill page faults\n", sum.v_vrfod / CLSIZE);
4061155Sbill 	printf("%9d pages examined by the clock daemon\n", sum.v_scan);
4071155Sbill 	printf("%9d revolutions of the clock hand\n", sum.v_rev);
4081155Sbill 	printf("%9d pages freed by the clock daemon\n", sum.v_dfree / CLSIZE);
4091155Sbill 	printf("%9d cpu context switches\n", sum.v_swtch);
4101155Sbill 	printf("%9d device interrupts\n", sum.v_intr);
41117262Smckusick 	printf("%9d software interrupts\n", sum.v_soft);
41218761Ssam #ifdef vax
41324429Smckusick 	printf("%9d pseudo-dma dz interrupts\n", sum.v_pdma);
41418761Ssam #endif
4151155Sbill 	printf("%9d traps\n", sum.v_trap);
4161155Sbill 	printf("%9d system calls\n", sum.v_syscall);
41715807Smckusick 	lseek(mf, (long)nl[X_NCHSTATS].n_value, 0);
41818761Ssam 	read(mf, &nchstats, sizeof nchstats);
41918761Ssam 	nchtotal = nchstats.ncs_goodhits + nchstats.ncs_badhits +
42018761Ssam 	    nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long;
42115807Smckusick 	printf("%9d total name lookups", nchtotal);
42215807Smckusick 	printf(" (cache hits %d%% system %d%% per-process)\n",
423*29664Ssam 	    pct(nchstats.ncs_goodhits, nchtotal),
424*29664Ssam 	    pct(nchstats.ncs_pass2, nchtotal));
42516586Ssam 	printf("%9s badhits %d, falsehits %d, toolong %d\n", "",
42618761Ssam 	    nchstats.ncs_badhits, nchstats.ncs_falsehits, nchstats.ncs_long);
42725512Ssam 	lseek(mf, (long)nl[X_XSTATS].n_value, 0);
42825512Ssam 	read(mf, &xstats, sizeof xstats);
42925512Ssam 	printf("%9d total calls to xalloc (cache hits %d%%)\n",
430*29664Ssam 	    xstats.alloc, pct(xstats.alloc_cachehit, xstats.alloc));
43125512Ssam 	printf("%9s sticky %d flushed %d unused %d\n", "",
43225512Ssam 	    xstats.alloc_inuse, xstats.alloc_cacheflush, xstats.alloc_unused);
43325512Ssam 	printf("%9d total calls to xfree", xstats.free);
43425512Ssam 	printf(" (sticky %d cached %d swapped %d)\n",
43525512Ssam 	    xstats.free_inuse, xstats.free_cache, xstats.free_cacheswap);
43625960Ssam #if defined(tahoe)
43725960Ssam 	lseek(mf, (long)nl[X_CKEYSTATS].n_value, 0);
43825960Ssam 	read(mf, &keystats, sizeof keystats);
43925960Ssam 	printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
44025960Ssam 	    keystats.ks_allocs, "code cache keys allocated",
441*29664Ssam 	    pct(keystats.ks_free, keystats.ks_allocs),
442*29664Ssam 	    pct(keystats.ks_norefs, keystats.ks_allocs),
443*29664Ssam 	    pct(keystats.ks_taken, keystats.ks_allocs),
444*29664Ssam 	    pct(keystats.ks_shared, keystats.ks_allocs));
44525960Ssam 	lseek(mf, (long)nl[X_DKEYSTATS].n_value, 0);
44625960Ssam 	read(mf, &keystats, sizeof keystats);
44725960Ssam 	printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
44825960Ssam 	    keystats.ks_allocs, "data cache keys allocated",
449*29664Ssam 	    pct(keystats.ks_free, keystats.ks_allocs),
450*29664Ssam 	    pct(keystats.ks_norefs, keystats.ks_allocs),
451*29664Ssam 	    pct(keystats.ks_taken, keystats.ks_allocs),
452*29664Ssam 	    pct(keystats.ks_shared, keystats.ks_allocs));
45325960Ssam #endif
4541155Sbill }
4551155Sbill 
4561155Sbill doforkst()
4571155Sbill {
4581155Sbill 
45918761Ssam 	lseek(mf, (long)nl[X_FORKSTAT].n_value, L_SET);
4601155Sbill 	read(mf, &forkstat, sizeof forkstat);
4611155Sbill 	printf("%d forks, %d pages, average=%.2f\n",
4621155Sbill 		forkstat.cntfork, forkstat.sizfork,
4631155Sbill 		(float) forkstat.sizfork / forkstat.cntfork);
4641155Sbill 	printf("%d vforks, %d pages, average=%.2f\n",
4651155Sbill 		forkstat.cntvfork, forkstat.sizvfork,
4661155Sbill 		(float)forkstat.sizvfork / forkstat.cntvfork);
4671155Sbill }
4681155Sbill 
4691155Sbill stats(dn)
4701155Sbill {
4711155Sbill 
47218761Ssam 	if (dn >= dk_ndrive) {
4731155Sbill 		printf("  0");
4741155Sbill 		return;
4751155Sbill 	}
4761448Sbill 	printf("%3.0f", s.xfer[dn]/etime);
4771155Sbill }
4781155Sbill 
4791155Sbill double
4801155Sbill stat1(row)
4811155Sbill {
4821448Sbill 	double t;
4831448Sbill 	register i;
4841155Sbill 
4851155Sbill 	t = 0;
4861155Sbill 	for(i=0; i<CPUSTATES; i++)
4871448Sbill 		t += s.time[i];
4881448Sbill 	if(t == 0.)
4891448Sbill 		t = 1.;
4901448Sbill 	return(s.time[row]*100./t);
4911155Sbill }
4921155Sbill 
4931155Sbill pct(top, bot)
4941155Sbill {
4951155Sbill 
4961155Sbill 	if (bot == 0)
4971155Sbill 		return (0);
4981155Sbill 	return ((top * 100) / bot);
4991155Sbill }
5003162Stoy 
50117262Smckusick dointr(nintv)
50217262Smckusick {
50317262Smckusick 	int nintr, inttotal;
50417262Smckusick 	long *intrcnt;
50517262Smckusick 	char *intrname, *malloc();
50617262Smckusick 
50717262Smckusick 	nintr = (nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value) / sizeof(long);
50817262Smckusick 	intrcnt = (long *) malloc(nl[X_EINTRCNT].n_value -
50917262Smckusick 		nl[X_INTRCNT].n_value);
51017262Smckusick 	intrname = malloc(nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value);
51117262Smckusick 	if (intrcnt == NULL || intrname == NULL) {
51217262Smckusick 		fprintf(stderr, "vmstat: out of memory\n");
51317262Smckusick 		exit(9);
51417262Smckusick 	}
51518761Ssam 	lseek(mf, (long)nl[X_INTRCNT].n_value, L_SET);
51617262Smckusick 	read(mf, intrcnt, nintr * sizeof (long));
51718761Ssam 	lseek(mf, (long)nl[X_INTRNAMES].n_value, L_SET);
51817262Smckusick 	read(mf, intrname, nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value);
51917262Smckusick 	printf("interrupt      total      rate\n");
52017262Smckusick 	inttotal = 0;
52117262Smckusick 	while (nintr--) {
52217262Smckusick 		if (*intrcnt)
52317262Smckusick 			printf("%-12s %8ld %8ld\n", intrname,
52417262Smckusick 			    *intrcnt, *intrcnt / nintv);
52517262Smckusick 		intrname += strlen(intrname) + 1;
52617262Smckusick 		inttotal += *intrcnt++;
52717262Smckusick 	}
52817262Smckusick 	printf("Total        %8ld %8ld\n", inttotal, inttotal / nintv);
52917262Smckusick }
53017262Smckusick 
53118761Ssam #define steal(where, var) \
53218761Ssam 	lseek(mf, where, L_SET); read(mf, &var, sizeof var);
5333162Stoy /*
5343162Stoy  * Read the drive names out of kmem.
5353162Stoy  */
53610826Ssam #ifdef vax
53718761Ssam #include <vaxuba/ubavar.h>
53818761Ssam #include <vaxmba/mbavar.h>
53918761Ssam 
5403162Stoy read_names()
5413162Stoy {
5423162Stoy 	struct mba_device mdev;
5433162Stoy 	register struct mba_device *mp;
5443162Stoy 	struct mba_driver mdrv;
5453162Stoy 	short two_char;
5463162Stoy 	char *cp = (char *) &two_char;
5473162Stoy 	struct uba_device udev, *up;
5483162Stoy 	struct uba_driver udrv;
5493162Stoy 
5503162Stoy 	mp = (struct mba_device *) nl[X_MBDINIT].n_value;
5513162Stoy 	up = (struct uba_device *) nl[X_UBDINIT].n_value;
5523492Sroot 	if (up == 0) {
55310826Ssam 		fprintf(stderr, "vmstat: Disk init info not in namelist\n");
5543162Stoy 		exit(1);
5553162Stoy 	}
5563492Sroot 	if (mp) for (;;) {
5573162Stoy 		steal(mp++, mdev);
5583162Stoy 		if (mdev.mi_driver == 0)
5593162Stoy 			break;
5603162Stoy 		if (mdev.mi_dk < 0 || mdev.mi_alive == 0)
5613162Stoy 			continue;
5623162Stoy 		steal(mdev.mi_driver, mdrv);
5633162Stoy 		steal(mdrv.md_dname, two_char);
56418761Ssam 		sprintf(dr_name[mdev.mi_dk], "%c%c%d",
56518761Ssam 		    cp[0], cp[1], mdev.mi_unit);
5663162Stoy 	}
5673492Sroot 	for (;;) {
5683162Stoy 		steal(up++, udev);
5693162Stoy 		if (udev.ui_driver == 0)
5703162Stoy 			break;
5713162Stoy 		if (udev.ui_dk < 0 || udev.ui_alive == 0)
5723162Stoy 			continue;
5733162Stoy 		steal(udev.ui_driver, udrv);
5743162Stoy 		steal(udrv.ud_dname, two_char);
57518761Ssam 		sprintf(dr_name[udev.ui_dk], "%c%c%d",
57618761Ssam 		    cp[0], cp[1], udev.ui_unit);
5773162Stoy 	}
5783162Stoy }
57910826Ssam #endif
58025708Ssam 
58125708Ssam #ifdef tahoe
58225708Ssam #include <tahoevba/vbavar.h>
58325708Ssam 
58425708Ssam /*
58525708Ssam  * Read the drive names out of kmem.
58625708Ssam  */
58725708Ssam read_names()
58825708Ssam {
58925708Ssam 	struct vba_device udev, *up;
59025708Ssam 	struct vba_driver udrv;
59125708Ssam 	short two_char;
59225708Ssam 	char *cp = (char *)&two_char;
59325708Ssam 
59425708Ssam 	up = (struct vba_device *) nl[X_VBDINIT].n_value;
59525708Ssam 	if (up == 0) {
59625708Ssam 		fprintf(stderr, "vmstat: Disk init info not in namelist\n");
59725708Ssam 		exit(1);
59825708Ssam 	}
59925708Ssam 	for (;;) {
60025708Ssam 		steal(up++, udev);
60125708Ssam 		if (udev.ui_driver == 0)
60225708Ssam 			break;
60325708Ssam 		if (udev.ui_dk < 0 || udev.ui_alive == 0)
60425708Ssam 			continue;
60525708Ssam 		steal(udev.ui_driver, udrv);
60625708Ssam 		steal(udrv.ud_dname, two_char);
60725708Ssam 		sprintf(dr_name[udev.ui_dk], "%c%c%d",
60825708Ssam 		     cp[0], cp[1], udev.ui_unit);
60925708Ssam 	}
61025708Ssam }
61125708Ssam #endif
612