xref: /csrg-svn/usr.bin/vmstat/vmstat.c (revision 24429)
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*24429Smckusick static char sccsid[] = "@(#)vmstat.c	5.2 (Berkeley) 08/26/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" },
7110826Ssam #ifdef vax
7218761Ssam #define X_MBDINIT	20
7310826Ssam 	{ "_mbdinit" },
7418761Ssam #define X_UBDINIT	21
7510826Ssam 	{ "_ubdinit" },
7610826Ssam #endif
7710826Ssam 	{ "" },
781155Sbill };
791155Sbill 
8018761Ssam char	**dr_name;
8118761Ssam int	*dr_select;
8218761Ssam int	dk_ndrive;
8318761Ssam int	ndrives = 0;
8418761Ssam #ifdef vax
8518761Ssam char	*defdrives[] = { "hp0", "hp1", "hp2",  0 };
8618761Ssam #else
8718761Ssam char	*defdrives[] = { 0 };
8818761Ssam #endif
891155Sbill double	stat1();
901155Sbill int	firstfree, maxfree;
913162Stoy int	hz;
9215266Ssam int	phz;
9315266Ssam int	HZ;
9418761Ssam 
9515266Ssam #ifdef vax
9615266Ssam #define	INTS(x)	((x) - (hz + phz))
9715266Ssam #endif
9815266Ssam 
9918761Ssam struct {
1001155Sbill 	int	busy;
1011448Sbill 	long	time[CPUSTATES];
10218761Ssam 	long	*xfer;
1031155Sbill 	struct	vmmeter Rate;
1041155Sbill 	struct	vmtotal	Total;
1051155Sbill 	struct	vmmeter Sum;
1061155Sbill 	struct	forkstat Forkstat;
1071155Sbill 	unsigned rectime;
1081155Sbill 	unsigned pgintime;
1091155Sbill } s, s1, z;
1101155Sbill #define	rate		s.Rate
1111155Sbill #define	total		s.Total
1121155Sbill #define	sum		s.Sum
1131155Sbill #define	forkstat	s.Forkstat
1141155Sbill 
11510826Ssam struct	vmmeter osum;
1161155Sbill int	zero;
1171155Sbill int	deficit;
1181155Sbill double	etime;
1191155Sbill int 	mf;
12017262Smckusick time_t	now, boottime;
12117262Smckusick int	printhdr();
12218768Ssam int	lines = 1;
1231155Sbill 
1241155Sbill main(argc, argv)
12510826Ssam 	int argc;
12610826Ssam 	char **argv;
1271155Sbill {
1281155Sbill 	extern char *ctime();
1291155Sbill 	register i,j;
13017262Smckusick 	int iter, nintv, iflag = 0;
1311155Sbill 	double f1, f2;
1321155Sbill 	long t;
13318761Ssam 	char *arg, **cp, name[6], buf[BUFSIZ];
1341155Sbill 
1351155Sbill 	nlist("/vmunix", nl);
1361155Sbill 	if(nl[0].n_type == 0) {
1371155Sbill 		printf("no /vmunix namelist\n");
1381155Sbill 		exit(1);
1391155Sbill 	}
1401155Sbill 	mf = open("/dev/kmem", 0);
1411155Sbill 	if(mf < 0) {
1421155Sbill 		printf("cannot open /dev/kmem\n");
1431155Sbill 		exit(1);
1441155Sbill 	}
1451155Sbill 	iter = 0;
1461155Sbill 	argc--, argv++;
1471155Sbill 	while (argc>0 && argv[0][0]=='-') {
1481155Sbill 		char *cp = *argv++;
1491155Sbill 		argc--;
1501155Sbill 		while (*++cp) switch (*cp) {
1511155Sbill 
1521155Sbill 		case 't':
1531155Sbill 			dotimes();
1541155Sbill 			exit(0);
15510826Ssam 
1561155Sbill 		case 'z':
1571155Sbill 			close(mf);
1581155Sbill 			mf = open("/dev/kmem", 2);
15918761Ssam 			lseek(mf, (long)nl[X_SUM].n_value, L_SET);
1601155Sbill 			write(mf, &z.Sum, sizeof z.Sum);
1611155Sbill 			exit(0);
1621155Sbill 
1631155Sbill 		case 'f':
1641155Sbill 			doforkst();
1651155Sbill 			exit(0);
1661155Sbill 
1671155Sbill 		case 's':
1681155Sbill 			dosum();
1691155Sbill 			exit(0);
1701155Sbill 
17117262Smckusick 		case 'i':
17217262Smckusick 			iflag++;
17317262Smckusick 			break;
17417262Smckusick 
1751155Sbill 		default:
17618761Ssam 			fprintf(stderr,
17718761Ssam 			    "usage: vmstat [ -fsi ] [ interval ] [ count]\n");
1781155Sbill 			exit(1);
1791155Sbill 		}
1801155Sbill 	}
18118761Ssam 	lseek(mf, (long)nl[X_FIRSTFREE].n_value, L_SET);
1821155Sbill 	read(mf, &firstfree, sizeof firstfree);
18318761Ssam 	lseek(mf, (long)nl[X_MAXFREE].n_value, L_SET);
1841155Sbill 	read(mf, &maxfree, sizeof maxfree);
18518761Ssam 	lseek(mf, (long)nl[X_BOOTTIME].n_value, L_SET);
1869249Ssam 	read(mf, &boottime, sizeof boottime);
18718761Ssam 	lseek(mf, (long)nl[X_HZ].n_value, L_SET);
1883162Stoy 	read(mf, &hz, sizeof hz);
18918761Ssam 	if (nl[X_PHZ].n_value != 0) {
19018761Ssam 		lseek(mf, (long)nl[X_PHZ].n_value, L_SET);
19118761Ssam 		read(mf, &phz, sizeof phz);
19218761Ssam 	}
19315266Ssam 	HZ = phz ? phz : hz;
19418761Ssam 	if (nl[DK_NDRIVE].n_value == 0) {
19518761Ssam 		printf("dk_ndrive undefined in system\n");
19618761Ssam 		exit(1);
1973162Stoy 	}
19818761Ssam 	lseek(mf, nl[X_DK_NDRIVE].n_value, L_SET);
19918761Ssam 	read(mf, &dk_ndrive, sizeof (dk_ndrive));
20018761Ssam 	if (dk_ndrive <= 0) {
20118761Ssam 		printf("dk_ndrive %d\n", dk_ndrive);
20218761Ssam 		exit(1);
20318761Ssam 	}
20418761Ssam 	dr_select = (int *)calloc(dk_ndrive, sizeof (int));
20518761Ssam 	dr_name = (char **)calloc(dk_ndrive, sizeof (char *));
20618761Ssam #define	allocate(e, t) \
20718761Ssam     s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
20818761Ssam     s1./**/e = (t *)calloc(dk_ndrive, sizeof (t));
20918761Ssam 	allocate(xfer, long);
21018761Ssam 	for (arg = buf, i = 0; i < dk_ndrive; i++) {
21118761Ssam 		dr_name[i] = arg;
21218761Ssam 		sprintf(dr_name[i], "dk%d", i);
21318761Ssam 		arg += strlen(dr_name[i]) + 1;
21418761Ssam 	}
2153162Stoy 	read_names();
2161155Sbill 	time(&now);
2179249Ssam 	nintv = now - boottime;
2181155Sbill 	if (nintv <= 0 || nintv > 60*60*24*365*10) {
2191155Sbill 		printf("Time makes no sense... namelist must be wrong.\n");
2201155Sbill 		exit(1);
2211155Sbill 	}
22217262Smckusick 	if (iflag) {
22317262Smckusick 		dointr(nintv);
22417262Smckusick 		exit(0);
22517262Smckusick 	}
22618761Ssam 	/*
22718761Ssam 	 * Choose drives to be displayed.  Priority
22818761Ssam 	 * goes to (in order) drives supplied as arguments,
22918761Ssam 	 * default drives.  If everything isn't filled
23018761Ssam 	 * in and there are drives not taken care of,
23118761Ssam 	 * display the first few that fit.
23218761Ssam 	 */
23318761Ssam 	ndrives = 0;
23418761Ssam 	while (argc > 0 && !isdigit(argv[0][0])) {
23518761Ssam 		for (i = 0; i < dk_ndrive; i++) {
23618761Ssam 			if (strcmp(dr_name[i], argv[0]))
23718761Ssam 				continue;
23818761Ssam 			dr_select[i] = 1;
23918761Ssam 			ndrives++;
24018761Ssam 		}
24118761Ssam 		argc--, argv++;
24218761Ssam 	}
24318761Ssam 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
24418761Ssam 		if (dr_select[i])
24518761Ssam 			continue;
24618761Ssam 		for (cp = defdrives; *cp; cp++)
24718761Ssam 			if (strcmp(dr_name[i], *cp) == 0) {
24818761Ssam 				dr_select[i] = 1;
24918761Ssam 				ndrives++;
25018761Ssam 				break;
25118761Ssam 			}
25218761Ssam 	}
25318761Ssam 	for (i = 0; i < dk_ndrive && ndrives < 4; i++) {
25418761Ssam 		if (dr_select[i])
25518761Ssam 			continue;
25618761Ssam 		dr_select[i] = 1;
25718761Ssam 		ndrives++;
25818761Ssam 	}
25918761Ssam 	if (argc > 1)
26018761Ssam 		iter = atoi(argv[1]);
26117262Smckusick 	signal(SIGCONT, printhdr);
2621155Sbill loop:
26318768Ssam 	if (--lines == 0)
26418768Ssam 		printhdr();
26518761Ssam 	lseek(mf, (long)nl[X_CPTIME].n_value, L_SET);
2661448Sbill  	read(mf, s.time, sizeof s.time);
26718761Ssam 	lseek(mf, (long)nl[X_DKXFER].n_value, L_SET);
26818761Ssam 	read(mf, s.xfer, dk_ndrive * sizeof (long));
26918761Ssam 	if (nintv != 1)
27018761Ssam 		lseek(mf, (long)nl[X_SUM].n_value, L_SET);
27118761Ssam 	else
27218761Ssam 		lseek(mf, (long)nl[X_RATE].n_value, L_SET);
27318761Ssam 	read(mf, &rate, sizeof rate);
27418761Ssam 	lseek(mf, (long)nl[X_TOTAL].n_value, L_SET);
2751155Sbill 	read(mf, &total, sizeof total);
27610826Ssam 	osum = sum;
27718761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
27810826Ssam 	read(mf, &sum, sizeof sum);
27918761Ssam 	lseek(mf, (long)nl[X_DEFICIT].n_value, L_SET);
2801155Sbill 	read(mf, &deficit, sizeof deficit);
2811448Sbill 	etime = 0;
28218761Ssam 	for (i=0; i < dk_ndrive; i++) {
2831448Sbill 		t = s.xfer[i];
2841448Sbill 		s.xfer[i] -= s1.xfer[i];
2851448Sbill 		s1.xfer[i] = t;
2861155Sbill 	}
2871155Sbill 	for (i=0; i < CPUSTATES; i++) {
2881448Sbill 		t = s.time[i];
2891448Sbill 		s.time[i] -= s1.time[i];
2901448Sbill 		s1.time[i] = t;
2911448Sbill 		etime += s.time[i];
2921155Sbill 	}
2931155Sbill 	if(etime == 0.)
2941155Sbill 		etime = 1.;
2953162Stoy 	printf("%2d%2d%2d", total.t_rq, total.t_dw+total.t_pw, total.t_sw);
29610826Ssam #define pgtok(a) ((a)*NBPG/1024)
29710826Ssam 	printf("%6d%5d", pgtok(total.t_avm), pgtok(total.t_free));
29815266Ssam 	printf("%4d%3d", (rate.v_pgrec - (rate.v_xsfrec+rate.v_xifrec))/nintv,
29915266Ssam 	    (rate.v_xsfrec+rate.v_xifrec)/nintv);
30010826Ssam 	printf("%4d", pgtok(rate.v_pgpgin)/nintv);
30110826Ssam 	printf("%4d%4d%4d%4d", pgtok(rate.v_pgpgout)/nintv,
30210826Ssam 	    pgtok(rate.v_dfree)/nintv, pgtok(deficit), rate.v_scan/nintv);
30318761Ssam 	etime /= (float)HZ;
30418761Ssam 	for (i = 0; i < dk_ndrive; i++)
30518761Ssam 		if (dr_select[i])
30618761Ssam 			stats(i);
30715266Ssam 	printf("%4d%4d%4d", INTS(rate.v_intr/nintv), rate.v_syscall/nintv,
30815266Ssam 	    rate.v_swtch/nintv);
3091155Sbill 	for(i=0; i<CPUSTATES; i++) {
3101155Sbill 		float f = stat1(i);
3111155Sbill 		if (i == 0) {		/* US+NI */
3121155Sbill 			i++;
3131155Sbill 			f += stat1(i);
3141155Sbill 		}
3151155Sbill 		printf("%3.0f", f);
3161155Sbill 	}
3171155Sbill 	printf("\n");
3181155Sbill 	fflush(stdout);
3191155Sbill contin:
3201155Sbill 	nintv = 1;
32118768Ssam 	if (--iter &&argc > 0) {
3221155Sbill 		sleep(atoi(argv[0]));
3231155Sbill 		goto loop;
3241155Sbill 	}
3251155Sbill }
3261155Sbill 
32717262Smckusick printhdr()
32817262Smckusick {
32918761Ssam 	register int i, j;
33018761Ssam 
33118761Ssam 	printf(" procs    memory              page           ");
33218761Ssam 	i = (ndrives * 3 - 6) / 2;
33318761Ssam 	if (i < 0)
33418761Ssam 		i = 0;
33518761Ssam 	for (j = 0; j < i; j++)
33618761Ssam 		putchar(' ');
33718761Ssam 	printf("faults");
33818761Ssam 	i = ndrives * 3 - 6 - i;
33918761Ssam 	for (j = 0; j < i; j++)
34018761Ssam 		putchar(' ');
34118761Ssam 	printf("               cpu\n");
34218761Ssam 	printf(" r b w   avm  fre  re at  pi  po  fr  de  sr ");
34318761Ssam 	for (i = 0; i < dk_ndrive; i++)
34418761Ssam 		if (dr_select[i])
34518761Ssam 			printf("%c%c ", dr_name[i][0], dr_name[i][2]);
34618761Ssam 	printf(" in  sy  cs us sy id\n");
34718768Ssam 	lines = 19;
34817262Smckusick }
34917262Smckusick 
3501155Sbill dotimes()
3511155Sbill {
3521155Sbill 
35318761Ssam 	lseek(mf, (long)nl[X_REC].n_value, L_SET);
3541155Sbill 	read(mf, &s.rectime, sizeof s.rectime);
35518761Ssam 	lseek(mf, (long)nl[X_PGIN].n_value, L_SET);
3561155Sbill 	read(mf, &s.pgintime, sizeof s.pgintime);
35718761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
3581155Sbill 	read(mf, &sum, sizeof sum);
3591155Sbill 	printf("%d reclaims, %d total time (usec)\n", sum.v_pgrec, s.rectime);
3601155Sbill 	printf("average: %d usec / reclaim\n", s.rectime/sum.v_pgrec);
3611155Sbill 	printf("\n");
3621155Sbill 	printf("%d page ins, %d total time (msec)\n",sum.v_pgin, s.pgintime/10);
3631155Sbill 	printf("average: %8.1f msec / page in\n", s.pgintime/(sum.v_pgin*10.0));
3641155Sbill }
3651155Sbill 
3661155Sbill dosum()
3671155Sbill {
36818761Ssam 	struct nchstats nchstats;
36915807Smckusick 	long nchtotal;
3701155Sbill 
37118761Ssam 	lseek(mf, (long)nl[X_SUM].n_value, L_SET);
3721155Sbill 	read(mf, &sum, sizeof sum);
3731155Sbill 	printf("%9d swap ins\n", sum.v_swpin);
3741155Sbill 	printf("%9d swap outs\n", sum.v_swpout);
3751155Sbill 	printf("%9d pages swapped in\n", sum.v_pswpin / CLSIZE);
3761155Sbill 	printf("%9d pages swapped out\n", sum.v_pswpout / CLSIZE);
3771155Sbill 	printf("%9d total address trans. faults taken\n", sum.v_faults);
3781155Sbill 	printf("%9d page ins\n", sum.v_pgin);
3791155Sbill 	printf("%9d page outs\n", sum.v_pgout);
3803612Sroot 	printf("%9d pages paged in\n", sum.v_pgpgin);
3813612Sroot 	printf("%9d pages paged out\n", sum.v_pgpgout);
3823612Sroot 	printf("%9d sequential process pages freed\n", sum.v_seqfree);
38312830Ssam 	printf("%9d total reclaims (%d%% fast)\n", sum.v_pgrec,
38412830Ssam 	    (sum.v_fastpgrec * 100) / (sum.v_pgrec == 0 ? 1 : sum.v_pgrec));
3851155Sbill 	printf("%9d reclaims from free list\n", sum.v_pgfrec);
3861155Sbill 	printf("%9d intransit blocking page faults\n", sum.v_intrans);
3871155Sbill 	printf("%9d zero fill pages created\n", sum.v_nzfod / CLSIZE);
3881155Sbill 	printf("%9d zero fill page faults\n", sum.v_zfod / CLSIZE);
3891155Sbill 	printf("%9d executable fill pages created\n", sum.v_nexfod / CLSIZE);
3901155Sbill 	printf("%9d executable fill page faults\n", sum.v_exfod / CLSIZE);
3911155Sbill 	printf("%9d swap text pages found in free list\n", sum.v_xsfrec);
3921155Sbill 	printf("%9d inode text pages found in free list\n", sum.v_xifrec);
3931155Sbill 	printf("%9d file fill pages created\n", sum.v_nvrfod / CLSIZE);
3941155Sbill 	printf("%9d file fill page faults\n", sum.v_vrfod / CLSIZE);
3951155Sbill 	printf("%9d pages examined by the clock daemon\n", sum.v_scan);
3961155Sbill 	printf("%9d revolutions of the clock hand\n", sum.v_rev);
3971155Sbill 	printf("%9d pages freed by the clock daemon\n", sum.v_dfree / CLSIZE);
3981155Sbill 	printf("%9d cpu context switches\n", sum.v_swtch);
3991155Sbill 	printf("%9d device interrupts\n", sum.v_intr);
40017262Smckusick 	printf("%9d software interrupts\n", sum.v_soft);
40118761Ssam #ifdef vax
402*24429Smckusick 	printf("%9d pseudo-dma dz interrupts\n", sum.v_pdma);
40318761Ssam #endif
4041155Sbill 	printf("%9d traps\n", sum.v_trap);
4051155Sbill 	printf("%9d system calls\n", sum.v_syscall);
40615807Smckusick 	lseek(mf, (long)nl[X_NCHSTATS].n_value, 0);
40718761Ssam 	read(mf, &nchstats, sizeof nchstats);
40818761Ssam 	nchtotal = nchstats.ncs_goodhits + nchstats.ncs_badhits +
40918761Ssam 	    nchstats.ncs_falsehits + nchstats.ncs_miss + nchstats.ncs_long;
41015807Smckusick 	printf("%9d total name lookups", nchtotal);
41116586Ssam #define	nz(x)	((x) ? (x) : 1)
41215807Smckusick 	printf(" (cache hits %d%% system %d%% per-process)\n",
41318761Ssam 	    nchstats.ncs_goodhits * 100 / nz(nchtotal),
41418761Ssam 	    nchstats.ncs_pass2 * 100 / nz(nchtotal));
41516586Ssam 	printf("%9s badhits %d, falsehits %d, toolong %d\n", "",
41618761Ssam 	    nchstats.ncs_badhits, nchstats.ncs_falsehits, nchstats.ncs_long);
4171155Sbill }
4181155Sbill 
4191155Sbill doforkst()
4201155Sbill {
4211155Sbill 
42218761Ssam 	lseek(mf, (long)nl[X_FORKSTAT].n_value, L_SET);
4231155Sbill 	read(mf, &forkstat, sizeof forkstat);
4241155Sbill 	printf("%d forks, %d pages, average=%.2f\n",
4251155Sbill 		forkstat.cntfork, forkstat.sizfork,
4261155Sbill 		(float) forkstat.sizfork / forkstat.cntfork);
4271155Sbill 	printf("%d vforks, %d pages, average=%.2f\n",
4281155Sbill 		forkstat.cntvfork, forkstat.sizvfork,
4291155Sbill 		(float)forkstat.sizvfork / forkstat.cntvfork);
4301155Sbill }
4311155Sbill 
4321155Sbill stats(dn)
4331155Sbill {
4341155Sbill 
43518761Ssam 	if (dn >= dk_ndrive) {
4361155Sbill 		printf("  0");
4371155Sbill 		return;
4381155Sbill 	}
4391448Sbill 	printf("%3.0f", s.xfer[dn]/etime);
4401155Sbill }
4411155Sbill 
4421155Sbill double
4431155Sbill stat1(row)
4441155Sbill {
4451448Sbill 	double t;
4461448Sbill 	register i;
4471155Sbill 
4481155Sbill 	t = 0;
4491155Sbill 	for(i=0; i<CPUSTATES; i++)
4501448Sbill 		t += s.time[i];
4511448Sbill 	if(t == 0.)
4521448Sbill 		t = 1.;
4531448Sbill 	return(s.time[row]*100./t);
4541155Sbill }
4551155Sbill 
4561155Sbill pct(top, bot)
4571155Sbill {
4581155Sbill 
4591155Sbill 	if (bot == 0)
4601155Sbill 		return (0);
4611155Sbill 	return ((top * 100) / bot);
4621155Sbill }
4633162Stoy 
46417262Smckusick dointr(nintv)
46517262Smckusick {
46617262Smckusick 	int nintr, inttotal;
46717262Smckusick 	long *intrcnt;
46817262Smckusick 	char *intrname, *malloc();
46917262Smckusick 
47017262Smckusick 	nintr = (nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value) / sizeof(long);
47117262Smckusick 	intrcnt = (long *) malloc(nl[X_EINTRCNT].n_value -
47217262Smckusick 		nl[X_INTRCNT].n_value);
47317262Smckusick 	intrname = malloc(nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value);
47417262Smckusick 	if (intrcnt == NULL || intrname == NULL) {
47517262Smckusick 		fprintf(stderr, "vmstat: out of memory\n");
47617262Smckusick 		exit(9);
47717262Smckusick 	}
47818761Ssam 	lseek(mf, (long)nl[X_INTRCNT].n_value, L_SET);
47917262Smckusick 	read(mf, intrcnt, nintr * sizeof (long));
48018761Ssam 	lseek(mf, (long)nl[X_INTRNAMES].n_value, L_SET);
48117262Smckusick 	read(mf, intrname, nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value);
48217262Smckusick 	printf("interrupt      total      rate\n");
48317262Smckusick 	inttotal = 0;
48417262Smckusick 	while (nintr--) {
48517262Smckusick 		if (*intrcnt)
48617262Smckusick 			printf("%-12s %8ld %8ld\n", intrname,
48717262Smckusick 			    *intrcnt, *intrcnt / nintv);
48817262Smckusick 		intrname += strlen(intrname) + 1;
48917262Smckusick 		inttotal += *intrcnt++;
49017262Smckusick 	}
49117262Smckusick 	printf("Total        %8ld %8ld\n", inttotal, inttotal / nintv);
49217262Smckusick }
49317262Smckusick 
49418761Ssam #define steal(where, var) \
49518761Ssam 	lseek(mf, where, L_SET); read(mf, &var, sizeof var);
4963162Stoy /*
4973162Stoy  * Read the drive names out of kmem.
4983162Stoy  */
49910826Ssam #ifdef vax
50018761Ssam #include <vaxuba/ubavar.h>
50118761Ssam #include <vaxmba/mbavar.h>
50218761Ssam 
5033162Stoy read_names()
5043162Stoy {
5053162Stoy 	struct mba_device mdev;
5063162Stoy 	register struct mba_device *mp;
5073162Stoy 	struct mba_driver mdrv;
5083162Stoy 	short two_char;
5093162Stoy 	char *cp = (char *) &two_char;
5103162Stoy 	struct uba_device udev, *up;
5113162Stoy 	struct uba_driver udrv;
5123162Stoy 
5133162Stoy 	mp = (struct mba_device *) nl[X_MBDINIT].n_value;
5143162Stoy 	up = (struct uba_device *) nl[X_UBDINIT].n_value;
5153492Sroot 	if (up == 0) {
51610826Ssam 		fprintf(stderr, "vmstat: Disk init info not in namelist\n");
5173162Stoy 		exit(1);
5183162Stoy 	}
5193492Sroot 	if (mp) for (;;) {
5203162Stoy 		steal(mp++, mdev);
5213162Stoy 		if (mdev.mi_driver == 0)
5223162Stoy 			break;
5233162Stoy 		if (mdev.mi_dk < 0 || mdev.mi_alive == 0)
5243162Stoy 			continue;
5253162Stoy 		steal(mdev.mi_driver, mdrv);
5263162Stoy 		steal(mdrv.md_dname, two_char);
52718761Ssam 		sprintf(dr_name[mdev.mi_dk], "%c%c%d",
52818761Ssam 		    cp[0], cp[1], mdev.mi_unit);
5293162Stoy 	}
5303492Sroot 	for (;;) {
5313162Stoy 		steal(up++, udev);
5323162Stoy 		if (udev.ui_driver == 0)
5333162Stoy 			break;
5343162Stoy 		if (udev.ui_dk < 0 || udev.ui_alive == 0)
5353162Stoy 			continue;
5363162Stoy 		steal(udev.ui_driver, udrv);
5373162Stoy 		steal(udrv.ud_dname, two_char);
53818761Ssam 		sprintf(dr_name[udev.ui_dk], "%c%c%d",
53918761Ssam 		    cp[0], cp[1], udev.ui_unit);
5403162Stoy 	}
5413162Stoy }
54210826Ssam #endif
543