xref: /csrg-svn/usr.bin/vmstat/vmstat.c (revision 25512)
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*25512Ssam static char sccsid[] = "@(#)vmstat.c	5.3 (Berkeley) 11/20/85";
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>
241155Sbill #include <sys/dk.h>
253162Stoy #include <sys/buf.h>
2615807Smckusick #include <sys/dir.h>
2718761Ssam #include <sys/inode.h>
2817262Smckusick #include <sys/namei.h>
291155Sbill 
301155Sbill struct nlist nl[] = {
311448Sbill #define	X_CPTIME	0
321448Sbill 	{ "_cp_time" },
331448Sbill #define	X_RATE		1
341155Sbill 	{ "_rate" },
351448Sbill #define X_TOTAL		2
361155Sbill 	{ "_total" },
371448Sbill #define	X_DEFICIT	3
381155Sbill 	{ "_deficit" },
391448Sbill #define	X_FORKSTAT	4
401155Sbill 	{ "_forkstat" },
411448Sbill #define X_SUM		5
421155Sbill 	{ "_sum" },
431448Sbill #define	X_FIRSTFREE	6
441155Sbill 	{ "_firstfree" },
451448Sbill #define	X_MAXFREE	7
461155Sbill 	{ "_maxfree" },
479249Ssam #define	X_BOOTTIME	8
489249Ssam 	{ "_boottime" },
491448Sbill #define	X_DKXFER	9
501448Sbill 	{ "_dk_xfer" },
5110826Ssam #define X_REC		10
521155Sbill 	{ "_rectime" },
5310826Ssam #define X_PGIN		11
541155Sbill 	{ "_pgintime" },
5510826Ssam #define X_HZ		12
563162Stoy 	{ "_hz" },
5718761Ssam #define X_PHZ		13
5815266Ssam 	{ "_phz" },
5915807Smckusick #define X_NCHSTATS	14
6015807Smckusick 	{ "_nchstats" },
6117262Smckusick #define	X_INTRNAMES	15
6217262Smckusick 	{ "_intrnames" },
6317262Smckusick #define	X_EINTRNAMES	16
6417262Smckusick 	{ "_eintrnames" },
6517262Smckusick #define	X_INTRCNT	17
6617262Smckusick 	{ "_intrcnt" },
6717262Smckusick #define	X_EINTRCNT	18
6817262Smckusick 	{ "_eintrcnt" },
6918761Ssam #define	X_DK_NDRIVE	19
7018761Ssam 	{ "_dk_ndrive" },
71*25512Ssam #define	X_XSTATS	20
72*25512Ssam 	{ "_xstats" },
7310826Ssam #ifdef vax
74*25512Ssam #define X_MBDINIT	21
7510826Ssam 	{ "_mbdinit" },
76*25512Ssam #define X_UBDINIT	22
7710826Ssam 	{ "_ubdinit" },
7810826Ssam #endif
7910826Ssam 	{ "" },
801155Sbill };
811155Sbill 
8218761Ssam char	**dr_name;
8318761Ssam int	*dr_select;
8418761Ssam int	dk_ndrive;
8518761Ssam int	ndrives = 0;
8618761Ssam #ifdef vax
8718761Ssam char	*defdrives[] = { "hp0", "hp1", "hp2",  0 };
8818761Ssam #else
8918761Ssam char	*defdrives[] = { 0 };
9018761Ssam #endif
911155Sbill double	stat1();
921155Sbill int	firstfree, maxfree;
933162Stoy int	hz;
9415266Ssam int	phz;
9515266Ssam int	HZ;
9618761Ssam 
9715266Ssam #ifdef vax
9815266Ssam #define	INTS(x)	((x) - (hz + phz))
9915266Ssam #endif
10015266Ssam 
10118761Ssam struct {
1021155Sbill 	int	busy;
1031448Sbill 	long	time[CPUSTATES];
10418761Ssam 	long	*xfer;
1051155Sbill 	struct	vmmeter Rate;
1061155Sbill 	struct	vmtotal	Total;
1071155Sbill 	struct	vmmeter Sum;
1081155Sbill 	struct	forkstat Forkstat;
1091155Sbill 	unsigned rectime;
1101155Sbill 	unsigned pgintime;
1111155Sbill } s, s1, z;
1121155Sbill #define	rate		s.Rate
1131155Sbill #define	total		s.Total
1141155Sbill #define	sum		s.Sum
1151155Sbill #define	forkstat	s.Forkstat
1161155Sbill 
11710826Ssam struct	vmmeter osum;
1181155Sbill int	zero;
1191155Sbill int	deficit;
1201155Sbill double	etime;
1211155Sbill int 	mf;
12217262Smckusick time_t	now, boottime;
12317262Smckusick int	printhdr();
12418768Ssam int	lines = 1;
1251155Sbill 
1261155Sbill main(argc, argv)
12710826Ssam 	int argc;
12810826Ssam 	char **argv;
1291155Sbill {
1301155Sbill 	extern char *ctime();
1311155Sbill 	register i,j;
13217262Smckusick 	int iter, nintv, iflag = 0;
1331155Sbill 	double f1, f2;
1341155Sbill 	long t;
13518761Ssam 	char *arg, **cp, name[6], buf[BUFSIZ];
1361155Sbill 
1371155Sbill 	nlist("/vmunix", nl);
1381155Sbill 	if(nl[0].n_type == 0) {
1391155Sbill 		printf("no /vmunix namelist\n");
1401155Sbill 		exit(1);
1411155Sbill 	}
1421155Sbill 	mf = open("/dev/kmem", 0);
1431155Sbill 	if(mf < 0) {
1441155Sbill 		printf("cannot open /dev/kmem\n");
1451155Sbill 		exit(1);
1461155Sbill 	}
1471155Sbill 	iter = 0;
1481155Sbill 	argc--, argv++;
1491155Sbill 	while (argc>0 && argv[0][0]=='-') {
1501155Sbill 		char *cp = *argv++;
1511155Sbill 		argc--;
1521155Sbill 		while (*++cp) switch (*cp) {
1531155Sbill 
1541155Sbill 		case 't':
1551155Sbill 			dotimes();
1561155Sbill 			exit(0);
15710826Ssam 
1581155Sbill 		case 'z':
1591155Sbill 			close(mf);
1601155Sbill 			mf = open("/dev/kmem", 2);
16118761Ssam 			lseek(mf, (long)nl[X_SUM].n_value, L_SET);
1621155Sbill 			write(mf, &z.Sum, sizeof z.Sum);
1631155Sbill 			exit(0);
1641155Sbill 
1651155Sbill 		case 'f':
1661155Sbill 			doforkst();
1671155Sbill 			exit(0);
1681155Sbill 
1691155Sbill 		case 's':
1701155Sbill 			dosum();
1711155Sbill 			exit(0);
1721155Sbill 
17317262Smckusick 		case 'i':
17417262Smckusick 			iflag++;
17517262Smckusick 			break;
17617262Smckusick 
1771155Sbill 		default:
17818761Ssam 			fprintf(stderr,
17918761Ssam 			    "usage: vmstat [ -fsi ] [ interval ] [ count]\n");
1801155Sbill 			exit(1);
1811155Sbill 		}
1821155Sbill 	}
18318761Ssam 	lseek(mf, (long)nl[X_FIRSTFREE].n_value, L_SET);
1841155Sbill 	read(mf, &firstfree, sizeof firstfree);
18518761Ssam 	lseek(mf, (long)nl[X_MAXFREE].n_value, L_SET);
1861155Sbill 	read(mf, &maxfree, sizeof maxfree);
18718761Ssam 	lseek(mf, (long)nl[X_BOOTTIME].n_value, L_SET);
1889249Ssam 	read(mf, &boottime, sizeof boottime);
18918761Ssam 	lseek(mf, (long)nl[X_HZ].n_value, L_SET);
1903162Stoy 	read(mf, &hz, sizeof hz);
19118761Ssam 	if (nl[X_PHZ].n_value != 0) {
19218761Ssam 		lseek(mf, (long)nl[X_PHZ].n_value, L_SET);
19318761Ssam 		read(mf, &phz, sizeof phz);
19418761Ssam 	}
19515266Ssam 	HZ = phz ? phz : hz;
19618761Ssam 	if (nl[DK_NDRIVE].n_value == 0) {
19718761Ssam 		printf("dk_ndrive undefined in system\n");
19818761Ssam 		exit(1);
1993162Stoy 	}
20018761Ssam 	lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET);
20118761Ssam 	read(mf, &dk_ndrive, sizeof (dk_ndrive));
20218761Ssam 	if (dk_ndrive <= 0) {
20318761Ssam 		printf("dk_ndrive %d\n", dk_ndrive);
20418761Ssam 		exit(1);
20518761Ssam 	}
20618761Ssam 	dr_select = (int *)calloc(dk_ndrive, sizeof (int));
20718761Ssam 	dr_name = (char **)calloc(dk_ndrive, sizeof (char *));
20818761Ssam #define	allocate(e, t) \
20918761Ssam     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
21018761Ssam     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t));
21118761Ssam 	allocate(xfer, long);
21218761Ssam 	for (arg = buf, i = 0; i < dk_ndrive; i++) {
21318761Ssam 		dr_name[i] = arg;
21418761Ssam 		sprintf(dr_name[i], "dk%d", i);
21518761Ssam 		arg += strlen(dr_name[i]) + 1;
21618761Ssam 	}
2173162Stoy 	read_names();
2181155Sbill 	time(&now);
2199249Ssam 	nintv = now - boottime;
2201155Sbill 	if (nintv <= 0 || nintv > 60*60*24*365*10) {
2211155Sbill 		printf("Time makes no sense... namelist must be wrong.\n");
2221155Sbill 		exit(1);
2231155Sbill 	}
22417262Smckusick 	if (iflag) {
22517262Smckusick 		dointr(nintv);
22617262Smckusick 		exit(0);
22717262Smckusick 	}
22818761Ssam 	/*
22918761Ssam 	 * Choose drives to be displayed.  Priority
23018761Ssam 	 * goes to (in order) drives supplied as arguments,
23118761Ssam 	 * default drives.  If everything isn't filled
23218761Ssam 	 * in and there are drives not taken care of,
23318761Ssam 	 * display the first few that fit.
23418761Ssam 	 */
23518761Ssam 	ndrives = 0;
23618761Ssam 	while (argc > 0 && !isdigit(argv[0][0])) {
23718761Ssam 		for (i = 0; i < dk_ndrive; i++) {
23818761Ssam 			if (strcmp(dr_name[i], argv[0]))
23918761Ssam 				continue;
24018761Ssam 			dr_select[i] = 1;
24118761Ssam 			ndrives++;
24218761Ssam 		}
24318761Ssam 		argc--, argv++;
24418761Ssam 	}
24518761Ssam 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
24618761Ssam 		if (dr_select[i])
24718761Ssam 			continue;
24818761Ssam 		for (cp = defdrives; *cp; cp++)
24918761Ssam 			if (strcmp(dr_name[i], *cp) == 0) {
25018761Ssam 				dr_select[i] = 1;
25118761Ssam 				ndrives++;
25218761Ssam 				break;
25318761Ssam 			}
25418761Ssam 	}
25518761Ssam 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
25618761Ssam 		if (dr_select[i])
25718761Ssam 			continue;
25818761Ssam 		dr_select[i] = 1;
25918761Ssam 		ndrives++;
26018761Ssam 	}
26118761Ssam 	if (argc > 1)
26218761Ssam 		iter = atoi(argv[1]);
26317262Smckusick 	signal(SIGCONT, printhdr);
2641155Sbill loop:
26518768Ssam 	if (--lines == 0)
26618768Ssam 		printhdr();
26718761Ssam 	lseek(mf, (long)nl[X_CPTIME].n_value, L_SET);
2681448Sbill  	read(mf, s.time, sizeof s.time);
26918761Ssam 	lseek(mf, (long)nl[X_DKXFER].n_value, L_SET);
27018761Ssam 	read(mf, s.xfer, dk_ndrive * sizeof (long));
27118761Ssam 	if (nintv != 1)
27218761Ssam 		lseek(mf, (long)nl[X_SUM].n_value, L_SET);
27318761Ssam 	else
27418761Ssam 		lseek(mf, (long)nl[X_RATE].n_value, L_SET);
27518761Ssam 	read(mf, &rate, sizeof rate);
27618761Ssam 	lseek(mf, (long)nl[X_TOTAL].n_value, L_SET);
2771155Sbill 	read(mf, &total, sizeof total);
27810826Ssam 	osum = sum;
27918761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
28010826Ssam 	read(mf, &sum, sizeof sum);
28118761Ssam 	lseek(mf, (long)nl[X_DEFICIT].n_value, L_SET);
2821155Sbill 	read(mf, &deficit, sizeof deficit);
2831448Sbill 	etime = 0;
28418761Ssam 	for (i=0; i < dk_ndrive; i++) {
2851448Sbill 		t = s.xfer[i];
2861448Sbill 		s.xfer[i] -= s1.xfer[i];
2871448Sbill 		s1.xfer[i] = t;
2881155Sbill 	}
2891155Sbill 	for (i=0; i < CPUSTATES; i++) {
2901448Sbill 		t = s.time[i];
2911448Sbill 		s.time[i] -= s1.time[i];
2921448Sbill 		s1.time[i] = t;
2931448Sbill 		etime += s.time[i];
2941155Sbill 	}
2951155Sbill 	if(etime == 0.)
2961155Sbill 		etime = 1.;
2973162Stoy 	printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw);
29810826Ssam #define pgtok(a) ((a)*NBPG/1024)
29910826Ssam 	printf("%6d%5d", pgtok(total.t_avm), pgtok(total.t_free));
30015266Ssam 	printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv,
30115266Ssam 	    (rate.v_xsfrec+rate.v_xifrec)/nintv);
30210826Ssam 	printf("%4d", pgtok(rate.v_pgpgin)/nintv);
30310826Ssam 	printf("%4d%4d%4d%4d", pgtok(rate.v_pgpgout)/nintv,
30410826Ssam 	    pgtok(rate.v_dfree)/nintv, pgtok(deficit), rate.v_scan/nintv);
30518761Ssam 	etime /= (float)HZ;
30618761Ssam 	for (i = 0; i < dk_ndrive; i++)
30718761Ssam 		if (dr_select[i])
30818761Ssam 			stats(i);
30915266Ssam 	printf("%4d%4d%4d", INTS(rate.v_intr/nintv), rate.v_syscall/nintv,
31015266Ssam 	    rate.v_swtch/nintv);
3111155Sbill 	for(i=0; i<CPUSTATES; i++) {
3121155Sbill 		float f = stat1(i);
3131155Sbill 		if (i == 0) {		/* US+NI */
3141155Sbill 			i++;
3151155Sbill 			f += stat1(i);
3161155Sbill 		}
3171155Sbill 		printf("%3.0f", f);
3181155Sbill 	}
3191155Sbill 	printf("\n");
3201155Sbill 	fflush(stdout);
3211155Sbill contin:
3221155Sbill 	nintv = 1;
32318768Ssam 	if (--iter &&argc > 0) {
3241155Sbill 		sleep(atoi(argv[0]));
3251155Sbill 		goto loop;
3261155Sbill 	}
3271155Sbill }
3281155Sbill 
32917262Smckusick printhdr()
33017262Smckusick {
33118761Ssam 	register int i, j;
33218761Ssam 
33318761Ssam 	printf(" procs    memory              page           ");
33418761Ssam 	i = (ndrives * 3 - 6) / 2;
33518761Ssam 	if (i < 0)
33618761Ssam 		i = 0;
33718761Ssam 	for (j = 0; j < i; j++)
33818761Ssam 		putchar(' ');
33918761Ssam 	printf("faults");
34018761Ssam 	i = ndrives * 3 - 6 - i;
34118761Ssam 	for (j = 0; j < i; j++)
34218761Ssam 		putchar(' ');
34318761Ssam 	printf("               cpu\n");
34418761Ssam 	printf(" r b w   avm  fre  re at  pi  po  fr  de  sr ");
34518761Ssam 	for (i = 0; i < dk_ndrive; i++)
34618761Ssam 		if (dr_select[i])
34718761Ssam 			printf("%c%c ", dr_name[i][0], dr_name[i][2]);
34818761Ssam 	printf(" in  sy  cs us sy id\n");
34918768Ssam 	lines = 19;
35017262Smckusick }
35117262Smckusick 
3521155Sbill dotimes()
3531155Sbill {
3541155Sbill 
35518761Ssam 	lseek(mf, (long)nl[X_REC].n_value, L_SET);
3561155Sbill 	read(mf, &s.rectime, sizeof s.rectime);
35718761Ssam 	lseek(mf, (long)nl[X_PGIN].n_value, L_SET);
3581155Sbill 	read(mf, &s.pgintime, sizeof s.pgintime);
35918761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
3601155Sbill 	read(mf, &sum, sizeof sum);
3611155Sbill 	printf("%d reclaims, %d total time (usec)\n", sum.v_pgrec, s.rectime);
3621155Sbill 	printf("average: %d usec / reclaim\n", s.rectime/sum.v_pgrec);
3631155Sbill 	printf("\n");
3641155Sbill 	printf("%d page ins, %d total time (msec)\n",sum.v_pgin, s.pgintime/10);
3651155Sbill 	printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0));
3661155Sbill }
3671155Sbill 
368*25512Ssam /* SHOULD BE AVAILABLE IN <sys/text.h> */
369*25512Ssam /*
370*25512Ssam  * Statistics
371*25512Ssam  */
372*25512Ssam struct xstats {
373*25512Ssam 	u_long	alloc;			/* calls to xalloc */
374*25512Ssam 	u_long	alloc_inuse;		/*	found in use/sticky */
375*25512Ssam 	u_long	alloc_cachehit;		/*	found in cache */
376*25512Ssam 	u_long	alloc_cacheflush;	/*	flushed cached text */
377*25512Ssam 	u_long	alloc_unused;		/*	flushed unused cached text */
378*25512Ssam 	u_long	free;			/* calls to xfree */
379*25512Ssam 	u_long	free_inuse;		/*	still in use/sticky */
380*25512Ssam 	u_long	free_cache;		/*	placed in cache */
381*25512Ssam 	u_long	free_cacheswap;		/*	swapped out to place in cache */
382*25512Ssam };
383*25512Ssam /* END SHOULD BE AVAILABLE... */
384*25512Ssam 
3851155Sbill dosum()
3861155Sbill {
38718761Ssam 	struct nchstats nchstats;
388*25512Ssam 	struct xstats  xstats;
38915807Smckusick 	long nchtotal;
3901155Sbill 
39118761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
3921155Sbill 	read(mf, &sum, sizeof sum);
3931155Sbill 	printf("%9d swap ins\n", sum.v_swpin);
3941155Sbill 	printf("%9d swap outs\n", sum.v_swpout);
3951155Sbill 	printf("%9d pages swapped in\n", sum.v_pswpin / CLSIZE);
3961155Sbill 	printf("%9d pages swapped out\n", sum.v_pswpout / CLSIZE);
3971155Sbill 	printf("%9d total address trans. faults taken\n", sum.v_faults);
3981155Sbill 	printf("%9d page ins\n", sum.v_pgin);
3991155Sbill 	printf("%9d page outs\n", sum.v_pgout);
4003612Sroot 	printf("%9d pages paged in\n", sum.v_pgpgin);
4013612Sroot 	printf("%9d pages paged out\n", sum.v_pgpgout);
4023612Sroot 	printf("%9d sequential process pages freed\n", sum.v_seqfree);
40312830Ssam 	printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec,
40412830Ssam 	    (sum.v_fastpgrec * 100) / (sum.v_pgrec == 0 ? 1 : sum.v_pgrec));
4051155Sbill 	printf("%9d reclaims from free list\n", sum.v_pgfrec);
4061155Sbill 	printf("%9d intransit blocking page faults\n", sum.v_intrans);
4071155Sbill 	printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE);
4081155Sbill 	printf("%9d zero fill page faults\n", sum.v_zfod / CLSIZE);
4091155Sbill 	printf("%9d executable fill pages created\n", sum.v_nexfod / CLSIZE);
4101155Sbill 	printf("%9d executable fill page faults\n", sum.v_exfod / CLSIZE);
4111155Sbill 	printf("%9d swap text pages found in free list\n", sum.v_xsfrec);
4121155Sbill 	printf("%9d inode text pages found in free list\n", sum.v_xifrec);
4131155Sbill 	printf("%9d file fill pages created\n", sum.v_nvrfod / CLSIZE);
4141155Sbill 	printf("%9d file fill page faults\n", sum.v_vrfod / CLSIZE);
4151155Sbill 	printf("%9d pages examined by the clock daemon\n", sum.v_scan);
4161155Sbill 	printf("%9d revolutions of the clock hand\n", sum.v_rev);
4171155Sbill 	printf("%9d pages freed by the clock daemon\n", sum.v_dfree / CLSIZE);
4181155Sbill 	printf("%9d cpu context switches\n", sum.v_swtch);
4191155Sbill 	printf("%9d device interrupts\n", sum.v_intr);
42017262Smckusick 	printf("%9d software interrupts\n", sum.v_soft);
42118761Ssam #ifdef vax
42224429Smckusick 	printf("%9d pseudo-dma dz interrupts\n", sum.v_pdma);
42318761Ssam #endif
4241155Sbill 	printf("%9d traps\n", sum.v_trap);
4251155Sbill 	printf("%9d system calls\n", sum.v_syscall);
42615807Smckusick 	lseek(mf, (long)nl[X_NCHSTATS].n_value, 0);
42718761Ssam 	read(mf, &nchstats, sizeof nchstats);
42818761Ssam 	nchtotal = nchstats.ncs_goodhits + nchstats.ncs_badhits +
42918761Ssam 	    nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long;
43015807Smckusick 	printf("%9d total name lookups", nchtotal);
43116586Ssam #define	nz(x)	((x) ? (x) : 1)
43215807Smckusick 	printf(" (cache hits %d%% system %d%% per-process)\n",
43318761Ssam 	    nchstats.ncs_goodhits * 100 / nz(nchtotal),
43418761Ssam 	    nchstats.ncs_pass2 * 100 / nz(nchtotal));
43516586Ssam 	printf("%9s badhits %d, falsehits %d, toolong %d\n", "",
43618761Ssam 	    nchstats.ncs_badhits, nchstats.ncs_falsehits, nchstats.ncs_long);
437*25512Ssam 	lseek(mf, (long)nl[X_XSTATS].n_value, 0);
438*25512Ssam 	read(mf, &xstats, sizeof xstats);
439*25512Ssam 	printf("%9d total calls to xalloc (cache hits %d%%)\n",
440*25512Ssam 	    xstats.alloc, xstats.alloc_cachehit * 100 / nz(xstats.alloc));
441*25512Ssam 	printf("%9s sticky %d flushed %d unused %d\n", "",
442*25512Ssam 	    xstats.alloc_inuse, xstats.alloc_cacheflush, xstats.alloc_unused);
443*25512Ssam 	printf("%9d total calls to xfree", xstats.free);
444*25512Ssam 	printf(" (sticky %d cached %d swapped %d)\n",
445*25512Ssam 	    xstats.free_inuse, xstats.free_cache, xstats.free_cacheswap);
4461155Sbill }
4471155Sbill 
4481155Sbill doforkst()
4491155Sbill {
4501155Sbill 
45118761Ssam 	lseek(mf, (long)nl[X_FORKSTAT].n_value, L_SET);
4521155Sbill 	read(mf, &forkstat, sizeof forkstat);
4531155Sbill 	printf("%d forks, %d pages, average=%.2f\n",
4541155Sbill 		forkstat.cntfork, forkstat.sizfork,
4551155Sbill 		(float) forkstat.sizfork / forkstat.cntfork);
4561155Sbill 	printf("%d vforks, %d pages, average=%.2f\n",
4571155Sbill 		forkstat.cntvfork, forkstat.sizvfork,
4581155Sbill 		(float)forkstat.sizvfork / forkstat.cntvfork);
4591155Sbill }
4601155Sbill 
4611155Sbill stats(dn)
4621155Sbill {
4631155Sbill 
46418761Ssam 	if (dn >= dk_ndrive) {
4651155Sbill 		printf("  0");
4661155Sbill 		return;
4671155Sbill 	}
4681448Sbill 	printf("%3.0f", s.xfer[dn]/etime);
4691155Sbill }
4701155Sbill 
4711155Sbill double
4721155Sbill stat1(row)
4731155Sbill {
4741448Sbill 	double t;
4751448Sbill 	register i;
4761155Sbill 
4771155Sbill 	t = 0;
4781155Sbill 	for(i=0; i<CPUSTATES; i++)
4791448Sbill 		t += s.time[i];
4801448Sbill 	if(t == 0.)
4811448Sbill 		t = 1.;
4821448Sbill 	return(s.time[row]*100./t);
4831155Sbill }
4841155Sbill 
4851155Sbill pct(top, bot)
4861155Sbill {
4871155Sbill 
4881155Sbill 	if (bot == 0)
4891155Sbill 		return (0);
4901155Sbill 	return ((top * 100) / bot);
4911155Sbill }
4923162Stoy 
49317262Smckusick dointr(nintv)
49417262Smckusick {
49517262Smckusick 	int nintr, inttotal;
49617262Smckusick 	long *intrcnt;
49717262Smckusick 	char *intrname, *malloc();
49817262Smckusick 
49917262Smckusick 	nintr = (nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value) / sizeof(long);
50017262Smckusick 	intrcnt = (long *) malloc(nl[X_EINTRCNT].n_value -
50117262Smckusick 		nl[X_INTRCNT].n_value);
50217262Smckusick 	intrname = malloc(nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value);
50317262Smckusick 	if (intrcnt == NULL || intrname == NULL) {
50417262Smckusick 		fprintf(stderr, "vmstat: out of memory\n");
50517262Smckusick 		exit(9);
50617262Smckusick 	}
50718761Ssam 	lseek(mf, (long)nl[X_INTRCNT].n_value, L_SET);
50817262Smckusick 	read(mf, intrcnt, nintr * sizeof (long));
50918761Ssam 	lseek(mf, (long)nl[X_INTRNAMES].n_value, L_SET);
51017262Smckusick 	read(mf, intrname, nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value);
51117262Smckusick 	printf("interrupt      total      rate\n");
51217262Smckusick 	inttotal = 0;
51317262Smckusick 	while (nintr--) {
51417262Smckusick 		if (*intrcnt)
51517262Smckusick 			printf("%-12s %8ld %8ld\n", intrname,
51617262Smckusick 			    *intrcnt, *intrcnt / nintv);
51717262Smckusick 		intrname += strlen(intrname) + 1;
51817262Smckusick 		inttotal += *intrcnt++;
51917262Smckusick 	}
52017262Smckusick 	printf("Total        %8ld %8ld\n", inttotal, inttotal / nintv);
52117262Smckusick }
52217262Smckusick 
52318761Ssam #define steal(where, var) \
52418761Ssam 	lseek(mf, where, L_SET); read(mf, &var, sizeof var);
5253162Stoy /*
5263162Stoy  * Read the drive names out of kmem.
5273162Stoy  */
52810826Ssam #ifdef vax
52918761Ssam #include <vaxuba/ubavar.h>
53018761Ssam #include <vaxmba/mbavar.h>
53118761Ssam 
5323162Stoy read_names()
5333162Stoy {
5343162Stoy 	struct mba_device mdev;
5353162Stoy 	register struct mba_device *mp;
5363162Stoy 	struct mba_driver mdrv;
5373162Stoy 	short two_char;
5383162Stoy 	char *cp = (char *) &two_char;
5393162Stoy 	struct uba_device udev, *up;
5403162Stoy 	struct uba_driver udrv;
5413162Stoy 
5423162Stoy 	mp = (struct mba_device *) nl[X_MBDINIT].n_value;
5433162Stoy 	up = (struct uba_device *) nl[X_UBDINIT].n_value;
5443492Sroot 	if (up == 0) {
54510826Ssam 		fprintf(stderr, "vmstat: Disk init info not in namelist\n");
5463162Stoy 		exit(1);
5473162Stoy 	}
5483492Sroot 	if (mp) for (;;) {
5493162Stoy 		steal(mp++, mdev);
5503162Stoy 		if (mdev.mi_driver == 0)
5513162Stoy 			break;
5523162Stoy 		if (mdev.mi_dk < 0 || mdev.mi_alive == 0)
5533162Stoy 			continue;
5543162Stoy 		steal(mdev.mi_driver, mdrv);
5553162Stoy 		steal(mdrv.md_dname, two_char);
55618761Ssam 		sprintf(dr_name[mdev.mi_dk], "%c%c%d",
55718761Ssam 		    cp[0], cp[1], mdev.mi_unit);
5583162Stoy 	}
5593492Sroot 	for (;;) {
5603162Stoy 		steal(up++, udev);
5613162Stoy 		if (udev.ui_driver == 0)
5623162Stoy 			break;
5633162Stoy 		if (udev.ui_dk < 0 || udev.ui_alive == 0)
5643162Stoy 			continue;
5653162Stoy 		steal(udev.ui_driver, udrv);
5663162Stoy 		steal(udrv.ud_dname, two_char);
56718761Ssam 		sprintf(dr_name[udev.ui_dk], "%c%c%d",
56818761Ssam 		    cp[0], cp[1], udev.ui_unit);
5693162Stoy 	}
5703162Stoy }
57110826Ssam #endif
572