Home | History | Annotate | Line # | Download | only in systat
vmstat.c revision 1.82.4.2
      1  1.82.4.2  pgoyette /*	$NetBSD: vmstat.c,v 1.82.4.2 2019/01/18 08:51:01 pgoyette Exp $	*/
      2       1.2       jtc 
      3       1.1       jtc /*-
      4       1.1       jtc  * Copyright (c) 1983, 1989, 1992, 1993
      5       1.1       jtc  *	The Regents of the University of California.  All rights reserved.
      6       1.1       jtc  *
      7       1.1       jtc  * Redistribution and use in source and binary forms, with or without
      8       1.1       jtc  * modification, are permitted provided that the following conditions
      9       1.1       jtc  * are met:
     10       1.1       jtc  * 1. Redistributions of source code must retain the above copyright
     11       1.1       jtc  *    notice, this list of conditions and the following disclaimer.
     12       1.1       jtc  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1       jtc  *    notice, this list of conditions and the following disclaimer in the
     14       1.1       jtc  *    documentation and/or other materials provided with the distribution.
     15      1.53       agc  * 3. Neither the name of the University nor the names of its contributors
     16       1.1       jtc  *    may be used to endorse or promote products derived from this software
     17       1.1       jtc  *    without specific prior written permission.
     18       1.1       jtc  *
     19       1.1       jtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1       jtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1       jtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1       jtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1       jtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1       jtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1       jtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1       jtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1       jtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1       jtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1       jtc  * SUCH DAMAGE.
     30       1.1       jtc  */
     31       1.1       jtc 
     32       1.8       mrg #include <sys/cdefs.h>
     33       1.1       jtc #ifndef lint
     34       1.2       jtc #if 0
     35       1.1       jtc static char sccsid[] = "@(#)vmstat.c	8.2 (Berkeley) 1/12/94";
     36       1.2       jtc #endif
     37  1.82.4.2  pgoyette __RCSID("$NetBSD: vmstat.c,v 1.82.4.2 2019/01/18 08:51:01 pgoyette Exp $");
     38       1.1       jtc #endif /* not lint */
     39       1.1       jtc 
     40       1.1       jtc /*
     41       1.1       jtc  * Cursed vmstat -- from Robert Elz.
     42       1.1       jtc  */
     43       1.1       jtc 
     44       1.1       jtc #include <sys/param.h>
     45      1.67  christos #include <sys/uio.h>
     46       1.1       jtc #include <sys/namei.h>
     47       1.1       jtc #include <sys/sysctl.h>
     48      1.70    dyoung #include <sys/evcnt.h>
     49       1.1       jtc 
     50      1.11       mrg #include <uvm/uvm_extern.h>
     51      1.11       mrg 
     52      1.66      yamt #include <errno.h>
     53       1.3   mycroft #include <stdlib.h>
     54       1.1       jtc #include <string.h>
     55      1.41       abs #include <util.h>
     56       1.3   mycroft 
     57       1.1       jtc #include "systat.h"
     58       1.1       jtc #include "extern.h"
     59      1.65     blymn #include "drvstats.h"
     60      1.40  christos #include "utmpentry.h"
     61      1.63       dsl #include "vmstat.h"
     62       1.1       jtc 
     63       1.1       jtc static struct Info {
     64      1.34    simonb 	struct	uvmexp_sysctl uvmexp;
     65       1.1       jtc 	struct	vmtotal Total;
     66      1.81    dennis 	struct	nchstats nchstats;
     67       1.1       jtc 	long	nchcount;
     68       1.1       jtc 	long	*intrcnt;
     69      1.44       dsl 	u_int64_t	*evcnt;
     70       1.1       jtc } s, s1, s2, z;
     71       1.1       jtc 
     72      1.63       dsl enum display_mode display_mode = TIME;
     73       1.1       jtc 
     74      1.33        ad static void allocinfo(struct Info *);
     75      1.33        ad static void copyinfo(struct Info *, struct Info *);
     76      1.33        ad static float cputime(int);
     77      1.49       dsl static void dinfo(int, int, int);
     78      1.63       dsl static void getinfo(struct Info *);
     79      1.33        ad static int ucount(void);
     80       1.1       jtc 
     81       1.1       jtc static	char buf[26];
     82      1.59       dsl static	u_int64_t temp;
     83      1.63       dsl double etime;
     84       1.1       jtc static	float hertz;
     85       1.1       jtc static	int nintr;
     86       1.1       jtc static	long *intrloc;
     87       1.1       jtc static	char **intrname;
     88       1.1       jtc static	int nextintsrow;
     89      1.49       dsl static	int disk_horiz = 1;
     90  1.82.4.1  pgoyette static	u_int nbuf;
     91       1.1       jtc 
     92       1.1       jtc WINDOW *
     93      1.33        ad openvmstat(void)
     94       1.1       jtc {
     95       1.1       jtc 	return (stdscr);
     96       1.1       jtc }
     97       1.1       jtc 
     98       1.1       jtc void
     99      1.33        ad closevmstat(WINDOW *w)
    100       1.1       jtc {
    101       1.1       jtc 
    102       1.1       jtc 	if (w == NULL)
    103       1.1       jtc 		return;
    104       1.1       jtc 	wclear(w);
    105       1.1       jtc 	wrefresh(w);
    106       1.1       jtc }
    107       1.1       jtc 
    108       1.1       jtc 
    109       1.1       jtc static struct nlist namelist[] = {
    110      1.79     joerg #define	X_INTRNAMES	0
    111      1.69  christos 	{ .n_name = "_intrnames" },
    112      1.79     joerg #define	X_EINTRNAMES	1
    113      1.69  christos 	{ .n_name = "_eintrnames" },
    114      1.79     joerg #define	X_INTRCNT	2
    115      1.69  christos 	{ .n_name = "_intrcnt" },
    116      1.79     joerg #define	X_EINTRCNT	3
    117      1.69  christos 	{ .n_name = "_eintrcnt" },
    118      1.79     joerg #define	X_ALLEVENTS	4
    119      1.69  christos 	{ .n_name = "_allevents" },
    120      1.69  christos 	{ .n_name = NULL }
    121       1.1       jtc };
    122       1.1       jtc 
    123       1.1       jtc /*
    124       1.1       jtc  * These constants define where the major pieces are laid out
    125       1.1       jtc  */
    126       1.1       jtc #define STATROW		 0	/* uses 1 row and 68 cols */
    127       1.1       jtc #define STATCOL		 2
    128  1.82.4.1  pgoyette #define MEMROW		 9	/* uses 5 rows and 31 cols */
    129       1.1       jtc #define MEMCOL		 0
    130       1.1       jtc #define PAGEROW		 2	/* uses 4 rows and 26 cols */
    131      1.48       dsl #define PAGECOL		54
    132      1.48       dsl #define INTSROW		 9	/* uses all rows to bottom and 17 cols */
    133      1.48       dsl #define INTSCOL		40
    134      1.48       dsl #define INTSCOLEND	(VMSTATCOL - 0)
    135      1.48       dsl #define PROCSROW	 2	/* uses 2 rows and 20 cols */
    136       1.1       jtc #define PROCSCOL	 0
    137      1.48       dsl #define GENSTATROW	 2	/* uses 2 rows and 30 cols */
    138      1.58  christos #define GENSTATCOL	17
    139      1.48       dsl #define VMSTATROW	 7	/* uses 17 rows and 15 cols */
    140      1.48       dsl #define VMSTATCOL	64
    141      1.48       dsl #define GRAPHROW	 5	/* uses 3 rows and 51 cols */
    142       1.1       jtc #define GRAPHCOL	 0
    143  1.82.4.1  pgoyette #define NAMEIROW	15	/* uses 3 rows and 38 cols (must be MEMROW + 5 + 1) */
    144       1.1       jtc #define NAMEICOL	 0
    145  1.82.4.1  pgoyette #define DISKROW		19	/* uses 5 rows and 50 cols (for 9 drives) */
    146       1.1       jtc #define DISKCOL		 0
    147  1.82.4.1  pgoyette #define DISKCOLWIDTH	 8
    148      1.49       dsl #define DISKCOLEND	INTSCOL
    149       1.1       jtc 
    150      1.44       dsl typedef struct intr_evcnt intr_evcnt_t;
    151      1.44       dsl struct intr_evcnt {
    152      1.44       dsl 	char		*ie_group;
    153      1.44       dsl 	char		*ie_name;
    154      1.44       dsl 	u_int64_t	*ie_count;	/* kernel address... */
    155      1.44       dsl 	int		ie_loc;		/* screen row */
    156      1.44       dsl } *ie_head;
    157      1.44       dsl int nevcnt;
    158      1.44       dsl 
    159      1.44       dsl static void
    160      1.44       dsl get_interrupt_events(void)
    161      1.44       dsl {
    162      1.44       dsl 	struct evcntlist allevents;
    163      1.44       dsl 	struct evcnt evcnt, *evptr;
    164      1.44       dsl 	intr_evcnt_t *ie;
    165      1.55    itojun 	intr_evcnt_t *n;
    166      1.44       dsl 
    167      1.44       dsl 	if (!NREAD(X_ALLEVENTS, &allevents, sizeof allevents))
    168      1.44       dsl 		return;
    169      1.60       chs 	evptr = TAILQ_FIRST(&allevents);
    170      1.60       chs 	for (; evptr != NULL; evptr = TAILQ_NEXT(&evcnt, ev_list)) {
    171      1.44       dsl 		if (!KREAD(evptr, &evcnt, sizeof evcnt))
    172      1.44       dsl 			return;
    173      1.44       dsl 		if (evcnt.ev_type != EVCNT_TYPE_INTR)
    174      1.44       dsl 			continue;
    175      1.55    itojun 		n = realloc(ie_head, sizeof *ie * (nevcnt + 1));
    176      1.55    itojun 		if (n == NULL) {
    177      1.44       dsl 			error("realloc failed");
    178      1.44       dsl 			die(0);
    179      1.44       dsl 		}
    180      1.55    itojun 		ie_head = n;
    181      1.44       dsl 		ie = ie_head + nevcnt;
    182      1.44       dsl 		ie->ie_group = malloc(evcnt.ev_grouplen + 1);
    183      1.44       dsl 		ie->ie_name = malloc(evcnt.ev_namelen + 1);
    184      1.44       dsl 		if (ie->ie_group == NULL || ie->ie_name == NULL)
    185      1.44       dsl 			return;
    186      1.46       dsl 		if (!KREAD(evcnt.ev_group, ie->ie_group, evcnt.ev_grouplen + 1))
    187      1.44       dsl 			return;
    188      1.46       dsl 		if (!KREAD(evcnt.ev_name, ie->ie_name, evcnt.ev_namelen + 1))
    189      1.44       dsl 			return;
    190      1.44       dsl 		ie->ie_count = &evptr->ev_count;
    191      1.44       dsl 		ie->ie_loc = 0;
    192      1.44       dsl 		nevcnt++;
    193      1.44       dsl 	}
    194      1.44       dsl }
    195      1.44       dsl 
    196       1.1       jtc int
    197      1.33        ad initvmstat(void)
    198       1.1       jtc {
    199      1.64       dsl 	static char *intrnamebuf;
    200      1.64       dsl 	char *cp;
    201       1.1       jtc 	int i;
    202       1.1       jtc 
    203      1.64       dsl 	if (intrnamebuf)
    204      1.64       dsl 		free(intrnamebuf);
    205      1.64       dsl 	if (intrname)
    206      1.64       dsl 		free(intrname);
    207      1.64       dsl 	if (intrloc)
    208      1.64       dsl 		free(intrloc);
    209      1.64       dsl 
    210       1.1       jtc 	if (namelist[0].n_type == 0) {
    211      1.60       chs 		if (kvm_nlist(kd, namelist) &&
    212      1.79     joerg 		    namelist[X_ALLEVENTS].n_type == 0) {
    213       1.1       jtc 			nlisterr(namelist);
    214       1.1       jtc 			return(0);
    215       1.1       jtc 		}
    216       1.1       jtc 	}
    217       1.1       jtc 	hertz = stathz ? stathz : hz;
    218      1.65     blymn 	if (!drvinit(1))
    219      1.61     blymn 		return(0);
    220      1.44       dsl 
    221      1.44       dsl 	/* Old style interrupt counts - deprecated */
    222      1.44       dsl 	nintr = (namelist[X_EINTRCNT].n_value -
    223      1.44       dsl 		namelist[X_INTRCNT].n_value) / sizeof (long);
    224      1.60       chs 	if (nintr) {
    225      1.60       chs 		intrloc = calloc(nintr, sizeof (long));
    226      1.60       chs 		intrname = calloc(nintr, sizeof (long));
    227      1.60       chs 		intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
    228      1.60       chs 				     namelist[X_INTRNAMES].n_value);
    229      1.60       chs 		if (intrnamebuf == NULL || intrname == 0 || intrloc == 0) {
    230      1.60       chs 			error("Out of memory\n");
    231      1.60       chs 			nintr = 0;
    232      1.60       chs 			return(0);
    233      1.60       chs 		}
    234      1.60       chs 		NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
    235      1.60       chs 		      NVAL(X_INTRNAMES));
    236      1.60       chs 		for (cp = intrnamebuf, i = 0; i < nintr; i++) {
    237      1.60       chs 			intrname[i] = cp;
    238      1.60       chs 			cp += strlen(cp) + 1;
    239      1.60       chs 		}
    240      1.44       dsl 	}
    241      1.44       dsl 
    242      1.44       dsl 	/* event counter interrupt counts */
    243      1.44       dsl 	get_interrupt_events();
    244      1.44       dsl 
    245      1.48       dsl 	nextintsrow = INTSROW + 1;
    246      1.44       dsl 	allocinfo(&s);
    247      1.44       dsl 	allocinfo(&s1);
    248      1.44       dsl 	allocinfo(&s2);
    249      1.44       dsl 	allocinfo(&z);
    250      1.44       dsl 
    251      1.63       dsl 	getinfo(&s2);
    252       1.1       jtc 	copyinfo(&s2, &s1);
    253       1.1       jtc 	return(1);
    254       1.1       jtc }
    255       1.1       jtc 
    256       1.1       jtc void
    257      1.33        ad fetchvmstat(void)
    258       1.1       jtc {
    259       1.1       jtc 	time_t now;
    260       1.1       jtc 
    261       1.1       jtc 	time(&now);
    262      1.50    itojun 	strlcpy(buf, ctime(&now), sizeof(buf));
    263      1.18      marc 	buf[19] = '\0';
    264      1.63       dsl 	getinfo(&s);
    265       1.1       jtc }
    266       1.1       jtc 
    267      1.44       dsl static void
    268      1.44       dsl print_ie_title(int i)
    269      1.44       dsl {
    270      1.44       dsl 	int width, name_width, group_width;
    271      1.44       dsl 
    272      1.48       dsl 	width = INTSCOLEND - (INTSCOL + 9);
    273      1.44       dsl 	if (width <= 0)
    274      1.44       dsl 		return;
    275      1.44       dsl 
    276      1.44       dsl 	move(ie_head[i].ie_loc, INTSCOL + 9);
    277      1.44       dsl 	group_width = strlen(ie_head[i].ie_group);
    278      1.44       dsl 	name_width = strlen(ie_head[i].ie_name);
    279      1.44       dsl 	width -= group_width + 1 + name_width;
    280      1.44       dsl 	if (width < 0) {
    281      1.47       dsl 		/*
    282      1.47       dsl 		 * Screen to narrow for full strings
    283      1.47       dsl 		 * This is all rather horrid, in some cases there are a lot
    284      1.47       dsl 		 * of events in the same group, and in others the event
    285      1.47       dsl 		 * name is "intr".  There are also names which need 7 or 8
    286      1.47       dsl 		 * columns before they become meaningful.
    287      1.47       dsl 		 * This is a bad compromise.
    288      1.47       dsl 		 */
    289      1.44       dsl 		width = -width;
    290      1.44       dsl 		group_width -= (width + 1) / 2;
    291      1.44       dsl 		name_width -= width / 2;
    292      1.47       dsl 		/* some have the 'useful' name "intr", display their group */
    293      1.47       dsl 		if (strcasecmp(ie_head[i].ie_name, "intr") == 0) {
    294      1.47       dsl 			 group_width += name_width + 1;
    295      1.47       dsl 			 name_width = 0;
    296      1.47       dsl 		} else {
    297      1.47       dsl 			if (group_width <= 3 || name_width < 0) {
    298      1.47       dsl 				/* don't display group */
    299      1.47       dsl 				name_width += group_width + 1;
    300      1.47       dsl 				group_width = 0;
    301      1.47       dsl 			}
    302      1.44       dsl 		}
    303      1.44       dsl 	}
    304      1.44       dsl 
    305      1.47       dsl 	if (group_width != 0) {
    306      1.47       dsl 		printw("%-.*s", group_width, ie_head[i].ie_group);
    307      1.47       dsl 		if (name_width != 0)
    308      1.47       dsl 			printw(" ");
    309      1.47       dsl 	}
    310      1.47       dsl 	if (name_width != 0)
    311      1.47       dsl 		printw("%-.*s", name_width, ie_head[i].ie_name);
    312      1.44       dsl }
    313      1.44       dsl 
    314       1.1       jtc void
    315      1.63       dsl labelvmstat_top(void)
    316       1.1       jtc {
    317       1.1       jtc 
    318       1.1       jtc 	clear();
    319      1.63       dsl 
    320       1.1       jtc 	mvprintw(STATROW, STATCOL + 4, "users    Load");
    321      1.13       mrg 
    322  1.82.4.1  pgoyette 	mvprintw(GENSTATROW, GENSTATCOL, "   Csw  Traps SysCal  Intr   Soft  Fault");
    323      1.63       dsl 
    324      1.63       dsl 	mvprintw(GRAPHROW, GRAPHCOL,
    325      1.63       dsl 		"    . %% Sy    . %% Us    . %% Ni    . %% In    . %% Id");
    326      1.75     rmind 	mvprintw(PROCSROW, PROCSCOL, "Proc:r  d  s");
    327      1.63       dsl 	mvprintw(GRAPHROW + 1, GRAPHCOL,
    328      1.63       dsl 		"|    |    |    |    |    |    |    |    |    |    |");
    329      1.63       dsl 
    330      1.63       dsl 	mvprintw(PAGEROW, PAGECOL + 8, "PAGING   SWAPPING ");
    331      1.13       mrg 	mvprintw(PAGEROW + 1, PAGECOL, "        in  out   in  out ");
    332  1.82.4.1  pgoyette 	mvprintw(PAGEROW + 2, PAGECOL, "  ops                     ");
    333  1.82.4.1  pgoyette 	mvprintw(PAGEROW + 3, PAGECOL, "pages                     ");
    334      1.63       dsl }
    335      1.63       dsl 
    336      1.63       dsl void
    337      1.63       dsl labelvmstat(void)
    338      1.63       dsl {
    339      1.63       dsl 	int i;
    340       1.1       jtc 
    341      1.63       dsl 	/* Top few lines first */
    342       1.1       jtc 
    343      1.63       dsl 	labelvmstat_top();
    344       1.1       jtc 
    345      1.63       dsl 	/* Left hand column */
    346       1.1       jtc 
    347  1.82.4.1  pgoyette 	mvprintw(MEMROW + 0, MEMCOL, "Anon                 %%   zero         ");
    348  1.82.4.1  pgoyette 	mvprintw(MEMROW + 1, MEMCOL, "Exec                 %%   wired        ");
    349  1.82.4.1  pgoyette 	mvprintw(MEMROW + 2, MEMCOL, "File                 %%   inact        ");
    350  1.82.4.1  pgoyette 	mvprintw(MEMROW + 3, MEMCOL, "Meta                 %%   bufs         ");
    351  1.82.4.1  pgoyette 	mvprintw(MEMROW + 4, MEMCOL, " (kB)        real   swaponly      free");
    352  1.82.4.1  pgoyette 	mvprintw(MEMROW + 5, MEMCOL, "Active                                ");
    353       1.1       jtc 
    354       1.1       jtc 	mvprintw(NAMEIROW, NAMEICOL, "Namei         Sys-cache     Proc-cache");
    355       1.1       jtc 	mvprintw(NAMEIROW + 1, NAMEICOL,
    356       1.1       jtc 		"    Calls     hits    %%     hits     %%");
    357      1.63       dsl 
    358  1.82.4.1  pgoyette 	mvprintw(DISKROW, DISKCOL, "%*s", DISKCOLWIDTH, "Disks:");
    359      1.49       dsl 	if (disk_horiz) {
    360      1.49       dsl 		mvprintw(DISKROW + 1, DISKCOL + 1, "seeks");
    361      1.49       dsl 		mvprintw(DISKROW + 2, DISKCOL + 1, "xfers");
    362      1.49       dsl 		mvprintw(DISKROW + 3, DISKCOL + 1, "bytes");
    363      1.49       dsl 		mvprintw(DISKROW + 4, DISKCOL + 1, "%%busy");
    364      1.49       dsl 	} else {
    365  1.82.4.1  pgoyette 		mvprintw(DISKROW, DISKCOL + 1 * DISKCOLWIDTH, "%*s", DISKCOLWIDTH, "seeks");
    366  1.82.4.1  pgoyette 		mvprintw(DISKROW, DISKCOL + 2 * DISKCOLWIDTH, "%*s", DISKCOLWIDTH, "xfers");
    367  1.82.4.1  pgoyette 		mvprintw(DISKROW, DISKCOL + 3 * DISKCOLWIDTH, "%*s", DISKCOLWIDTH, "bytes");
    368  1.82.4.2  pgoyette 		mvprintw(DISKROW, DISKCOL + 4 * DISKCOLWIDTH, "%*s", DISKCOLWIDTH, "%busy");
    369      1.49       dsl 	}
    370      1.63       dsl 
    371      1.63       dsl 	/* Middle column */
    372      1.63       dsl 
    373      1.63       dsl 	mvprintw(INTSROW, INTSCOL + 9, "Interrupts");
    374       1.1       jtc 	for (i = 0; i < nintr; i++) {
    375       1.1       jtc 		if (intrloc[i] == 0)
    376       1.1       jtc 			continue;
    377      1.47       dsl 		mvprintw(intrloc[i], INTSCOL + 9, "%-.*s",
    378      1.48       dsl 			INTSCOLEND - (INTSCOL + 9), intrname[i]);
    379       1.1       jtc 	}
    380      1.44       dsl 	for (i = 0; i < nevcnt; i++) {
    381      1.44       dsl 		if (ie_head[i].ie_loc == 0)
    382      1.44       dsl 			continue;
    383      1.44       dsl 		print_ie_title(i);
    384      1.44       dsl 	}
    385      1.63       dsl 
    386      1.63       dsl 	/* Right hand column */
    387      1.63       dsl 
    388      1.63       dsl 	mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "forks");
    389      1.63       dsl 	mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "fkppw");
    390      1.63       dsl 	mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "fksvm");
    391      1.63       dsl 	mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "pwait");
    392      1.63       dsl 	mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "relck");
    393      1.63       dsl 	mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "rlkok");
    394      1.63       dsl 	mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "noram");
    395      1.63       dsl 	mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "ndcpy");
    396      1.63       dsl 	mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "fltcp");
    397      1.63       dsl 	mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "zfod");
    398      1.63       dsl 	mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "cow");
    399      1.63       dsl 	mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "fmin");
    400      1.63       dsl 	mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "ftarg");
    401      1.63       dsl 	mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "itarg");
    402  1.82.4.1  pgoyette 	mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "flnan");
    403      1.63       dsl 	mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "pdfre");
    404      1.63       dsl 
    405      1.63       dsl 	if (LINES - 1 > VMSTATROW + 16)
    406      1.63       dsl 		mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "pdscn");
    407       1.1       jtc }
    408       1.1       jtc 
    409      1.63       dsl #define X(s, s1, fld)	{temp = (s).fld[i]; (s).fld[i] -= (s1).fld[i]; \
    410      1.63       dsl 			if (display_mode == TIME) (s1).fld[i] = temp;}
    411      1.63       dsl #define Z(s, s1, fld)	{temp = (s).nchstats.fld; \
    412      1.63       dsl 			(s).nchstats.fld -= (s1).nchstats.fld; \
    413      1.63       dsl 			if (display_mode == TIME) (s1).nchstats.fld = temp;}
    414      1.63       dsl #define PUTRATE(s, s1, fld, l, c, w) \
    415      1.63       dsl 			{temp = (s).fld; (s).fld -= (s1).fld; \
    416      1.63       dsl 			if (display_mode == TIME) (s1).fld = temp; \
    417      1.63       dsl 			putint((int)((float)(s).fld/etime + 0.5), l, c, w);}
    418       1.1       jtc #define MAXFAIL 5
    419       1.1       jtc 
    420      1.25    simonb static	char cpuchar[CPUSTATES] = { '=' , '>', '-', '%', ' ' };
    421      1.25    simonb static	char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_INTR, CP_IDLE };
    422       1.1       jtc 
    423       1.1       jtc void
    424      1.63       dsl show_vmstat_top(vmtotal_t *Total, uvmexp_sysctl_t *uvm, uvmexp_sysctl_t *uvm1)
    425      1.63       dsl {
    426      1.63       dsl 	float f1, f2;
    427      1.63       dsl 	int psiz;
    428      1.63       dsl 	int i, l, c;
    429      1.63       dsl 	struct {
    430      1.63       dsl 		struct uvmexp_sysctl *uvmexp;
    431      1.63       dsl 	} us, us1;
    432      1.63       dsl 
    433      1.63       dsl 	us.uvmexp = uvm;
    434      1.63       dsl 	us1.uvmexp = uvm1;
    435      1.63       dsl 
    436      1.63       dsl 	putint(ucount(), STATROW, STATCOL, 3);
    437      1.63       dsl 	putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
    438      1.63       dsl 	putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
    439      1.63       dsl 	putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
    440      1.63       dsl 	mvaddstr(STATROW, STATCOL + 53, buf);
    441      1.63       dsl 
    442      1.63       dsl 	putint(Total->t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
    443      1.63       dsl 	putint(Total->t_dw, PROCSROW + 1, PROCSCOL + 6, 3);
    444      1.63       dsl 	putint(Total->t_sl, PROCSROW + 1, PROCSCOL + 9, 3);
    445      1.63       dsl 
    446      1.63       dsl 	PUTRATE(us, us1, uvmexp->swtch, GENSTATROW + 1, GENSTATCOL - 1, 7);
    447      1.68       dsl 	PUTRATE(us, us1, uvmexp->traps, GENSTATROW + 1, GENSTATCOL + 7, 6);
    448      1.68       dsl 	PUTRATE(us, us1, uvmexp->syscalls, GENSTATROW + 1, GENSTATCOL + 14, 6);
    449      1.68       dsl 	PUTRATE(us, us1, uvmexp->intrs, GENSTATROW + 1, GENSTATCOL + 21, 5);
    450      1.72     njoly 	PUTRATE(us, us1, uvmexp->softs, GENSTATROW + 1, GENSTATCOL + 27, 6);
    451      1.72     njoly 	PUTRATE(us, us1, uvmexp->faults, GENSTATROW + 1, GENSTATCOL + 34, 6);
    452      1.63       dsl 
    453  1.82.4.1  pgoyette 	/*
    454  1.82.4.1  pgoyette 	 * XXX it sure would be nice if this did what top(1) does and showed
    455  1.82.4.1  pgoyette 	 * the utilization of each CPU on a separate line, though perhaps IFF
    456  1.82.4.1  pgoyette 	 * the screen is tall enough
    457  1.82.4.1  pgoyette 	 */
    458      1.63       dsl 	/* Last CPU state not calculated yet. */
    459      1.63       dsl 	for (f2 = 0.0, psiz = 0, c = 0; c < CPUSTATES; c++) {
    460      1.63       dsl 		i = cpuorder[c];
    461      1.63       dsl 		f1 = cputime(i);
    462      1.63       dsl 		f2 += f1;
    463      1.63       dsl 		l = (int) ((f2 + 1.0) / 2.0) - psiz;
    464      1.63       dsl 		if (c == 0)
    465      1.63       dsl 			putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);
    466      1.63       dsl 		else
    467      1.63       dsl 			putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c + 1, 5, 1, 0);
    468      1.63       dsl 		mvhline(GRAPHROW + 2, psiz, cpuchar[c], l);
    469      1.63       dsl 		psiz += l;
    470      1.63       dsl 	}
    471      1.63       dsl 
    472      1.63       dsl 	PUTRATE(us, us1, uvmexp->pageins, PAGEROW + 2, PAGECOL + 5, 5);
    473      1.63       dsl 	PUTRATE(us, us1, uvmexp->pdpageouts, PAGEROW + 2, PAGECOL + 10, 5);
    474      1.63       dsl 	PUTRATE(us, us1, uvmexp->pgswapin, PAGEROW + 3, PAGECOL + 5, 5);
    475      1.63       dsl 	PUTRATE(us, us1, uvmexp->pgswapout, PAGEROW + 3, PAGECOL + 10, 5);
    476      1.63       dsl }
    477      1.63       dsl 
    478      1.63       dsl void
    479      1.33        ad showvmstat(void)
    480       1.1       jtc {
    481      1.63       dsl 	int inttotal;
    482      1.49       dsl 	int i, l, r, c;
    483       1.1       jtc 	static int failcnt = 0;
    484      1.49       dsl 	static int relabel = 0;
    485      1.49       dsl 	static int last_disks = 0;
    486      1.59       dsl 	static char pigs[] = "pigs";
    487  1.82.4.1  pgoyette 	static u_long bufmem;
    488  1.82.4.1  pgoyette 	struct buf_sysctl *buffers;
    489  1.82.4.1  pgoyette 	int mib[6];
    490  1.82.4.1  pgoyette 	size_t size;
    491  1.82.4.1  pgoyette 	int extraslop = 0;
    492      1.49       dsl 
    493      1.49       dsl 	if (relabel) {
    494      1.49       dsl 		labelvmstat();
    495      1.49       dsl 		relabel = 0;
    496      1.49       dsl 	}
    497      1.39  sommerfe 
    498      1.62       dsl 	cpuswap();
    499      1.63       dsl 	if (display_mode == TIME) {
    500      1.65     blymn 		drvswap();
    501      1.44       dsl 		etime = cur.cp_etime;
    502      1.44       dsl 		/* < 5 ticks - ignore this trash */
    503      1.44       dsl 		if ((etime * hertz) < 1.0) {
    504      1.74       wiz 			if (failcnt++ <= MAXFAIL)
    505      1.44       dsl 				return;
    506       1.1       jtc 			clear();
    507       1.1       jtc 			mvprintw(2, 10, "The alternate system clock has died!");
    508       1.1       jtc 			mvprintw(3, 10, "Reverting to ``pigs'' display.");
    509       1.1       jtc 			move(CMDLINE, 0);
    510       1.1       jtc 			refresh();
    511       1.1       jtc 			failcnt = 0;
    512       1.1       jtc 			sleep(5);
    513      1.59       dsl 			command(pigs);
    514      1.44       dsl 			return;
    515       1.1       jtc 		}
    516      1.44       dsl 	} else
    517      1.44       dsl 		etime = 1.0;
    518      1.44       dsl 
    519      1.63       dsl 	show_vmstat_top(&s.Total, &s.uvmexp, &s1.uvmexp);
    520       1.1       jtc 
    521      1.63       dsl 	/* Memory totals */
    522      1.17  drochner #define pgtokb(pg)	((pg) * (s.uvmexp.pagesize / 1024))
    523  1.82.4.1  pgoyette 
    524  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.anonpages),				MEMROW + 0, MEMCOL + 7, 10);
    525  1.82.4.1  pgoyette 	putint((s.uvmexp.anonpages * 100 + 0.5) / s.uvmexp.npages,	MEMROW + 0, MEMCOL + 17, 4);
    526  1.82.4.1  pgoyette 
    527  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.zeropages),				MEMROW + 0, MEMCOL + 30, 8);
    528  1.82.4.1  pgoyette 
    529  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.execpages),				MEMROW + 1, MEMCOL + 7, 10);
    530  1.82.4.1  pgoyette 	putint((s.uvmexp.execpages * 100 + 0.5) / s.uvmexp.npages,	MEMROW + 1, MEMCOL + 17, 4);
    531  1.82.4.1  pgoyette 
    532  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.wired),					MEMROW + 1, MEMCOL + 30, 8);
    533  1.82.4.1  pgoyette 
    534  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.filepages),				MEMROW + 2, MEMCOL + 7, 10);
    535  1.82.4.1  pgoyette 	putint((s.uvmexp.filepages * 100 + 0.5) / s.uvmexp.npages,	MEMROW + 2, MEMCOL + 17, 4);
    536  1.82.4.1  pgoyette 
    537  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.inactive),				MEMROW + 2, MEMCOL + 30, 8);
    538  1.82.4.1  pgoyette 
    539  1.82.4.1  pgoyette 	/* Get total size of metadata buffers */
    540  1.82.4.1  pgoyette 	size = sizeof(bufmem);
    541  1.82.4.1  pgoyette 	if (sysctlbyname("vm.bufmem", &bufmem, &size, NULL, 0) < 0) {
    542  1.82.4.1  pgoyette 		error("can't get buffers size: %s\n", strerror(errno));
    543  1.82.4.1  pgoyette 		return;
    544  1.82.4.1  pgoyette 	}
    545  1.82.4.1  pgoyette 
    546  1.82.4.1  pgoyette 	/* Get number of metadata buffers */
    547  1.82.4.1  pgoyette 	size = 0;
    548  1.82.4.1  pgoyette 	buffers = NULL;
    549  1.82.4.1  pgoyette 	mib[0] = CTL_KERN;
    550  1.82.4.1  pgoyette 	mib[1] = KERN_BUF;
    551  1.82.4.1  pgoyette 	mib[2] = KERN_BUF_ALL;
    552  1.82.4.1  pgoyette 	mib[3] = KERN_BUF_ALL;
    553  1.82.4.1  pgoyette 	mib[4] = (int)sizeof(struct buf_sysctl);
    554  1.82.4.1  pgoyette 	mib[5] = INT_MAX; /* we want them all */
    555  1.82.4.1  pgoyette again:
    556  1.82.4.1  pgoyette 	if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) {
    557  1.82.4.1  pgoyette 		error("can't get buffers size: %s\n", strerror(errno));
    558  1.82.4.1  pgoyette 		return;
    559  1.82.4.1  pgoyette 	}
    560  1.82.4.1  pgoyette 	if (size == 0) {
    561  1.82.4.1  pgoyette 		error("buffers size is zero: %s\n", strerror(errno));
    562  1.82.4.1  pgoyette 		return;
    563  1.82.4.1  pgoyette 	}
    564  1.82.4.1  pgoyette 	size += extraslop * sizeof(struct buf_sysctl);
    565  1.82.4.1  pgoyette 	buffers = malloc(size);
    566  1.82.4.1  pgoyette 	if (buffers == NULL) {
    567  1.82.4.1  pgoyette 		error("can't allocate buffers: %s\n", strerror(errno));
    568  1.82.4.1  pgoyette 		return;
    569  1.82.4.1  pgoyette 	}
    570  1.82.4.1  pgoyette 	if (sysctl(mib, 6, buffers, &size, NULL, 0) < 0) {
    571  1.82.4.1  pgoyette 		free(buffers);
    572  1.82.4.1  pgoyette 		if (extraslop == 0) {
    573  1.82.4.1  pgoyette 			extraslop = 100;
    574  1.82.4.1  pgoyette 			goto again;
    575  1.82.4.1  pgoyette 		}
    576  1.82.4.1  pgoyette 		error("can't get buffers: %s\n", strerror(errno));
    577  1.82.4.1  pgoyette 		return;
    578  1.82.4.1  pgoyette 	}
    579  1.82.4.1  pgoyette 	free(buffers);			/* XXX there must be a better way! */
    580  1.82.4.1  pgoyette 	nbuf = size / sizeof(struct buf_sysctl);
    581  1.82.4.1  pgoyette 
    582  1.82.4.1  pgoyette 	putint((int) (bufmem / 1024),		MEMROW + 3, MEMCOL + 5, 12);
    583  1.82.4.1  pgoyette 	putint((int) ((bufmem * 100) + 0.5) / s.uvmexp.pagesize / s.uvmexp.npages,
    584  1.82.4.1  pgoyette 						MEMROW + 3, MEMCOL + 17, 4);
    585  1.82.4.1  pgoyette 	putint(nbuf,				MEMROW + 3, MEMCOL + 30, 8);
    586  1.82.4.1  pgoyette 
    587  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.active),		MEMROW + 5, MEMCOL + 7, 10);
    588  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.swpgonly),	MEMROW + 5, MEMCOL + 18, 10);
    589  1.82.4.1  pgoyette 	putint(pgtokb(s.uvmexp.free),		MEMROW + 5, MEMCOL + 28, 10);
    590  1.82.4.1  pgoyette 
    591      1.63       dsl #undef pgtokb
    592      1.63       dsl 
    593      1.63       dsl 	/* Namei cache */
    594      1.63       dsl 	Z(s, s1, ncs_goodhits); Z(s, s1, ncs_badhits); Z(s, s1, ncs_miss);
    595      1.63       dsl 	Z(s, s1, ncs_long); Z(s, s1, ncs_pass2); Z(s, s1, ncs_2passes);
    596      1.63       dsl 	s.nchcount = s.nchstats.ncs_goodhits + s.nchstats.ncs_badhits +
    597      1.77     njoly 	    s.nchstats.ncs_miss + s.nchstats.ncs_long +
    598      1.77     njoly 	    s.nchstats.ncs_pass2 + s.nchstats.ncs_2passes;
    599      1.63       dsl 	if (display_mode == TIME)
    600      1.63       dsl 		s1.nchcount = s.nchcount;
    601      1.63       dsl 
    602      1.63       dsl 	putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
    603      1.63       dsl 	putint(s.nchstats.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 9, 9);
    604      1.63       dsl #define nz(x)	((x) ? (x) : 1)
    605      1.63       dsl 	putfloat(s.nchstats.ncs_goodhits * 100.0 / nz(s.nchcount),
    606      1.63       dsl 	   NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
    607      1.63       dsl 	putint(s.nchstats.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
    608      1.63       dsl 	putfloat(s.nchstats.ncs_pass2 * 100.0 / nz(s.nchcount),
    609      1.63       dsl 	   NAMEIROW + 2, NAMEICOL + 34, 4, 0, 1);
    610      1.63       dsl #undef nz
    611      1.12       mrg 
    612      1.63       dsl 	/* Disks */
    613      1.61     blymn 	for (l = 0, i = 0, r = DISKROW, c = DISKCOL;
    614      1.73     lukem 	     i < (int)ndrive; i++) {
    615      1.65     blymn 		if (!drv_select[i])
    616      1.65     blymn 			continue;
    617      1.61     blymn 
    618      1.49       dsl 		if (disk_horiz)
    619      1.49       dsl 			c += DISKCOLWIDTH;
    620      1.49       dsl 		else
    621      1.49       dsl 			r++;
    622      1.49       dsl 		if (c + DISKCOLWIDTH > DISKCOLEND) {
    623      1.49       dsl 			if (disk_horiz && LINES - 1 - DISKROW >
    624      1.61     blymn 			    (DISKCOLEND - DISKCOL) / DISKCOLWIDTH) {
    625      1.49       dsl 				disk_horiz = 0;
    626      1.49       dsl 				relabel = 1;
    627      1.49       dsl 			}
    628      1.49       dsl 			break;
    629       1.1       jtc 		}
    630      1.49       dsl 		if (r >= LINES - 1) {
    631      1.49       dsl 			if (!disk_horiz && LINES - 1 - DISKROW <
    632      1.61     blymn 			    (DISKCOLEND - DISKCOL) / DISKCOLWIDTH) {
    633      1.49       dsl 				disk_horiz = 1;
    634      1.49       dsl 				relabel = 1;
    635      1.49       dsl 			}
    636      1.49       dsl 			break;
    637      1.49       dsl 		}
    638      1.49       dsl 		l++;
    639      1.49       dsl 
    640      1.65     blymn 		dinfo(i, r, c);
    641      1.49       dsl 	}
    642      1.49       dsl 	/* blank out if we lost any disks */
    643      1.49       dsl 	for (i = l; i < last_disks; i++) {
    644      1.49       dsl 		int j;
    645      1.49       dsl 		if (disk_horiz)
    646      1.49       dsl 			c += DISKCOLWIDTH;
    647      1.49       dsl 		else
    648      1.49       dsl 			r++;
    649      1.49       dsl 		for (j = 0; j < 5; j++) {
    650      1.49       dsl 			if (disk_horiz)
    651      1.56   mycroft 				mvprintw(r+j, c, "%*s", DISKCOLWIDTH, "");
    652      1.49       dsl 			else
    653      1.56   mycroft 				mvprintw(r, c+j*DISKCOLWIDTH, "%*s", DISKCOLWIDTH, "");
    654      1.49       dsl 		}
    655      1.49       dsl 	}
    656      1.49       dsl 	last_disks = l;
    657      1.63       dsl 
    658      1.63       dsl 	/* Interrupts */
    659      1.63       dsl 	failcnt = 0;
    660      1.63       dsl 	inttotal = 0;
    661      1.63       dsl 	for (i = 0; i < nintr; i++) {
    662      1.63       dsl 		if (s.intrcnt[i] == 0)
    663      1.63       dsl 			continue;
    664      1.63       dsl 		if (intrloc[i] == 0) {
    665      1.63       dsl 			if (nextintsrow == LINES)
    666      1.63       dsl 				continue;
    667      1.63       dsl 			intrloc[i] = nextintsrow++;
    668      1.63       dsl 			mvprintw(intrloc[i], INTSCOL + 9, "%-.*s",
    669      1.63       dsl 				INTSCOLEND - (INTSCOL + 9), intrname[i]);
    670      1.63       dsl 		}
    671      1.63       dsl 		X(s, s1, intrcnt);
    672      1.63       dsl 		l = (int)((float)s.intrcnt[i]/etime + 0.5);
    673      1.63       dsl 		inttotal += l;
    674      1.63       dsl 		putint(l, intrloc[i], INTSCOL, 8);
    675      1.63       dsl 	}
    676      1.63       dsl 
    677      1.63       dsl 	for (i = 0; i < nevcnt; i++) {
    678      1.63       dsl 		if (s.evcnt[i] == 0)
    679      1.63       dsl 			continue;
    680      1.63       dsl 		if (ie_head[i].ie_loc == 0) {
    681      1.63       dsl 			if (nextintsrow == LINES)
    682      1.63       dsl 				continue;
    683      1.63       dsl 			ie_head[i].ie_loc = nextintsrow++;
    684      1.63       dsl 			print_ie_title(i);
    685      1.63       dsl 		}
    686      1.63       dsl 		X(s, s1, evcnt);
    687      1.63       dsl 		l = (int)((float)s.evcnt[i]/etime + 0.5);
    688      1.63       dsl 		inttotal += l;
    689      1.63       dsl 		putint(l, ie_head[i].ie_loc, INTSCOL, 8);
    690      1.63       dsl 	}
    691      1.63       dsl 	putint(inttotal, INTSROW, INTSCOL, 8);
    692      1.63       dsl 
    693      1.63       dsl 	PUTRATE(s, s1, uvmexp.forks, VMSTATROW + 0, VMSTATCOL + 3, 6);
    694      1.63       dsl 	PUTRATE(s, s1, uvmexp.forks_ppwait, VMSTATROW + 1, VMSTATCOL + 3, 6);
    695      1.63       dsl 	PUTRATE(s, s1, uvmexp.forks_sharevm, VMSTATROW + 2, VMSTATCOL + 3, 6);
    696      1.63       dsl 	PUTRATE(s, s1, uvmexp.fltpgwait, VMSTATROW + 3, VMSTATCOL + 4, 5);
    697      1.63       dsl 	PUTRATE(s, s1, uvmexp.fltrelck, VMSTATROW + 4, VMSTATCOL + 3, 6);
    698      1.63       dsl 	PUTRATE(s, s1, uvmexp.fltrelckok, VMSTATROW + 5, VMSTATCOL + 3, 6);
    699      1.63       dsl 	PUTRATE(s, s1, uvmexp.fltnoram, VMSTATROW + 6, VMSTATCOL + 3, 6);
    700      1.63       dsl 	PUTRATE(s, s1, uvmexp.fltamcopy, VMSTATROW + 7, VMSTATCOL + 3, 6);
    701      1.63       dsl 	PUTRATE(s, s1, uvmexp.flt_prcopy, VMSTATROW + 8, VMSTATCOL + 3, 6);
    702      1.63       dsl 	PUTRATE(s, s1, uvmexp.flt_przero, VMSTATROW + 9, VMSTATCOL + 3, 6);
    703      1.63       dsl 	PUTRATE(s, s1, uvmexp.flt_acow, VMSTATROW + 10, VMSTATCOL, 9);
    704      1.63       dsl 	putint(s.uvmexp.freemin, VMSTATROW + 11, VMSTATCOL, 9);
    705      1.63       dsl 	putint(s.uvmexp.freetarg, VMSTATROW + 12, VMSTATCOL, 9);
    706      1.63       dsl 	putint(s.uvmexp.inactarg, VMSTATROW + 13, VMSTATCOL, 9);
    707  1.82.4.1  pgoyette 	putint(s.uvmexp.fltnoanon, VMSTATROW + 14, VMSTATCOL, 9);
    708      1.63       dsl 	PUTRATE(s, s1, uvmexp.pdfreed, VMSTATROW + 15, VMSTATCOL, 9);
    709      1.63       dsl 	if (LINES - 1 > VMSTATROW + 16)
    710      1.63       dsl 		PUTRATE(s, s1, uvmexp.pdscans, VMSTATROW + 16, VMSTATCOL, 9);
    711      1.63       dsl 
    712       1.1       jtc }
    713       1.1       jtc 
    714      1.22     jwise void
    715      1.33        ad vmstat_boot(char *args)
    716      1.22     jwise {
    717      1.22     jwise 	copyinfo(&z, &s1);
    718      1.63       dsl 	display_mode = BOOT;
    719      1.22     jwise }
    720      1.22     jwise 
    721      1.22     jwise void
    722      1.33        ad vmstat_run(char *args)
    723      1.22     jwise {
    724      1.22     jwise 	copyinfo(&s1, &s2);
    725      1.63       dsl 	display_mode = RUN;
    726      1.22     jwise }
    727      1.22     jwise 
    728      1.22     jwise void
    729      1.44       dsl vmstat_time(char *args)
    730       1.1       jtc {
    731      1.63       dsl 	display_mode = TIME;
    732      1.22     jwise }
    733       1.1       jtc 
    734      1.22     jwise void
    735      1.33        ad vmstat_zero(char *args)
    736      1.22     jwise {
    737      1.63       dsl 	if (display_mode == RUN)
    738      1.63       dsl 		getinfo(&s1);
    739       1.1       jtc }
    740       1.1       jtc 
    741       1.1       jtc /* calculate number of users on the system */
    742       1.1       jtc static int
    743      1.33        ad ucount(void)
    744       1.1       jtc {
    745      1.40  christos 	static int onusers = -1;
    746      1.40  christos 	int nusers = 0;
    747      1.40  christos 	struct utmpentry *ehead;
    748      1.40  christos 
    749      1.40  christos 	nusers = getutentries(NULL, &ehead);
    750       1.1       jtc 
    751      1.21       mrg 	if (nusers != onusers) {
    752      1.21       mrg 		if (nusers == 1)
    753      1.21       mrg 			mvprintw(STATROW, STATCOL + 8, " ");
    754      1.21       mrg 		else
    755      1.21       mrg 			mvprintw(STATROW, STATCOL + 8, "s");
    756      1.21       mrg 	}
    757      1.21       mrg 	onusers = nusers;
    758       1.1       jtc 	return (nusers);
    759       1.1       jtc }
    760       1.1       jtc 
    761       1.1       jtc static float
    762      1.33        ad cputime(int indx)
    763       1.1       jtc {
    764       1.1       jtc 	double t;
    765      1.10     lukem 	int i;
    766       1.1       jtc 
    767       1.1       jtc 	t = 0;
    768       1.1       jtc 	for (i = 0; i < CPUSTATES; i++)
    769      1.39  sommerfe 		t += cur.cp_time[i];
    770       1.1       jtc 	if (t == 0.0)
    771       1.1       jtc 		t = 1.0;
    772      1.39  sommerfe 	return (cur.cp_time[indx] * 100.0 / t);
    773       1.1       jtc }
    774       1.1       jtc 
    775      1.63       dsl void
    776      1.44       dsl puthumanint(u_int64_t n, int l, int c, int w)
    777      1.41       abs {
    778      1.41       abs 	char b[128];
    779      1.41       abs 
    780      1.48       dsl 	if (move(l, c) != OK)
    781      1.48       dsl 		return;
    782      1.41       abs 	if (n == 0) {
    783      1.41       abs 		hline(' ', w);
    784      1.41       abs 		return;
    785      1.41       abs 	}
    786      1.44       dsl 	if (humanize_number(b, w, n, "", HN_AUTOSCALE, HN_NOSPACE) == -1 ) {
    787      1.41       abs 		hline('*', w);
    788      1.41       abs 		return;
    789      1.41       abs 	}
    790      1.63       dsl 	printw("%*s", w, b);
    791      1.41       abs }
    792      1.41       abs 
    793      1.63       dsl void
    794      1.33        ad putint(int n, int l, int c, int w)
    795       1.1       jtc {
    796       1.1       jtc 	char b[128];
    797       1.1       jtc 
    798      1.48       dsl 	if (move(l, c) != OK)
    799      1.48       dsl 		return;
    800       1.1       jtc 	if (n == 0) {
    801      1.30   mycroft 		hline(' ', w);
    802       1.1       jtc 		return;
    803       1.1       jtc 	}
    804      1.14       mrg 	(void)snprintf(b, sizeof b, "%*d", w, n);
    805      1.73     lukem 	if ((int)strlen(b) > w) {
    806      1.63       dsl 		if (display_mode == TIME)
    807      1.63       dsl 			hline('*', w);
    808      1.63       dsl 		else
    809      1.63       dsl 			puthumanint(n, l, c, w);
    810       1.1       jtc 		return;
    811       1.1       jtc 	}
    812       1.1       jtc 	addstr(b);
    813       1.1       jtc }
    814       1.1       jtc 
    815      1.63       dsl void
    816      1.33        ad putfloat(double f, int l, int c, int w, int d, int nz)
    817       1.1       jtc {
    818       1.1       jtc 	char b[128];
    819       1.1       jtc 
    820      1.48       dsl 	if (move(l, c) != OK)
    821      1.48       dsl 		return;
    822       1.1       jtc 	if (nz && f == 0.0) {
    823      1.30   mycroft 		hline(' ', w);
    824       1.1       jtc 		return;
    825       1.1       jtc 	}
    826      1.14       mrg 	(void)snprintf(b, sizeof b, "%*.*f", w, d, f);
    827      1.73     lukem 	if ((int)strlen(b) > w) {
    828      1.30   mycroft 		hline('*', w);
    829       1.1       jtc 		return;
    830       1.1       jtc 	}
    831       1.1       jtc 	addstr(b);
    832       1.1       jtc }
    833       1.1       jtc 
    834       1.1       jtc static void
    835      1.63       dsl getinfo(struct Info *stats)
    836       1.1       jtc {
    837       1.4       cgd 	int mib[2];
    838       1.4       cgd 	size_t size;
    839      1.44       dsl 	int i;
    840       1.1       jtc 
    841      1.62       dsl 	cpureadstats();
    842      1.65     blymn 	drvreadstats();
    843      1.78     joerg 	size = sizeof(stats->nchstats);
    844      1.78     joerg 	if (sysctlbyname("vfs.namecache_stats", &stats->nchstats, &size,
    845      1.78     joerg 	    NULL, 0) < 0) {
    846      1.78     joerg 		error("can't get namecache statistics: %s\n", strerror(errno));
    847      1.78     joerg 		memset(&stats->nchstats, 0, sizeof(stats->nchstats));
    848      1.78     joerg 	}
    849      1.60       chs 	if (nintr)
    850  1.82.4.1  pgoyette 		NREAD(X_INTRCNT, stats->intrcnt, nintr * sizeof(long));
    851      1.44       dsl 	for (i = 0; i < nevcnt; i++)
    852      1.60       chs 		KREAD(ie_head[i].ie_count, &stats->evcnt[i],
    853      1.60       chs 		      sizeof stats->evcnt[i]);
    854      1.59       dsl 	size = sizeof(stats->uvmexp);
    855      1.11       mrg 	mib[0] = CTL_VM;
    856      1.34    simonb 	mib[1] = VM_UVMEXP2;
    857      1.59       dsl 	if (sysctl(mib, 2, &stats->uvmexp, &size, NULL, 0) < 0) {
    858      1.11       mrg 		error("can't get uvmexp: %s\n", strerror(errno));
    859      1.59       dsl 		memset(&stats->uvmexp, 0, sizeof(stats->uvmexp));
    860      1.11       mrg 	}
    861      1.59       dsl 	size = sizeof(stats->Total);
    862       1.1       jtc 	mib[0] = CTL_VM;
    863       1.1       jtc 	mib[1] = VM_METER;
    864      1.59       dsl 	if (sysctl(mib, 2, &stats->Total, &size, NULL, 0) < 0) {
    865       1.1       jtc 		error("Can't get kernel info: %s\n", strerror(errno));
    866      1.59       dsl 		memset(&stats->Total, 0, sizeof(stats->Total));
    867       1.1       jtc 	}
    868       1.1       jtc }
    869       1.1       jtc 
    870       1.1       jtc static void
    871      1.59       dsl allocinfo(struct Info *stats)
    872       1.1       jtc {
    873       1.1       jtc 
    874      1.60       chs 	if (nintr &&
    875      1.60       chs 	    (stats->intrcnt = calloc(nintr, sizeof(long))) == NULL) {
    876      1.44       dsl 		error("calloc failed");
    877      1.44       dsl 		die(0);
    878      1.44       dsl 	}
    879      1.59       dsl 	if ((stats->evcnt = calloc(nevcnt, sizeof(u_int64_t))) == NULL) {
    880      1.44       dsl 		error("calloc failed");
    881      1.23     jwise 		die(0);
    882      1.23     jwise 	}
    883       1.1       jtc }
    884       1.1       jtc 
    885       1.1       jtc static void
    886      1.33        ad copyinfo(struct Info *from, struct Info *to)
    887       1.1       jtc {
    888       1.1       jtc 	long *intrcnt;
    889      1.44       dsl 	u_int64_t *evcnt;
    890       1.1       jtc 
    891       1.5   thorpej 	intrcnt = to->intrcnt;
    892      1.44       dsl 	evcnt = to->evcnt;
    893       1.1       jtc 	*to = *from;
    894      1.54       dsl 	memmove(to->intrcnt = intrcnt, from->intrcnt, nintr * sizeof *intrcnt);
    895      1.44       dsl 	memmove(to->evcnt = evcnt, from->evcnt, nevcnt * sizeof *evcnt);
    896       1.1       jtc }
    897       1.1       jtc 
    898       1.1       jtc static void
    899      1.49       dsl dinfo(int dn, int r, int c)
    900       1.1       jtc {
    901      1.82   mlelstv 	double atime, dtime;
    902      1.49       dsl #define ADV if (disk_horiz) r++; else c += DISKCOLWIDTH
    903      1.49       dsl 
    904      1.82   mlelstv 	/* elapsed time for disk stats */
    905      1.82   mlelstv 	dtime = etime;
    906      1.82   mlelstv 	if (cur.timestamp[dn].tv_sec || cur.timestamp[dn].tv_usec) {
    907      1.82   mlelstv 		dtime = (double)cur.timestamp[dn].tv_sec +
    908      1.82   mlelstv 			((double)cur.timestamp[dn].tv_usec / (double)1000000);
    909      1.82   mlelstv 	}
    910      1.82   mlelstv 
    911      1.49       dsl 	mvprintw(r, c, "%*.*s", DISKCOLWIDTH, DISKCOLWIDTH, dr_name[dn]);
    912      1.49       dsl 	ADV;
    913       1.1       jtc 
    914      1.82   mlelstv 	putint((int)(cur.seek[dn]/dtime+0.5), r, c, DISKCOLWIDTH);
    915      1.61     blymn 	ADV;
    916      1.82   mlelstv 	putint((int)((cur.rxfer[dn]+cur.wxfer[dn])/dtime+0.5),
    917      1.61     blymn 	    r, c, DISKCOLWIDTH);
    918      1.61     blymn 	ADV;
    919      1.82   mlelstv 	puthumanint((cur.rbytes[dn] + cur.wbytes[dn]) / dtime + 0.5,
    920      1.61     blymn 		    r, c, DISKCOLWIDTH);
    921      1.61     blymn 	ADV;
    922      1.61     blymn 
    923      1.61     blymn 	/* time busy in disk activity */
    924      1.65     blymn 	atime = cur.time[dn].tv_sec + cur.time[dn].tv_usec / 1000000.0;
    925      1.82   mlelstv 	atime = atime * 100.0 / dtime;
    926      1.61     blymn 	if (atime >= 100)
    927      1.61     blymn 		putint(100, r, c, DISKCOLWIDTH);
    928      1.61     blymn 	else
    929      1.61     blymn 		putfloat(atime, r, c, DISKCOLWIDTH, 1, 1);
    930       1.1       jtc }
    931