vmstat.c revision 51421
11590Srgrimes/*-
21590Srgrimes * Copyright (c) 1983, 1989, 1992, 1993
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * Redistribution and use in source and binary forms, with or without
61590Srgrimes * modification, are permitted provided that the following conditions
71590Srgrimes * are met:
81590Srgrimes * 1. Redistributions of source code must retain the above copyright
91590Srgrimes *    notice, this list of conditions and the following disclaimer.
101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer in the
121590Srgrimes *    documentation and/or other materials provided with the distribution.
131590Srgrimes * 3. All advertising materials mentioning features or use of this software
141590Srgrimes *    must display the following acknowledgement:
151590Srgrimes *	This product includes software developed by the University of
161590Srgrimes *	California, Berkeley and its contributors.
171590Srgrimes * 4. Neither the name of the University nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
321590Srgrimes */
331590Srgrimes
341590Srgrimes#ifndef lint
3528149Scharnier#if 0
361590Srgrimesstatic char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 1/12/94";
3728149Scharnier#endif
3828149Scharnierstatic const char rcsid[] =
3950477Speter  "$FreeBSD: head/usr.bin/systat/vmstat.c 51421 1999-09-19 18:04:54Z green $";
401590Srgrimes#endif /* not lint */
411590Srgrimes
421590Srgrimes/*
431590Srgrimes * Cursed vmstat -- from Robert Elz.
441590Srgrimes */
451590Srgrimes
461590Srgrimes#include <sys/param.h>
471590Srgrimes#include <sys/buf.h>
481590Srgrimes#include <sys/stat.h>
491590Srgrimes#include <sys/time.h>
501590Srgrimes#include <sys/proc.h>
5112811Sbde#include <sys/uio.h>
521590Srgrimes#include <sys/namei.h>
531590Srgrimes#include <sys/sysctl.h>
5439230Sgibbs#include <sys/dkstat.h>
5512805Speter#include <sys/vmmeter.h>
561590Srgrimes
5712811Sbde#include <vm/vm_param.h>
5812811Sbde
5928149Scharnier#include <ctype.h>
6028149Scharnier#include <err.h>
611590Srgrimes#include <nlist.h>
621590Srgrimes#include <paths.h>
6328149Scharnier#include <signal.h>
6428149Scharnier#include <stdlib.h>
651590Srgrimes#include <string.h>
6614953Sache#include <time.h>
671590Srgrimes#include <unistd.h>
6828149Scharnier#include <utmp.h>
6939230Sgibbs#include <devstat.h>
701590Srgrimes#include "systat.h"
711590Srgrimes#include "extern.h"
7240060Sobrien#include "devs.h"
731590Srgrimes
741590Srgrimesstatic struct Info {
751590Srgrimes	long	time[CPUSTATES];
761590Srgrimes	struct	vmmeter Cnt;
771590Srgrimes	struct	vmtotal Total;
781590Srgrimes	struct	nchstats nchstats;
791590Srgrimes	long	nchcount;
801590Srgrimes	long	*intrcnt;
8129842Speter	int	bufspace;
8229842Speter	int	desiredvnodes;
8337455Sbde	long	numvnodes;
8437455Sbde	long	freevnodes;
8549245Sdes	long	numdirtybuffers;
861590Srgrimes} s, s1, s2, z;
871590Srgrimes
8839230Sgibbsstruct statinfo cur, last, run;
8939230Sgibbs
901590Srgrimes#define	cnt s.Cnt
911590Srgrimes#define oldcnt s1.Cnt
921590Srgrimes#define	total s.Total
931590Srgrimes#define	nchtotal s.nchstats
941590Srgrimes#define	oldnchtotal s1.nchstats
951590Srgrimes
961590Srgrimesstatic	enum state { BOOT, TIME, RUN } state = TIME;
971590Srgrimes
981590Srgrimesstatic void allocinfo __P((struct Info *));
991590Srgrimesstatic void copyinfo __P((struct Info *, struct Info *));
1001590Srgrimesstatic float cputime __P((int));
10139230Sgibbsstatic void dinfo __P((int, int, struct statinfo *, struct statinfo *));
1021590Srgrimesstatic void getinfo __P((struct Info *, enum state));
1031590Srgrimesstatic void putint __P((int, int, int, int));
1041590Srgrimesstatic void putfloat __P((double, int, int, int, int, int));
10539230Sgibbsstatic void putlongdouble __P((long double, int, int, int, int, int));
1061590Srgrimesstatic int ucount __P((void));
1071590Srgrimes
10836430Sjhaystatic	int ncpu;
1091590Srgrimesstatic	int ut;
1101590Srgrimesstatic	char buf[26];
1111590Srgrimesstatic	time_t t;
1121590Srgrimesstatic	double etime;
1131590Srgrimesstatic	int nintr;
1141590Srgrimesstatic	long *intrloc;
1151590Srgrimesstatic	char **intrname;
1161590Srgrimesstatic	int nextintsrow;
11743756Sdillonstatic  int extended_vm_stats;
1181590Srgrimes
1191590Srgrimesstruct	utmp utmp;
1201590Srgrimes
1211590Srgrimes
1221590SrgrimesWINDOW *
1231590Srgrimesopenkre()
1241590Srgrimes{
1251590Srgrimes
1261590Srgrimes	ut = open(_PATH_UTMP, O_RDONLY);
1271590Srgrimes	if (ut < 0)
1281590Srgrimes		error("No utmp");
1291590Srgrimes	return (stdscr);
1301590Srgrimes}
1311590Srgrimes
1321590Srgrimesvoid
1331590Srgrimesclosekre(w)
1341590Srgrimes	WINDOW *w;
1351590Srgrimes{
1361590Srgrimes
1371590Srgrimes	(void) close(ut);
1381590Srgrimes	if (w == NULL)
1391590Srgrimes		return;
1401590Srgrimes	wclear(w);
1411590Srgrimes	wrefresh(w);
1421590Srgrimes}
1431590Srgrimes
1441590Srgrimes
1451590Srgrimesstatic struct nlist namelist[] = {
1461590Srgrimes#define X_CPTIME	0
1471590Srgrimes	{ "_cp_time" },
1481590Srgrimes#define X_CNT		1
1491590Srgrimes	{ "_cnt" },
1509501Sbde#define	X_BUFFERSPACE	2
1519501Sbde	{ "_bufspace" },
15239230Sgibbs#define	X_NCHSTATS	3
1531590Srgrimes	{ "_nchstats" },
15439230Sgibbs#define	X_INTRNAMES	4
1551590Srgrimes	{ "_intrnames" },
15639230Sgibbs#define	X_EINTRNAMES	5
1571590Srgrimes	{ "_eintrnames" },
15839230Sgibbs#define	X_INTRCNT	6
1591590Srgrimes	{ "_intrcnt" },
16039230Sgibbs#define	X_EINTRCNT	7
1611590Srgrimes	{ "_eintrcnt" },
16239230Sgibbs#define	X_DESIREDVNODES	8
16329842Speter	{ "_desiredvnodes" },
16439230Sgibbs#define	X_NUMVNODES	9
16529842Speter	{ "_numvnodes" },
16639230Sgibbs#define	X_FREEVNODES	10
16729842Speter	{ "_freevnodes" },
16849245Sdes#define X_NUMDIRTYBUFFERS 11
16949245Sdes	{ "_numdirtybuffers" },
1701590Srgrimes	{ "" },
1711590Srgrimes};
1721590Srgrimes
1731590Srgrimes/*
1741590Srgrimes * These constants define where the major pieces are laid out
1751590Srgrimes */
1761590Srgrimes#define STATROW		 0	/* uses 1 row and 68 cols */
1771590Srgrimes#define STATCOL		 2
1781590Srgrimes#define MEMROW		 2	/* uses 4 rows and 31 cols */
1791590Srgrimes#define MEMCOL		 0
1801590Srgrimes#define PAGEROW		 2	/* uses 4 rows and 26 cols */
18119687Sjkh#define PAGECOL		46
18219687Sjkh#define INTSROW		 6	/* uses all rows to bottom and 17 cols */
1837455Sdg#define INTSCOL		61
1841590Srgrimes#define PROCSROW	 7	/* uses 2 rows and 20 cols */
1851590Srgrimes#define PROCSCOL	 0
1861590Srgrimes#define GENSTATROW	 7	/* uses 2 rows and 30 cols */
1871590Srgrimes#define GENSTATCOL	20
1884808Sdg#define VMSTATROW	 6	/* uses 17 rows and 12 cols */
1891590Srgrimes#define VMSTATCOL	48
1901590Srgrimes#define GRAPHROW	10	/* uses 3 rows and 51 cols */
1911590Srgrimes#define GRAPHCOL	 0
1921590Srgrimes#define NAMEIROW	14	/* uses 3 rows and 38 cols */
1931590Srgrimes#define NAMEICOL	 0
1941590Srgrimes#define DISKROW		18	/* uses 5 rows and 50 cols (for 9 drives) */
1951590Srgrimes#define DISKCOL		 0
1961590Srgrimes
19739230Sgibbs#define	DRIVESPACE	 7	/* max # for space */
1981590Srgrimes
1991590Srgrimes#define	MAXDRIVES	DRIVESPACE	 /* max # to display */
2001590Srgrimes
2011590Srgrimesint
2021590Srgrimesinitkre()
2031590Srgrimes{
2041590Srgrimes	char *intrnamebuf, *cp;
2051590Srgrimes	int i;
2061590Srgrimes
2071590Srgrimes	if (namelist[0].n_type == 0) {
2081590Srgrimes		if (kvm_nlist(kd, namelist)) {
2091590Srgrimes			nlisterr(namelist);
2101590Srgrimes			return(0);
2111590Srgrimes		}
2121590Srgrimes		if (namelist[0].n_type == 0) {
2131590Srgrimes			error("No namelist");
2141590Srgrimes			return(0);
2151590Srgrimes		}
2161590Srgrimes	}
21739230Sgibbs
21839230Sgibbs	if (num_devices = getnumdevs() < 0) {
21939230Sgibbs		warnx("%s", devstat_errbuf);
2201590Srgrimes		return(0);
2211590Srgrimes	}
22239230Sgibbs
22339230Sgibbs	cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
22439230Sgibbs	last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
22539230Sgibbs	run.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
22639230Sgibbs	bzero(cur.dinfo, sizeof(struct devinfo));
22739230Sgibbs	bzero(last.dinfo, sizeof(struct devinfo));
22839230Sgibbs	bzero(run.dinfo, sizeof(struct devinfo));
22939230Sgibbs
23039230Sgibbs	if (dsinit(MAXDRIVES, &cur, &last, &run) != 1)
23139230Sgibbs		return(0);
23239230Sgibbs
2331590Srgrimes	if (nintr == 0) {
2341590Srgrimes		nintr = (namelist[X_EINTRCNT].n_value -
2351590Srgrimes			namelist[X_INTRCNT].n_value) / sizeof (long);
2361590Srgrimes		intrloc = calloc(nintr, sizeof (long));
2371590Srgrimes		intrname = calloc(nintr, sizeof (long));
2381590Srgrimes		intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
2391590Srgrimes			namelist[X_INTRNAMES].n_value);
2401590Srgrimes		if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
2411590Srgrimes			error("Out of memory\n");
2421590Srgrimes			if (intrnamebuf)
2431590Srgrimes				free(intrnamebuf);
2441590Srgrimes			if (intrname)
2451590Srgrimes				free(intrname);
2461590Srgrimes			if (intrloc)
2471590Srgrimes				free(intrloc);
2481590Srgrimes			nintr = 0;
2491590Srgrimes			return(0);
2501590Srgrimes		}
2511590Srgrimes		NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
2521590Srgrimes			NVAL(X_INTRNAMES));
2531590Srgrimes		for (cp = intrnamebuf, i = 0; i < nintr; i++) {
2541590Srgrimes			intrname[i] = cp;
2551590Srgrimes			cp += strlen(cp) + 1;
2561590Srgrimes		}
2571590Srgrimes		nextintsrow = INTSROW + 2;
2581590Srgrimes		allocinfo(&s);
2591590Srgrimes		allocinfo(&s1);
2601590Srgrimes		allocinfo(&s2);
2611590Srgrimes		allocinfo(&z);
2621590Srgrimes	}
2631590Srgrimes	getinfo(&s2, RUN);
2641590Srgrimes	copyinfo(&s2, &s1);
2651590Srgrimes	return(1);
2661590Srgrimes}
2671590Srgrimes
2681590Srgrimesvoid
2691590Srgrimesfetchkre()
2701590Srgrimes{
2711590Srgrimes	time_t now;
27214953Sache	struct tm *tp;
2731590Srgrimes
2741590Srgrimes	time(&now);
27514953Sache	tp = localtime(&now);
27614953Sache	(void) strftime(buf, sizeof(buf), "%c", tp);
2771590Srgrimes	buf[16] = '\0';
2781590Srgrimes	getinfo(&s, state);
2791590Srgrimes}
2801590Srgrimes
2811590Srgrimesvoid
2821590Srgrimeslabelkre()
2831590Srgrimes{
2841590Srgrimes	register int i, j;
2851590Srgrimes
2861590Srgrimes	clear();
2871590Srgrimes	mvprintw(STATROW, STATCOL + 4, "users    Load");
28819687Sjkh	mvprintw(MEMROW, MEMCOL, "Mem:KB    REAL            VIRTUAL");
28919687Sjkh	mvprintw(MEMROW + 1, MEMCOL, "        Tot   Share      Tot    Share");
2901590Srgrimes	mvprintw(MEMROW + 2, MEMCOL, "Act");
2911590Srgrimes	mvprintw(MEMROW + 3, MEMCOL, "All");
2921590Srgrimes
29319687Sjkh	mvprintw(MEMROW + 1, MEMCOL + 41, "Free");
2941590Srgrimes
2953614Sdg	mvprintw(PAGEROW, PAGECOL,     "        VN PAGER  SWAP PAGER ");
2963614Sdg	mvprintw(PAGEROW + 1, PAGECOL, "        in  out     in  out ");
2971590Srgrimes	mvprintw(PAGEROW + 2, PAGECOL, "count");
2981590Srgrimes	mvprintw(PAGEROW + 3, PAGECOL, "pages");
2991590Srgrimes
3001590Srgrimes	mvprintw(INTSROW, INTSCOL + 3, " Interrupts");
3011590Srgrimes	mvprintw(INTSROW + 1, INTSCOL + 9, "total");
3021590Srgrimes
30343756Sdillon	mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "cow");
3047351Sdg	mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "wire");
3057351Sdg	mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "act");
3067351Sdg	mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "inact");
3077351Sdg	mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "cache");
3087351Sdg	mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "free");
3097351Sdg	mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "daefr");
3107351Sdg	mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "prcfr");
3117351Sdg	mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "react");
3127351Sdg	mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "pdwake");
3137351Sdg	mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "pdpgs");
3147351Sdg	mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "intrn");
3157351Sdg	mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "buf");
31649245Sdes	mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "dirtybuf");
3171590Srgrimes
31849245Sdes	mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "desiredvnodes");
31949245Sdes	mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "numvnodes");
32049245Sdes	mvprintw(VMSTATROW + 17, VMSTATCOL + 10, "freevnodes");
32129842Speter
3221590Srgrimes	mvprintw(GENSTATROW, GENSTATCOL, "  Csw  Trp  Sys  Int  Sof  Flt");
3231590Srgrimes
3241590Srgrimes	mvprintw(GRAPHROW, GRAPHCOL,
3254930Sbde		"  . %%Sys    . %%Intr   . %%User   . %%Nice   . %%Idle");
3261590Srgrimes	mvprintw(PROCSROW, PROCSCOL, "Proc:r  p  d  s  w");
3271590Srgrimes	mvprintw(GRAPHROW + 1, GRAPHCOL,
3281590Srgrimes		"|    |    |    |    |    |    |    |    |    |    |");
3291590Srgrimes
33014918Sbde	mvprintw(NAMEIROW, NAMEICOL, "Namei         Name-cache    Dir-cache");
3311590Srgrimes	mvprintw(NAMEIROW + 1, NAMEICOL,
33214918Sbde		"    Calls     hits    %%     hits    %%");
33351421Sgreen	mvprintw(DISKROW, DISKCOL, "Disks");
33439230Sgibbs	mvprintw(DISKROW + 1, DISKCOL, "KB/t");
33539230Sgibbs	mvprintw(DISKROW + 2, DISKCOL, "tps");
33639230Sgibbs	mvprintw(DISKROW + 3, DISKCOL, "MB/s");
33749245Sdes	mvprintw(DISKROW + 4, DISKCOL, "%% busy");
33839230Sgibbs	/*
33939230Sgibbs	 * For now, we don't support a fourth disk statistic.  So there's
34039230Sgibbs	 * no point in providing a label for it.  If someone can think of a
34139230Sgibbs	 * fourth useful disk statistic, there is room to add it.
34239230Sgibbs	 */
34339230Sgibbs	/* mvprintw(DISKROW + 4, DISKCOL, " msps"); */
3441590Srgrimes	j = 0;
34539230Sgibbs	for (i = 0; i < num_devices && j < MAXDRIVES; i++)
34639230Sgibbs		if (dev_select[i].selected) {
34739230Sgibbs			char tmpstr[80];
34839230Sgibbs			sprintf(tmpstr, "%s%d", dev_select[i].device_name,
34939230Sgibbs				dev_select[i].unit_number);
35039230Sgibbs			mvprintw(DISKROW, DISKCOL + 5 + 6 * j,
35139230Sgibbs				" %5.5s", tmpstr);
3521590Srgrimes			j++;
3531590Srgrimes		}
35443756Sdillon
35543756Sdillon	if (j <= 4) {
35643756Sdillon		/*
35743756Sdillon		 * room for extended VM stats
35843756Sdillon		 */
35943756Sdillon		mvprintw(VMSTATROW + 11, VMSTATCOL - 6, "zfod");
36043757Sdillon		mvprintw(VMSTATROW + 12, VMSTATCOL - 6, "ofod");
36143757Sdillon		mvprintw(VMSTATROW + 13, VMSTATCOL - 6, "%%slo-z");
36243757Sdillon		mvprintw(VMSTATROW + 14, VMSTATCOL - 6, "tfree");
36343756Sdillon		extended_vm_stats = 1;
36443756Sdillon	} else {
36543756Sdillon		extended_vm_stats = 0;
36643756Sdillon		mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "zfod");
36743756Sdillon	}
36843756Sdillon
3691590Srgrimes	for (i = 0; i < nintr; i++) {
3701590Srgrimes		if (intrloc[i] == 0)
3711590Srgrimes			continue;
3727455Sdg		mvprintw(intrloc[i], INTSCOL + 9, "%-10.10s", intrname[i]);
3731590Srgrimes	}
3741590Srgrimes}
3751590Srgrimes
3761590Srgrimes#define X(fld)	{t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
37739230Sgibbs#define Q(fld)	{t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;}
3781590Srgrimes#define Y(fld)	{t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
3791590Srgrimes#define Z(fld)	{t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
3801590Srgrimes	if(state == TIME) s1.nchstats.fld = t;}
3811590Srgrimes#define PUTRATE(fld, l, c, w) \
3821590Srgrimes	Y(fld); \
3831590Srgrimes	putint((int)((float)s.fld/etime + 0.5), l, c, w)
3841590Srgrimes#define MAXFAIL 5
3851590Srgrimes
3864930Sbdestatic	char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' };
3874930Sbdestatic	char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE,
3884930Sbde				     CP_IDLE };
3891590Srgrimes
3901590Srgrimesvoid
3911590Srgrimesshowkre()
3921590Srgrimes{
3931590Srgrimes	float f1, f2;
3941590Srgrimes	int psiz, inttotal;
3951590Srgrimes	int i, l, c;
3961590Srgrimes	static int failcnt = 0;
3971590Srgrimes
3981590Srgrimes	etime = 0;
3991590Srgrimes	for(i = 0; i < CPUSTATES; i++) {
4001590Srgrimes		X(time);
40139230Sgibbs		Q(cp_time);
4021590Srgrimes		etime += s.time[i];
4031590Srgrimes	}
4041590Srgrimes	if (etime < 5.0) {	/* < 5 ticks - ignore this trash */
4051590Srgrimes		if (failcnt++ >= MAXFAIL) {
4061590Srgrimes			clear();
4071590Srgrimes			mvprintw(2, 10, "The alternate system clock has died!");
4081590Srgrimes			mvprintw(3, 10, "Reverting to ``pigs'' display.");
4091590Srgrimes			move(CMDLINE, 0);
4101590Srgrimes			refresh();
4111590Srgrimes			failcnt = 0;
4121590Srgrimes			sleep(5);
4131590Srgrimes			command("pigs");
4141590Srgrimes		}
4151590Srgrimes		return;
4161590Srgrimes	}
4171590Srgrimes	failcnt = 0;
4181590Srgrimes	etime /= hertz;
41936430Sjhay	etime /= ncpu;
4201590Srgrimes	inttotal = 0;
4211590Srgrimes	for (i = 0; i < nintr; i++) {
4221590Srgrimes		if (s.intrcnt[i] == 0)
4231590Srgrimes			continue;
4241590Srgrimes		if (intrloc[i] == 0) {
4251590Srgrimes			if (nextintsrow == LINES)
4261590Srgrimes				continue;
4271590Srgrimes			intrloc[i] = nextintsrow++;
4287455Sdg			mvprintw(intrloc[i], INTSCOL + 9, "%-10.10s",
4291590Srgrimes				intrname[i]);
4301590Srgrimes		}
4311590Srgrimes		X(intrcnt);
4321590Srgrimes		l = (int)((float)s.intrcnt[i]/etime + 0.5);
4331590Srgrimes		inttotal += l;
4347455Sdg		putint(l, intrloc[i], INTSCOL + 2, 6);
4351590Srgrimes	}
4367455Sdg	putint(inttotal, INTSROW + 1, INTSCOL + 2, 6);
4371590Srgrimes	Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss);
4387138Sphk	Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes); Z(ncs_neghits);
4391590Srgrimes	s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits +
4407012Sphk	    nchtotal.ncs_miss + nchtotal.ncs_long + nchtotal.ncs_neghits;
4411590Srgrimes	if (state == TIME)
4421590Srgrimes		s1.nchcount = s.nchcount;
4431590Srgrimes
4441590Srgrimes	psiz = 0;
4451590Srgrimes	f2 = 0.0;
4464930Sbde	for (c = 0; c < CPUSTATES; c++) {
4471590Srgrimes		i = cpuorder[c];
4481590Srgrimes		f1 = cputime(i);
4491590Srgrimes		f2 += f1;
4501590Srgrimes		l = (int) ((f2 + 1.0) / 2.0) - psiz;
4514930Sbde		if (f1 > 99.9)
4524930Sbde			f1 = 99.9;	/* no room to display 100.0 */
4534930Sbde		putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c, 4, 1, 0);
4541590Srgrimes		move(GRAPHROW + 2, psiz);
4551590Srgrimes		psiz += l;
4561590Srgrimes		while (l-- > 0)
4571590Srgrimes			addch(cpuchar[c]);
4581590Srgrimes	}
4591590Srgrimes
4601590Srgrimes	putint(ucount(), STATROW, STATCOL, 3);
4611590Srgrimes	putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
4621590Srgrimes	putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
4631590Srgrimes	putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
4641590Srgrimes	mvaddstr(STATROW, STATCOL + 53, buf);
4651590Srgrimes#define pgtokb(pg)	((pg) * cnt.v_page_size / 1024)
46619687Sjkh	putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 3, 8);
46719687Sjkh	putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 11, 8);
46819687Sjkh	putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 19, 9);
46919687Sjkh	putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 28, 9);
47019687Sjkh	putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 3, 8);
47119687Sjkh	putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 11, 8);
47219687Sjkh	putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 19, 9);
47319687Sjkh	putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 28, 9);
47419687Sjkh	putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 37, 8);
4751590Srgrimes	putint(total.t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
4761590Srgrimes	putint(total.t_pw, PROCSROW + 1, PROCSCOL + 6, 3);
4771590Srgrimes	putint(total.t_dw, PROCSROW + 1, PROCSCOL + 9, 3);
4781590Srgrimes	putint(total.t_sl, PROCSROW + 1, PROCSCOL + 12, 3);
4791590Srgrimes	putint(total.t_sw, PROCSROW + 1, PROCSCOL + 15, 3);
48043756Sdillon	if (extended_vm_stats == 0) {
48143756Sdillon		PUTRATE(Cnt.v_zfod, VMSTATROW + 0, VMSTATCOL + 4, 5);
48243756Sdillon	}
48343756Sdillon	PUTRATE(Cnt.v_cow_faults, VMSTATROW + 1, VMSTATCOL + 3, 6);
4847351Sdg	putint(pgtokb(cnt.v_wire_count), VMSTATROW + 2, VMSTATCOL, 9);
4857351Sdg	putint(pgtokb(cnt.v_active_count), VMSTATROW + 3, VMSTATCOL, 9);
4867351Sdg	putint(pgtokb(cnt.v_inactive_count), VMSTATROW + 4, VMSTATCOL, 9);
4877351Sdg	putint(pgtokb(cnt.v_cache_count), VMSTATROW + 5, VMSTATCOL, 9);
4887351Sdg	putint(pgtokb(cnt.v_free_count), VMSTATROW + 6, VMSTATCOL, 9);
4897351Sdg	PUTRATE(Cnt.v_dfree, VMSTATROW + 7, VMSTATCOL, 9);
4907351Sdg	PUTRATE(Cnt.v_pfree, VMSTATROW + 8, VMSTATCOL, 9);
4917351Sdg	PUTRATE(Cnt.v_reactivated, VMSTATROW + 9, VMSTATCOL, 9);
4927351Sdg	PUTRATE(Cnt.v_pdwakeups, VMSTATROW + 10, VMSTATCOL, 9);
4937351Sdg	PUTRATE(Cnt.v_pdpages, VMSTATROW + 11, VMSTATCOL, 9);
4947351Sdg	PUTRATE(Cnt.v_intrans, VMSTATROW + 12, VMSTATCOL, 9);
49543756Sdillon
49643756Sdillon	if (extended_vm_stats) {
49743756Sdillon	    PUTRATE(Cnt.v_zfod, VMSTATROW + 11, VMSTATCOL - 16, 9);
49843757Sdillon	    PUTRATE(Cnt.v_ozfod, VMSTATROW + 12, VMSTATCOL - 16, 9);
49943756Sdillon	    putint(
50043756Sdillon		((s.Cnt.v_ozfod < s.Cnt.v_zfod) ?
50143756Sdillon		    s.Cnt.v_ozfod * 100 / s.Cnt.v_zfod :
50243756Sdillon		    0
50343756Sdillon		),
50443757Sdillon		VMSTATROW + 13,
50543756Sdillon		VMSTATCOL - 16,
50643756Sdillon		9
50743756Sdillon	    );
50843757Sdillon	    PUTRATE(Cnt.v_tfree, VMSTATROW + 14, VMSTATCOL - 16, 9);
50943756Sdillon	}
51043756Sdillon
5117351Sdg	putint(s.bufspace/1024, VMSTATROW + 13, VMSTATCOL, 9);
51249245Sdes	putint(s.numdirtybuffers, VMSTATROW + 14, VMSTATCOL, 9);
51349245Sdes	putint(s.desiredvnodes, VMSTATROW + 15, VMSTATCOL, 9);
51449245Sdes	putint(s.numvnodes, VMSTATROW + 16, VMSTATCOL, 9);
51549245Sdes	putint(s.freevnodes, VMSTATROW + 17, VMSTATCOL, 9);
5163614Sdg	PUTRATE(Cnt.v_vnodein, PAGEROW + 2, PAGECOL + 5, 5);
5173614Sdg	PUTRATE(Cnt.v_vnodeout, PAGEROW + 2, PAGECOL + 10, 5);
5183614Sdg	PUTRATE(Cnt.v_swapin, PAGEROW + 2, PAGECOL + 17, 5);
5193614Sdg	PUTRATE(Cnt.v_swapout, PAGEROW + 2, PAGECOL + 22, 5);
5203614Sdg	PUTRATE(Cnt.v_vnodepgsin, PAGEROW + 3, PAGECOL + 5, 5);
5213614Sdg	PUTRATE(Cnt.v_vnodepgsout, PAGEROW + 3, PAGECOL + 10, 5);
5223614Sdg	PUTRATE(Cnt.v_swappgsin, PAGEROW + 3, PAGECOL + 17, 5);
5233614Sdg	PUTRATE(Cnt.v_swappgsout, PAGEROW + 3, PAGECOL + 22, 5);
5241590Srgrimes	PUTRATE(Cnt.v_swtch, GENSTATROW + 1, GENSTATCOL, 5);
5251590Srgrimes	PUTRATE(Cnt.v_trap, GENSTATROW + 1, GENSTATCOL + 5, 5);
5261590Srgrimes	PUTRATE(Cnt.v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 5);
5271590Srgrimes	PUTRATE(Cnt.v_intr, GENSTATROW + 1, GENSTATCOL + 15, 5);
5281590Srgrimes	PUTRATE(Cnt.v_soft, GENSTATROW + 1, GENSTATCOL + 20, 5);
5293614Sdg	PUTRATE(Cnt.v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 5);
5301590Srgrimes	mvprintw(DISKROW, DISKCOL + 5, "                              ");
53139230Sgibbs	for (i = 0, c = 0; i < num_devices && c < MAXDRIVES; i++)
53239230Sgibbs		if (dev_select[i].selected) {
53339230Sgibbs			char tmpstr[80];
53439230Sgibbs			sprintf(tmpstr, "%s%d", dev_select[i].device_name,
53539230Sgibbs				dev_select[i].unit_number);
53639230Sgibbs			mvprintw(DISKROW, DISKCOL + 5 + 6 * c,
53739230Sgibbs				" %5.5s", tmpstr);
53839230Sgibbs			switch(state) {
53939230Sgibbs			case TIME:
54039230Sgibbs				dinfo(i, ++c, &cur, &last);
54139230Sgibbs				break;
54239230Sgibbs			case RUN:
54339230Sgibbs				dinfo(i, ++c, &cur, &run);
54439230Sgibbs				break;
54539230Sgibbs			case BOOT:
54639230Sgibbs				dinfo(i, ++c, &cur, NULL);
54739230Sgibbs				break;
54839230Sgibbs			}
5491590Srgrimes		}
5501590Srgrimes	putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
5517012Sphk	putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits),
5527012Sphk	   NAMEIROW + 2, NAMEICOL + 9, 9);
5531590Srgrimes#define nz(x)	((x) ? (x) : 1)
5548874Srgrimes	putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) *
5557012Sphk	   100.0 / nz(s.nchcount),
5561590Srgrimes	   NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
5571590Srgrimes	putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
5581590Srgrimes	putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
55914918Sbde	   NAMEIROW + 2, NAMEICOL + 33, 4, 0, 1);
5601590Srgrimes#undef nz
5611590Srgrimes}
5621590Srgrimes
5631590Srgrimesint
5641590Srgrimescmdkre(cmd, args)
5651590Srgrimes	char *cmd, *args;
5661590Srgrimes{
56739230Sgibbs	int retval;
5681590Srgrimes
5691590Srgrimes	if (prefix(cmd, "run")) {
57039230Sgibbs		retval = 1;
5711590Srgrimes		copyinfo(&s2, &s1);
57239230Sgibbs		switch (getdevs(&run)) {
57339230Sgibbs		case -1:
57439230Sgibbs			errx(1, "%s", devstat_errbuf);
57539230Sgibbs			break;
57639230Sgibbs		case 1:
57739230Sgibbs			num_devices = run.dinfo->numdevs;
57839230Sgibbs			generation = run.dinfo->generation;
57939230Sgibbs			retval = dscmd("refresh", NULL, MAXDRIVES, &cur);
58039230Sgibbs			if (retval == 2)
58139230Sgibbs				labelkre();
58239230Sgibbs			break;
58339230Sgibbs		default:
58439230Sgibbs			break;
58539230Sgibbs		}
5861590Srgrimes		state = RUN;
58739230Sgibbs		return (retval);
5881590Srgrimes	}
5891590Srgrimes	if (prefix(cmd, "boot")) {
5901590Srgrimes		state = BOOT;
5911590Srgrimes		copyinfo(&z, &s1);
5921590Srgrimes		return (1);
5931590Srgrimes	}
5941590Srgrimes	if (prefix(cmd, "time")) {
5951590Srgrimes		state = TIME;
5961590Srgrimes		return (1);
5971590Srgrimes	}
5981590Srgrimes	if (prefix(cmd, "zero")) {
59939230Sgibbs		retval = 1;
60039230Sgibbs		if (state == RUN) {
6011590Srgrimes			getinfo(&s1, RUN);
60239230Sgibbs			switch (getdevs(&run)) {
60339230Sgibbs			case -1:
60439230Sgibbs				errx(1, "%s", devstat_errbuf);
60539230Sgibbs				break;
60639230Sgibbs			case 1:
60739230Sgibbs				num_devices = run.dinfo->numdevs;
60839230Sgibbs				generation = run.dinfo->generation;
60939230Sgibbs				retval = dscmd("refresh",NULL, MAXDRIVES, &cur);
61039230Sgibbs				if (retval == 2)
61139230Sgibbs					labelkre();
61239230Sgibbs				break;
61339230Sgibbs			default:
61439230Sgibbs				break;
61539230Sgibbs			}
61639230Sgibbs		}
61739230Sgibbs		return (retval);
6181590Srgrimes	}
61939230Sgibbs	retval = dscmd(cmd, args, MAXDRIVES, &cur);
62039230Sgibbs
62139230Sgibbs	if (retval == 2)
62239230Sgibbs		labelkre();
62339230Sgibbs
62439230Sgibbs	return(retval);
6251590Srgrimes}
6261590Srgrimes
6271590Srgrimes/* calculate number of users on the system */
6281590Srgrimesstatic int
6291590Srgrimesucount()
6301590Srgrimes{
6311590Srgrimes	register int nusers = 0;
6321590Srgrimes
6331590Srgrimes	if (ut < 0)
6341590Srgrimes		return (0);
6351590Srgrimes	while (read(ut, &utmp, sizeof(utmp)))
6361590Srgrimes		if (utmp.ut_name[0] != '\0')
6371590Srgrimes			nusers++;
6381590Srgrimes
6391590Srgrimes	lseek(ut, 0L, L_SET);
6401590Srgrimes	return (nusers);
6411590Srgrimes}
6421590Srgrimes
6431590Srgrimesstatic float
6441590Srgrimescputime(indx)
6451590Srgrimes	int indx;
6461590Srgrimes{
6471590Srgrimes	double t;
6481590Srgrimes	register int i;
6491590Srgrimes
6501590Srgrimes	t = 0;
6511590Srgrimes	for (i = 0; i < CPUSTATES; i++)
6521590Srgrimes		t += s.time[i];
6531590Srgrimes	if (t == 0.0)
6541590Srgrimes		t = 1.0;
6551590Srgrimes	return (s.time[indx] * 100.0 / t);
6561590Srgrimes}
6571590Srgrimes
6581590Srgrimesstatic void
6591590Srgrimesputint(n, l, c, w)
6601590Srgrimes	int n, l, c, w;
6611590Srgrimes{
6621590Srgrimes	char b[128];
6631590Srgrimes
6641590Srgrimes	move(l, c);
6651590Srgrimes	if (n == 0) {
6661590Srgrimes		while (w-- > 0)
6671590Srgrimes			addch(' ');
6681590Srgrimes		return;
6691590Srgrimes	}
67036789Simp	snprintf(b, sizeof(b), "%*d", w, n);
6711590Srgrimes	if (strlen(b) > w) {
6721590Srgrimes		while (w-- > 0)
6731590Srgrimes			addch('*');
6741590Srgrimes		return;
6751590Srgrimes	}
6761590Srgrimes	addstr(b);
6771590Srgrimes}
6781590Srgrimes
6791590Srgrimesstatic void
6801590Srgrimesputfloat(f, l, c, w, d, nz)
6811590Srgrimes	double f;
6821590Srgrimes	int l, c, w, d, nz;
6831590Srgrimes{
6841590Srgrimes	char b[128];
6851590Srgrimes
6861590Srgrimes	move(l, c);
6871590Srgrimes	if (nz && f == 0.0) {
6881590Srgrimes		while (--w >= 0)
6891590Srgrimes			addch(' ');
6901590Srgrimes		return;
6911590Srgrimes	}
69236789Simp	snprintf(b, sizeof(b), "%*.*f", w, d, f);
69344935Sbde	if (strlen(b) > w)
69444935Sbde		snprintf(b, sizeof(b), "%*.0f", w, f);
6951590Srgrimes	if (strlen(b) > w) {
6961590Srgrimes		while (--w >= 0)
6971590Srgrimes			addch('*');
6981590Srgrimes		return;
6991590Srgrimes	}
7001590Srgrimes	addstr(b);
7011590Srgrimes}
7021590Srgrimes
7031590Srgrimesstatic void
70439230Sgibbsputlongdouble(f, l, c, w, d, nz)
70539230Sgibbs	long double f;
70639230Sgibbs	int l, c, w, d, nz;
70739230Sgibbs{
70839230Sgibbs	char b[128];
70939230Sgibbs
71039230Sgibbs	move(l, c);
71139230Sgibbs	if (nz && f == 0.0) {
71239230Sgibbs		while (--w >= 0)
71339230Sgibbs			addch(' ');
71439230Sgibbs		return;
71539230Sgibbs	}
71639230Sgibbs	sprintf(b, "%*.*Lf", w, d, f);
71744935Sbde	if (strlen(b) > w)
71844935Sbde		sprintf(b, "%*.0Lf", w, f);
71939230Sgibbs	if (strlen(b) > w) {
72039230Sgibbs		while (--w >= 0)
72139230Sgibbs			addch('*');
72239230Sgibbs		return;
72339230Sgibbs	}
72439230Sgibbs	addstr(b);
72539230Sgibbs}
72639230Sgibbs
72739230Sgibbsstatic void
7281590Srgrimesgetinfo(s, st)
7291590Srgrimes	struct Info *s;
7301590Srgrimes	enum state st;
7311590Srgrimes{
73239230Sgibbs	struct devinfo *tmp_dinfo;
7331590Srgrimes	int mib[2], size;
7341590Srgrimes	extern int errno;
7351590Srgrimes
7361590Srgrimes	NREAD(X_CPTIME, s->time, sizeof s->time);
73739230Sgibbs	NREAD(X_CPTIME, cur.cp_time, sizeof(cur.cp_time));
7381590Srgrimes	NREAD(X_CNT, &s->Cnt, sizeof s->Cnt);
73937455Sbde	NREAD(X_BUFFERSPACE, &s->bufspace, sizeof(s->bufspace));
74037455Sbde	NREAD(X_DESIREDVNODES, &s->desiredvnodes, sizeof(s->desiredvnodes));
74129842Speter	NREAD(X_NUMVNODES, &s->numvnodes, LONG);
74229842Speter	NREAD(X_FREEVNODES, &s->freevnodes, LONG);
7431590Srgrimes	NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
7441590Srgrimes	NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
74549245Sdes	NREAD(X_NUMDIRTYBUFFERS, &s->numdirtybuffers, sizeof(s->numdirtybuffers));
7461590Srgrimes	size = sizeof(s->Total);
7471590Srgrimes	mib[0] = CTL_VM;
7481590Srgrimes	mib[1] = VM_METER;
7491590Srgrimes	if (sysctl(mib, 2, &s->Total, &size, NULL, 0) < 0) {
7501590Srgrimes		error("Can't get kernel info: %s\n", strerror(errno));
7511590Srgrimes		bzero(&s->Total, sizeof(s->Total));
7521590Srgrimes	}
75336430Sjhay	size = sizeof(ncpu);
75436430Sjhay	if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0)
75536430Sjhay		ncpu = 1;
75639230Sgibbs
75739230Sgibbs	tmp_dinfo = last.dinfo;
75839230Sgibbs	last.dinfo = cur.dinfo;
75939230Sgibbs	cur.dinfo = tmp_dinfo;
76039230Sgibbs
76139230Sgibbs	last.busy_time = cur.busy_time;
76239230Sgibbs	switch (getdevs(&cur)) {
76339230Sgibbs	case -1:
76439230Sgibbs		errx(1, "%s", devstat_errbuf);
76539230Sgibbs		break;
76639230Sgibbs	case 1:
76739230Sgibbs		num_devices = cur.dinfo->numdevs;
76839230Sgibbs		generation = cur.dinfo->generation;
76939230Sgibbs		cmdkre("refresh", NULL);
77039230Sgibbs		break;
77139230Sgibbs	default:
77239230Sgibbs		break;
77339230Sgibbs	}
7741590Srgrimes}
7751590Srgrimes
7761590Srgrimesstatic void
7771590Srgrimesallocinfo(s)
7781590Srgrimes	struct Info *s;
7791590Srgrimes{
7801590Srgrimes
78119598Sbde	s->intrcnt = (long *) calloc(nintr, sizeof(long));
78228149Scharnier	if (s->intrcnt == NULL)
78328149Scharnier		errx(2, "out of memory");
7841590Srgrimes}
7851590Srgrimes
7861590Srgrimesstatic void
7871590Srgrimescopyinfo(from, to)
7881590Srgrimes	register struct Info *from, *to;
7891590Srgrimes{
7901590Srgrimes	long *intrcnt;
7911590Srgrimes
7921590Srgrimes	/*
7931590Srgrimes	 * time, wds, seek, and xfer are malloc'd so we have to
7948874Srgrimes	 * save the pointers before the structure copy and then
7951590Srgrimes	 * copy by hand.
7961590Srgrimes	 */
79739230Sgibbs	intrcnt = to->intrcnt;
7981590Srgrimes	*to = *from;
79939230Sgibbs
8001590Srgrimes	bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
8011590Srgrimes}
8021590Srgrimes
8031590Srgrimesstatic void
80439230Sgibbsdinfo(dn, c, now, then)
8051590Srgrimes	int dn, c;
80639230Sgibbs	struct statinfo *now, *then;
8071590Srgrimes{
80839230Sgibbs	long double transfers_per_second;
80939230Sgibbs	long double kb_per_transfer, mb_per_second;
81049245Sdes	long double elapsed_time, device_busy;
81139230Sgibbs	int di;
8121590Srgrimes
81339230Sgibbs	di = dev_select[dn].position;
81439230Sgibbs
81549245Sdes	elapsed_time = compute_etime(now->busy_time, then ?
81639230Sgibbs				     then->busy_time :
81739967Sken				     now->dinfo->devices[di].dev_creation_time);
81839230Sgibbs
81949245Sdes	device_busy =  compute_etime(now->dinfo->devices[di].busy_time, then ?
82049245Sdes				     then->dinfo->devices[di].busy_time :
82149245Sdes				     now->dinfo->devices[di].dev_creation_time);
82249245Sdes
82339230Sgibbs	if (compute_stats(&now->dinfo->devices[di], then ?
82449245Sdes			  &then->dinfo->devices[di] : NULL, elapsed_time,
82539230Sgibbs			  NULL, NULL, NULL,
82639230Sgibbs			  &kb_per_transfer, &transfers_per_second,
82739230Sgibbs			  &mb_per_second, NULL, NULL) != 0)
82839230Sgibbs		errx(1, "%s", devstat_errbuf);
82939230Sgibbs
83049245Sdes	if ((device_busy == 0) && (transfers_per_second > 5))
83149245Sdes		/* the device has been 100% busy, fake it because
83249245Sdes		 * as long as the device is 100% busy the busy_time
83349245Sdes		 * field in the devstat struct is not updated */
83449245Sdes		device_busy = elapsed_time;
83549245Sdes	if (device_busy > elapsed_time)
83649245Sdes		/* this normally happens after one or more periods
83749245Sdes		 * where the device has been 100% busy, correct it */
83849245Sdes		device_busy = elapsed_time;
83949245Sdes
84039230Sgibbs	c = DISKCOL + c * 6;
84139230Sgibbs	putlongdouble(kb_per_transfer, DISKROW + 1, c, 5, 2, 0);
84239230Sgibbs	putlongdouble(transfers_per_second, DISKROW + 2, c, 5, 0, 0);
84339230Sgibbs	putlongdouble(mb_per_second, DISKROW + 3, c, 5, 2, 0);
84449245Sdes	putlongdouble(device_busy * 100 / elapsed_time, DISKROW + 4, c, 5, 0, 0);
8451590Srgrimes}
846