1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1983, 1989, 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#ifdef lint
|
|
|
|
static const char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
|
1997-08-13 06:45:11 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cursed vmstat -- from Robert Elz.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/proc.h>
|
1995-12-13 15:01:13 +00:00
|
|
|
#include <sys/uio.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/namei.h>
|
2003-02-16 15:46:25 +00:00
|
|
|
#include <sys/resource.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/sysctl.h>
|
1995-12-13 11:34:46 +00:00
|
|
|
#include <sys/vmmeter.h>
|
1995-12-13 15:01:13 +00:00
|
|
|
|
|
|
|
#include <vm/vm_param.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1997-08-13 06:45:11 +00:00
|
|
|
#include <err.h>
|
2000-04-14 06:39:19 +00:00
|
|
|
#include <errno.h>
|
2001-03-21 20:32:20 +00:00
|
|
|
#include <langinfo.h>
|
1997-08-13 06:45:11 +00:00
|
|
|
#include <nlist.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <paths.h>
|
1997-08-13 06:45:11 +00:00
|
|
|
#include <signal.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdlib.h>
|
1997-08-13 06:45:11 +00:00
|
|
|
#include <string.h>
|
1996-03-31 16:39:26 +00:00
|
|
|
#include <time.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <unistd.h>
|
2010-01-13 18:09:54 +00:00
|
|
|
#include <utmpx.h>
|
1998-09-15 08:16:45 +00:00
|
|
|
#include <devstat.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "systat.h"
|
|
|
|
#include "extern.h"
|
1998-10-08 09:56:10 +00:00
|
|
|
#include "devs.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
static struct Info {
|
|
|
|
long time[CPUSTATES];
|
2001-03-23 03:58:25 +00:00
|
|
|
u_int v_swtch; /* context switches */
|
|
|
|
u_int v_trap; /* calls to trap */
|
|
|
|
u_int v_syscall; /* calls to syscall() */
|
|
|
|
u_int v_intr; /* device interrupts */
|
|
|
|
u_int v_soft; /* software interrupts */
|
|
|
|
/*
|
|
|
|
* Virtual memory activity.
|
|
|
|
*/
|
|
|
|
u_int v_vm_faults; /* number of address memory faults */
|
|
|
|
u_int v_cow_faults; /* number of copy-on-writes */
|
|
|
|
u_int v_zfod; /* pages zero filled on demand */
|
|
|
|
u_int v_ozfod; /* optimized zero fill pages */
|
|
|
|
u_int v_swapin; /* swap pager pageins */
|
|
|
|
u_int v_swapout; /* swap pager pageouts */
|
|
|
|
u_int v_swappgsin; /* swap pager pages paged in */
|
|
|
|
u_int v_swappgsout; /* swap pager pages paged out */
|
|
|
|
u_int v_vnodein; /* vnode pager pageins */
|
|
|
|
u_int v_vnodeout; /* vnode pager pageouts */
|
|
|
|
u_int v_vnodepgsin; /* vnode_pager pages paged in */
|
|
|
|
u_int v_vnodepgsout; /* vnode pager pages paged out */
|
|
|
|
u_int v_intrans; /* intransit blocking page faults */
|
|
|
|
u_int v_reactivated; /* number of pages reactivated from free list */
|
|
|
|
u_int v_pdwakeups; /* number of times daemon has awaken from sleep */
|
|
|
|
u_int v_pdpages; /* number of pages analyzed by daemon */
|
|
|
|
|
|
|
|
u_int v_dfree; /* pages freed by daemon */
|
|
|
|
u_int v_pfree; /* pages freed by exiting processes */
|
|
|
|
u_int v_tfree; /* total pages freed */
|
|
|
|
/*
|
|
|
|
* Distribution of page usages.
|
|
|
|
*/
|
|
|
|
u_int v_page_size; /* page size in bytes */
|
|
|
|
u_int v_free_count; /* number of pages free */
|
|
|
|
u_int v_wire_count; /* number of pages wired down */
|
|
|
|
u_int v_active_count; /* number of pages active */
|
|
|
|
u_int v_inactive_count; /* number of pages inactive */
|
|
|
|
u_int v_cache_count; /* number of pages on buffer cache queue */
|
1994-05-27 12:33:43 +00:00
|
|
|
struct vmtotal Total;
|
|
|
|
struct nchstats nchstats;
|
|
|
|
long nchcount;
|
|
|
|
long *intrcnt;
|
2009-03-10 15:25:19 +00:00
|
|
|
long bufspace;
|
1997-09-25 01:14:25 +00:00
|
|
|
int desiredvnodes;
|
2000-12-02 20:08:33 +00:00
|
|
|
long numvnodes;
|
|
|
|
long freevnodes;
|
2001-03-29 02:18:19 +00:00
|
|
|
int numdirtybuffers;
|
1994-05-27 12:33:43 +00:00
|
|
|
} s, s1, s2, z;
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
struct statinfo cur, last, run;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#define total s.Total
|
|
|
|
#define nchtotal s.nchstats
|
|
|
|
#define oldnchtotal s1.nchstats
|
|
|
|
|
|
|
|
static enum state { BOOT, TIME, RUN } state = TIME;
|
|
|
|
|
2002-03-22 01:42:45 +00:00
|
|
|
static void allocinfo(struct Info *);
|
|
|
|
static void copyinfo(struct Info *, struct Info *);
|
|
|
|
static float cputime(int);
|
|
|
|
static void dinfo(int, int, struct statinfo *, struct statinfo *);
|
|
|
|
static void getinfo(struct Info *);
|
|
|
|
static void putint(int, int, int, int);
|
|
|
|
static void putfloat(double, int, int, int, int, int);
|
|
|
|
static void putlongdouble(long double, int, int, int, int, int);
|
|
|
|
static int ucount(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-05-27 21:01:37 +00:00
|
|
|
static int ncpu;
|
1994-05-27 12:33:43 +00:00
|
|
|
static char buf[26];
|
|
|
|
static time_t t;
|
|
|
|
static double etime;
|
|
|
|
static int nintr;
|
|
|
|
static long *intrloc;
|
|
|
|
static char **intrname;
|
|
|
|
static int nextintsrow;
|
|
|
|
|
|
|
|
WINDOW *
|
2008-01-16 19:27:43 +00:00
|
|
|
openkre(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (stdscr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-16 19:27:43 +00:00
|
|
|
closekre(WINDOW *w)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (w == NULL)
|
|
|
|
return;
|
|
|
|
wclear(w);
|
|
|
|
wrefresh(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These constants define where the major pieces are laid out
|
|
|
|
*/
|
2006-02-14 08:33:02 +00:00
|
|
|
#define STATROW 0 /* uses 1 row and 67 cols */
|
2006-02-14 13:27:25 +00:00
|
|
|
#define STATCOL 0
|
2006-02-14 08:33:02 +00:00
|
|
|
#define MEMROW 2 /* uses 4 rows and 45 cols */
|
1994-05-27 12:33:43 +00:00
|
|
|
#define MEMCOL 0
|
2006-04-30 23:52:16 +00:00
|
|
|
#define PAGEROW 2 /* uses 4 rows and 30 cols */
|
2006-02-14 13:27:25 +00:00
|
|
|
#define PAGECOL 47
|
2006-02-14 10:47:36 +00:00
|
|
|
#define INTSROW 6 /* uses all rows to bottom and 16 cols */
|
|
|
|
#define INTSCOL 64
|
2006-02-14 13:27:25 +00:00
|
|
|
#define PROCSROW 6 /* uses 3 rows and 19 cols */
|
1994-05-27 12:33:43 +00:00
|
|
|
#define PROCSCOL 0
|
2006-02-14 10:47:36 +00:00
|
|
|
#define GENSTATROW 7 /* uses 2 rows and 29 cols */
|
|
|
|
#define GENSTATCOL 21
|
2006-04-30 23:52:16 +00:00
|
|
|
#define VMSTATROW 7 /* uses 17 rows and 12-14 cols */
|
|
|
|
#define VMSTATCOL 49 /* actually 50-51 for some fields */
|
|
|
|
#define GRAPHROW 10 /* uses 3 rows and 49-51 cols */
|
1994-05-27 12:33:43 +00:00
|
|
|
#define GRAPHCOL 0
|
2006-04-30 20:31:00 +00:00
|
|
|
#define VNSTATROW 13 /* uses 4 rows and 13 columns */
|
|
|
|
#define VNSTATCOL 35
|
|
|
|
#define NAMEIROW 14 /* uses 3 rows and 32 cols */
|
1994-05-27 12:33:43 +00:00
|
|
|
#define NAMEICOL 0
|
2006-02-14 08:33:02 +00:00
|
|
|
#define DISKROW 18 /* uses 5 rows and 47 cols (for 7 drives) */
|
1994-05-27 12:33:43 +00:00
|
|
|
#define DISKCOL 0
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
#define DRIVESPACE 7 /* max # for space */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#define MAXDRIVES DRIVESPACE /* max # to display */
|
|
|
|
|
|
|
|
int
|
2008-01-16 19:27:43 +00:00
|
|
|
initkre(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2006-04-30 01:39:46 +00:00
|
|
|
char *cp, *cp1, *cp2, *intrnamebuf, *nextcp;
|
1994-05-27 12:33:43 +00:00
|
|
|
int i;
|
2001-06-01 13:29:19 +00:00
|
|
|
size_t sz;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-09-06 04:06:12 +00:00
|
|
|
if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
|
1998-09-15 08:16:45 +00:00
|
|
|
warnx("%s", devstat_errbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
return(0);
|
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
run.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
bzero(cur.dinfo, sizeof(struct devinfo));
|
|
|
|
bzero(last.dinfo, sizeof(struct devinfo));
|
|
|
|
bzero(run.dinfo, sizeof(struct devinfo));
|
|
|
|
|
|
|
|
if (dsinit(MAXDRIVES, &cur, &last, &run) != 1)
|
|
|
|
return(0);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (nintr == 0) {
|
2001-06-01 13:29:19 +00:00
|
|
|
if (sysctlbyname("hw.intrcnt", NULL, &sz, NULL, 0) == -1) {
|
|
|
|
error("sysctl(hw.intrcnt...) failed: %s",
|
|
|
|
strerror(errno));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
nintr = sz / sizeof(u_long);
|
1994-05-27 12:33:43 +00:00
|
|
|
intrloc = calloc(nintr, sizeof (long));
|
2001-06-01 13:29:19 +00:00
|
|
|
intrname = calloc(nintr, sizeof (char *));
|
2001-03-23 03:58:25 +00:00
|
|
|
intrnamebuf = sysctl_dynread("hw.intrnames", NULL);
|
|
|
|
if (intrnamebuf == NULL || intrname == NULL ||
|
|
|
|
intrloc == NULL) {
|
|
|
|
error("Out of memory");
|
1994-05-27 12:33:43 +00:00
|
|
|
if (intrnamebuf)
|
|
|
|
free(intrnamebuf);
|
|
|
|
if (intrname)
|
|
|
|
free(intrname);
|
|
|
|
if (intrloc)
|
|
|
|
free(intrloc);
|
|
|
|
nintr = 0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
for (cp = intrnamebuf, i = 0; i < nintr; i++) {
|
2006-04-30 01:39:46 +00:00
|
|
|
nextcp = cp + strlen(cp) + 1;
|
|
|
|
|
|
|
|
/* Discard trailing spaces. */
|
|
|
|
for (cp1 = nextcp - 1; cp1 > cp && *(cp1 - 1) == ' '; )
|
|
|
|
*--cp1 = '\0';
|
|
|
|
|
|
|
|
/* Convert "irqN: name" to "name irqN". */
|
|
|
|
if (strncmp(cp, "irq", 3) == 0) {
|
|
|
|
cp1 = cp + 3;
|
|
|
|
while (isdigit((u_char)*cp1))
|
|
|
|
cp1++;
|
|
|
|
if (cp1 != cp && *cp1 == ':' &&
|
|
|
|
*(cp1 + 1) == ' ') {
|
2010-06-18 18:18:03 +00:00
|
|
|
sz = strlen(cp);
|
2006-04-30 01:39:46 +00:00
|
|
|
*cp1 = '\0';
|
|
|
|
cp1 = cp1 + 2;
|
|
|
|
cp2 = strdup(cp);
|
2010-06-18 18:18:03 +00:00
|
|
|
bcopy(cp1, cp, sz - (cp1 - cp) + 1);
|
|
|
|
/* If line is long - drop "irq",
|
|
|
|
if too long - drop "irqN". */
|
|
|
|
if (sz <= 10 + 1) {
|
|
|
|
strcat(cp, " ");
|
|
|
|
strcat(cp, cp2);
|
|
|
|
} else if (sz <= 10 + 4) {
|
|
|
|
strcat(cp, " ");
|
|
|
|
strcat(cp, cp2 + 3);
|
|
|
|
}
|
2006-04-30 01:39:46 +00:00
|
|
|
free(cp2);
|
|
|
|
}
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
intrname[i] = cp;
|
2006-04-30 01:39:46 +00:00
|
|
|
cp = nextcp;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
nextintsrow = INTSROW + 2;
|
|
|
|
allocinfo(&s);
|
|
|
|
allocinfo(&s1);
|
|
|
|
allocinfo(&s2);
|
|
|
|
allocinfo(&z);
|
|
|
|
}
|
2001-12-12 00:13:37 +00:00
|
|
|
getinfo(&s2);
|
1994-05-27 12:33:43 +00:00
|
|
|
copyinfo(&s2, &s1);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-16 19:27:43 +00:00
|
|
|
fetchkre(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
time_t now;
|
1996-03-31 16:39:26 +00:00
|
|
|
struct tm *tp;
|
2001-03-21 20:32:20 +00:00
|
|
|
static int d_first = -1;
|
|
|
|
|
|
|
|
if (d_first < 0)
|
|
|
|
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
time(&now);
|
1996-03-31 16:39:26 +00:00
|
|
|
tp = localtime(&now);
|
2001-03-21 20:32:20 +00:00
|
|
|
(void) strftime(buf, sizeof(buf),
|
|
|
|
d_first ? "%e %b %R" : "%b %e %R", tp);
|
2001-12-12 00:13:37 +00:00
|
|
|
getinfo(&s);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-16 19:27:43 +00:00
|
|
|
labelkre(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-12 00:13:37 +00:00
|
|
|
int i, j;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
clear();
|
2006-02-14 13:27:25 +00:00
|
|
|
mvprintw(STATROW, STATCOL + 6, "users Load");
|
1996-11-12 19:16:46 +00:00
|
|
|
mvprintw(MEMROW, MEMCOL, "Mem:KB REAL VIRTUAL");
|
|
|
|
mvprintw(MEMROW + 1, MEMCOL, " Tot Share Tot Share");
|
1994-05-27 12:33:43 +00:00
|
|
|
mvprintw(MEMROW + 2, MEMCOL, "Act");
|
|
|
|
mvprintw(MEMROW + 3, MEMCOL, "All");
|
|
|
|
|
1996-11-12 19:16:46 +00:00
|
|
|
mvprintw(MEMROW + 1, MEMCOL + 41, "Free");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2006-02-14 13:27:25 +00:00
|
|
|
mvprintw(PAGEROW, PAGECOL, " VN PAGER SWAP PAGER");
|
|
|
|
mvprintw(PAGEROW + 1, PAGECOL, " in out in out");
|
1994-05-27 12:33:43 +00:00
|
|
|
mvprintw(PAGEROW + 2, PAGECOL, "count");
|
|
|
|
mvprintw(PAGEROW + 3, PAGECOL, "pages");
|
|
|
|
|
2006-02-14 10:47:36 +00:00
|
|
|
mvprintw(INTSROW, INTSCOL + 1, "Interrupts");
|
|
|
|
mvprintw(INTSROW + 1, INTSCOL + 6, "total");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2006-04-30 23:52:16 +00:00
|
|
|
mvprintw(VMSTATROW, VMSTATCOL + 9, "cow");
|
|
|
|
mvprintw(VMSTATROW + 1, VMSTATCOL + 9, "zfod");
|
|
|
|
mvprintw(VMSTATROW + 2, VMSTATCOL + 9, "ozfod");
|
|
|
|
mvprintw(VMSTATROW + 3, VMSTATCOL + 9 - 1, "%%ozfod");
|
2006-05-01 07:02:52 +00:00
|
|
|
mvprintw(VMSTATROW + 4, VMSTATCOL + 9, "daefr");
|
|
|
|
mvprintw(VMSTATROW + 5, VMSTATCOL + 9, "prcfr");
|
|
|
|
mvprintw(VMSTATROW + 6, VMSTATCOL + 9, "totfr");
|
|
|
|
mvprintw(VMSTATROW + 7, VMSTATCOL + 9, "react");
|
|
|
|
mvprintw(VMSTATROW + 8, VMSTATCOL + 9, "pdwak");
|
|
|
|
mvprintw(VMSTATROW + 9, VMSTATCOL + 9, "pdpgs");
|
|
|
|
mvprintw(VMSTATROW + 10, VMSTATCOL + 9, "intrn");
|
|
|
|
mvprintw(VMSTATROW + 11, VMSTATCOL + 9, "wire");
|
|
|
|
mvprintw(VMSTATROW + 12, VMSTATCOL + 9, "act");
|
|
|
|
mvprintw(VMSTATROW + 13, VMSTATCOL + 9, "inact");
|
|
|
|
mvprintw(VMSTATROW + 14, VMSTATCOL + 9, "cache");
|
|
|
|
mvprintw(VMSTATROW + 15, VMSTATCOL + 9, "free");
|
2006-05-01 00:26:43 +00:00
|
|
|
if (LINES - 1 > VMSTATROW + 16)
|
|
|
|
mvprintw(VMSTATROW + 16, VMSTATCOL + 9, "buf");
|
1997-09-25 01:14:25 +00:00
|
|
|
|
2006-02-14 10:47:36 +00:00
|
|
|
mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
mvprintw(GRAPHROW, GRAPHCOL,
|
1994-12-03 10:06:40 +00:00
|
|
|
" . %%Sys . %%Intr . %%User . %%Nice . %%Idle");
|
2006-02-14 13:27:25 +00:00
|
|
|
mvprintw(PROCSROW, PROCSCOL, "Proc:");
|
|
|
|
mvprintw(PROCSROW + 1, PROCSCOL, " r p d s w");
|
1994-05-27 12:33:43 +00:00
|
|
|
mvprintw(GRAPHROW + 1, GRAPHCOL,
|
|
|
|
"| | | | | | | | | | |");
|
|
|
|
|
2006-04-30 20:31:00 +00:00
|
|
|
mvprintw(VNSTATROW, VNSTATCOL + 8, "dtbuf");
|
|
|
|
mvprintw(VNSTATROW + 1, VNSTATCOL + 8, "desvn");
|
|
|
|
mvprintw(VNSTATROW + 2, VNSTATCOL + 8, "numvn");
|
|
|
|
mvprintw(VNSTATROW + 3, VNSTATCOL + 8, "frevn");
|
|
|
|
|
|
|
|
mvprintw(NAMEIROW, NAMEICOL, "Namei Name-cache Dir-cache");
|
1994-05-27 12:33:43 +00:00
|
|
|
mvprintw(NAMEIROW + 1, NAMEICOL,
|
2006-04-30 20:31:00 +00:00
|
|
|
" Calls hits %% hits %%");
|
1999-09-19 18:04:54 +00:00
|
|
|
mvprintw(DISKROW, DISKCOL, "Disks");
|
1998-09-15 08:16:45 +00:00
|
|
|
mvprintw(DISKROW + 1, DISKCOL, "KB/t");
|
|
|
|
mvprintw(DISKROW + 2, DISKCOL, "tps");
|
|
|
|
mvprintw(DISKROW + 3, DISKCOL, "MB/s");
|
2006-02-14 10:47:36 +00:00
|
|
|
mvprintw(DISKROW + 4, DISKCOL, "%%busy");
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* For now, we don't support a fourth disk statistic. So there's
|
|
|
|
* no point in providing a label for it. If someone can think of a
|
|
|
|
* fourth useful disk statistic, there is room to add it.
|
|
|
|
*/
|
|
|
|
/* mvprintw(DISKROW + 4, DISKCOL, " msps"); */
|
1994-05-27 12:33:43 +00:00
|
|
|
j = 0;
|
1998-09-15 08:16:45 +00:00
|
|
|
for (i = 0; i < num_devices && j < MAXDRIVES; i++)
|
|
|
|
if (dev_select[i].selected) {
|
|
|
|
char tmpstr[80];
|
|
|
|
sprintf(tmpstr, "%s%d", dev_select[i].device_name,
|
|
|
|
dev_select[i].unit_number);
|
|
|
|
mvprintw(DISKROW, DISKCOL + 5 + 6 * j,
|
|
|
|
" %5.5s", tmpstr);
|
1994-05-27 12:33:43 +00:00
|
|
|
j++;
|
|
|
|
}
|
1999-02-08 02:11:52 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
for (i = 0; i < nintr; i++) {
|
|
|
|
if (intrloc[i] == 0)
|
|
|
|
continue;
|
2006-02-14 10:47:36 +00:00
|
|
|
mvprintw(intrloc[i], INTSCOL + 6, "%-10.10s", intrname[i]);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
|
1998-09-15 08:16:45 +00:00
|
|
|
#define Q(fld) {t=cur.fld[i]; cur.fld[i]-=last.fld[i]; if(state==TIME) last.fld[i]=t;}
|
1994-05-27 12:33:43 +00:00
|
|
|
#define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
|
|
|
|
#define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
|
|
|
|
if(state == TIME) s1.nchstats.fld = t;}
|
|
|
|
#define PUTRATE(fld, l, c, w) \
|
2006-02-14 09:33:51 +00:00
|
|
|
do { \
|
1994-05-27 12:33:43 +00:00
|
|
|
Y(fld); \
|
2006-02-14 09:33:51 +00:00
|
|
|
putint((int)((float)s.fld/etime + 0.5), l, c, w); \
|
|
|
|
} while (0)
|
1994-05-27 12:33:43 +00:00
|
|
|
#define MAXFAIL 5
|
|
|
|
|
1994-12-03 10:06:40 +00:00
|
|
|
static char cpuchar[CPUSTATES] = { '=' , '+', '>', '-', ' ' };
|
|
|
|
static char cpuorder[CPUSTATES] = { CP_SYS, CP_INTR, CP_USER, CP_NICE,
|
|
|
|
CP_IDLE };
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
void
|
2008-01-16 19:27:43 +00:00
|
|
|
showkre(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
float f1, f2;
|
|
|
|
int psiz, inttotal;
|
2006-04-30 00:50:08 +00:00
|
|
|
int i, l, lc;
|
1994-05-27 12:33:43 +00:00
|
|
|
static int failcnt = 0;
|
|
|
|
|
|
|
|
etime = 0;
|
|
|
|
for(i = 0; i < CPUSTATES; i++) {
|
|
|
|
X(time);
|
1998-09-15 08:16:45 +00:00
|
|
|
Q(cp_time);
|
1994-05-27 12:33:43 +00:00
|
|
|
etime += s.time[i];
|
|
|
|
}
|
|
|
|
if (etime < 5.0) { /* < 5 ticks - ignore this trash */
|
|
|
|
if (failcnt++ >= MAXFAIL) {
|
|
|
|
clear();
|
|
|
|
mvprintw(2, 10, "The alternate system clock has died!");
|
|
|
|
mvprintw(3, 10, "Reverting to ``pigs'' display.");
|
|
|
|
move(CMDLINE, 0);
|
|
|
|
refresh();
|
|
|
|
failcnt = 0;
|
|
|
|
sleep(5);
|
|
|
|
command("pigs");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
failcnt = 0;
|
|
|
|
etime /= hertz;
|
1998-05-27 21:01:37 +00:00
|
|
|
etime /= ncpu;
|
1994-05-27 12:33:43 +00:00
|
|
|
inttotal = 0;
|
|
|
|
for (i = 0; i < nintr; i++) {
|
|
|
|
if (s.intrcnt[i] == 0)
|
|
|
|
continue;
|
|
|
|
if (intrloc[i] == 0) {
|
|
|
|
if (nextintsrow == LINES)
|
|
|
|
continue;
|
|
|
|
intrloc[i] = nextintsrow++;
|
2006-02-14 10:47:36 +00:00
|
|
|
mvprintw(intrloc[i], INTSCOL + 6, "%-10.10s",
|
2006-04-30 00:50:08 +00:00
|
|
|
intrname[i]);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
X(intrcnt);
|
|
|
|
l = (int)((float)s.intrcnt[i]/etime + 0.5);
|
|
|
|
inttotal += l;
|
2006-02-14 10:47:36 +00:00
|
|
|
putint(l, intrloc[i], INTSCOL, 5);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2006-02-14 10:47:36 +00:00
|
|
|
putint(inttotal, INTSROW + 1, INTSCOL, 5);
|
1994-05-27 12:33:43 +00:00
|
|
|
Z(ncs_goodhits); Z(ncs_badhits); Z(ncs_miss);
|
1995-03-18 08:55:15 +00:00
|
|
|
Z(ncs_long); Z(ncs_pass2); Z(ncs_2passes); Z(ncs_neghits);
|
1994-05-27 12:33:43 +00:00
|
|
|
s.nchcount = nchtotal.ncs_goodhits + nchtotal.ncs_badhits +
|
1995-03-12 01:58:18 +00:00
|
|
|
nchtotal.ncs_miss + nchtotal.ncs_long + nchtotal.ncs_neghits;
|
1994-05-27 12:33:43 +00:00
|
|
|
if (state == TIME)
|
|
|
|
s1.nchcount = s.nchcount;
|
|
|
|
|
|
|
|
psiz = 0;
|
|
|
|
f2 = 0.0;
|
2001-12-12 00:13:37 +00:00
|
|
|
for (lc = 0; lc < CPUSTATES; lc++) {
|
|
|
|
i = cpuorder[lc];
|
1994-05-27 12:33:43 +00:00
|
|
|
f1 = cputime(i);
|
|
|
|
f2 += f1;
|
|
|
|
l = (int) ((f2 + 1.0) / 2.0) - psiz;
|
2001-12-12 00:13:37 +00:00
|
|
|
putfloat(f1, GRAPHROW, GRAPHCOL + 10 * lc, 4, 1, 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
move(GRAPHROW + 2, psiz);
|
|
|
|
psiz += l;
|
|
|
|
while (l-- > 0)
|
2001-12-12 00:13:37 +00:00
|
|
|
addch(cpuchar[lc]);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2006-02-14 13:27:25 +00:00
|
|
|
putint(ucount(), STATROW, STATCOL, 5);
|
|
|
|
putfloat(avenrun[0], STATROW, STATCOL + 20, 5, 2, 0);
|
|
|
|
putfloat(avenrun[1], STATROW, STATCOL + 26, 5, 2, 0);
|
|
|
|
putfloat(avenrun[2], STATROW, STATCOL + 32, 5, 2, 0);
|
|
|
|
mvaddstr(STATROW, STATCOL + 55, buf);
|
2005-02-21 14:35:00 +00:00
|
|
|
#define pgtokb(pg) ((pg) * (s.v_page_size / 1024))
|
2006-11-28 12:46:02 +00:00
|
|
|
putint(pgtokb(total.t_arm), MEMROW + 2, MEMCOL + 4, 7);
|
|
|
|
putint(pgtokb(total.t_armshr), MEMROW + 2, MEMCOL + 12, 7);
|
|
|
|
putint(pgtokb(total.t_avm), MEMROW + 2, MEMCOL + 20, 8);
|
|
|
|
putint(pgtokb(total.t_avmshr), MEMROW + 2, MEMCOL + 29, 8);
|
|
|
|
putint(pgtokb(total.t_rm), MEMROW + 3, MEMCOL + 4, 7);
|
|
|
|
putint(pgtokb(total.t_rmshr), MEMROW + 3, MEMCOL + 12, 7);
|
|
|
|
putint(pgtokb(total.t_vm), MEMROW + 3, MEMCOL + 20, 8);
|
|
|
|
putint(pgtokb(total.t_vmshr), MEMROW + 3, MEMCOL + 29, 8);
|
|
|
|
putint(pgtokb(total.t_free), MEMROW + 2, MEMCOL + 38, 7);
|
|
|
|
putint(total.t_rq - 1, PROCSROW + 2, PROCSCOL, 3);
|
|
|
|
putint(total.t_pw, PROCSROW + 2, PROCSCOL + 4, 3);
|
|
|
|
putint(total.t_dw, PROCSROW + 2, PROCSCOL + 8, 3);
|
|
|
|
putint(total.t_sl, PROCSROW + 2, PROCSCOL + 12, 3);
|
|
|
|
putint(total.t_sw, PROCSROW + 2, PROCSCOL + 16, 3);
|
2006-04-30 23:52:16 +00:00
|
|
|
PUTRATE(v_cow_faults, VMSTATROW, VMSTATCOL + 2, 8 - 2);
|
|
|
|
PUTRATE(v_zfod, VMSTATROW + 1, VMSTATCOL + 2, 8 - 2);
|
|
|
|
PUTRATE(v_ozfod, VMSTATROW + 2, VMSTATCOL, 8);
|
2006-04-30 22:34:54 +00:00
|
|
|
putint(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0,
|
2006-04-30 23:52:16 +00:00
|
|
|
VMSTATROW + 3, VMSTATCOL + 1, 8 - 1);
|
2006-05-01 07:02:52 +00:00
|
|
|
PUTRATE(v_dfree, VMSTATROW + 4, VMSTATCOL + 2, 8 - 2);
|
|
|
|
PUTRATE(v_pfree, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2);
|
|
|
|
PUTRATE(v_tfree, VMSTATROW + 6, VMSTATCOL, 8);
|
|
|
|
PUTRATE(v_reactivated, VMSTATROW + 7, VMSTATCOL, 8);
|
|
|
|
PUTRATE(v_pdwakeups, VMSTATROW + 8, VMSTATCOL, 8);
|
|
|
|
PUTRATE(v_pdpages, VMSTATROW + 9, VMSTATCOL, 8);
|
|
|
|
PUTRATE(v_intrans, VMSTATROW + 10, VMSTATCOL, 8);
|
2006-11-28 12:46:02 +00:00
|
|
|
putint(pgtokb(s.v_wire_count), VMSTATROW + 11, VMSTATCOL, 8);
|
|
|
|
putint(pgtokb(s.v_active_count), VMSTATROW + 12, VMSTATCOL, 8);
|
|
|
|
putint(pgtokb(s.v_inactive_count), VMSTATROW + 13, VMSTATCOL, 8);
|
|
|
|
putint(pgtokb(s.v_cache_count), VMSTATROW + 14, VMSTATCOL, 8);
|
|
|
|
putint(pgtokb(s.v_free_count), VMSTATROW + 15, VMSTATCOL, 8);
|
2006-05-01 00:26:43 +00:00
|
|
|
if (LINES - 1 > VMSTATROW + 16)
|
|
|
|
putint(s.bufspace / 1024, VMSTATROW + 16, VMSTATCOL, 8);
|
2006-02-14 13:27:25 +00:00
|
|
|
PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5);
|
|
|
|
PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5);
|
|
|
|
PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5);
|
|
|
|
PUTRATE(v_swapout, PAGEROW + 2, PAGECOL + 25, 5);
|
|
|
|
PUTRATE(v_vnodepgsin, PAGEROW + 3, PAGECOL + 6, 5);
|
|
|
|
PUTRATE(v_vnodepgsout, PAGEROW + 3, PAGECOL + 12, 5);
|
|
|
|
PUTRATE(v_swappgsin, PAGEROW + 3, PAGECOL + 19, 5);
|
|
|
|
PUTRATE(v_swappgsout, PAGEROW + 3, PAGECOL + 25, 5);
|
2006-02-14 10:47:36 +00:00
|
|
|
PUTRATE(v_swtch, GENSTATROW + 1, GENSTATCOL, 4);
|
|
|
|
PUTRATE(v_trap, GENSTATROW + 1, GENSTATCOL + 5, 4);
|
|
|
|
PUTRATE(v_syscall, GENSTATROW + 1, GENSTATCOL + 10, 4);
|
|
|
|
PUTRATE(v_intr, GENSTATROW + 1, GENSTATCOL + 15, 4);
|
|
|
|
PUTRATE(v_soft, GENSTATROW + 1, GENSTATCOL + 20, 4);
|
|
|
|
PUTRATE(v_vm_faults, GENSTATROW + 1, GENSTATCOL + 25, 4);
|
2001-12-12 00:13:37 +00:00
|
|
|
for (i = 0, lc = 0; i < num_devices && lc < MAXDRIVES; i++)
|
1998-09-15 08:16:45 +00:00
|
|
|
if (dev_select[i].selected) {
|
|
|
|
switch(state) {
|
|
|
|
case TIME:
|
2001-12-12 00:13:37 +00:00
|
|
|
dinfo(i, ++lc, &cur, &last);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
case RUN:
|
2001-12-12 00:13:37 +00:00
|
|
|
dinfo(i, ++lc, &cur, &run);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
case BOOT:
|
2001-12-12 00:13:37 +00:00
|
|
|
dinfo(i, ++lc, &cur, NULL);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2006-04-30 20:31:00 +00:00
|
|
|
putint(s.numdirtybuffers, VNSTATROW, VNSTATCOL, 7);
|
|
|
|
putint(s.desiredvnodes, VNSTATROW + 1, VNSTATCOL, 7);
|
|
|
|
putint(s.numvnodes, VNSTATROW + 2, VNSTATCOL, 7);
|
|
|
|
putint(s.freevnodes, VNSTATROW + 3, VNSTATCOL, 7);
|
|
|
|
putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 8);
|
1995-03-12 01:58:18 +00:00
|
|
|
putint((nchtotal.ncs_goodhits + nchtotal.ncs_neghits),
|
2006-04-30 20:31:00 +00:00
|
|
|
NAMEIROW + 2, NAMEICOL + 9, 7);
|
1994-05-27 12:33:43 +00:00
|
|
|
#define nz(x) ((x) ? (x) : 1)
|
1995-05-30 06:41:30 +00:00
|
|
|
putfloat((nchtotal.ncs_goodhits+nchtotal.ncs_neghits) *
|
1995-03-12 01:58:18 +00:00
|
|
|
100.0 / nz(s.nchcount),
|
2006-04-30 20:31:00 +00:00
|
|
|
NAMEIROW + 2, NAMEICOL + 17, 3, 0, 1);
|
|
|
|
putint(nchtotal.ncs_pass2, NAMEIROW + 2, NAMEICOL + 21, 7);
|
1994-05-27 12:33:43 +00:00
|
|
|
putfloat(nchtotal.ncs_pass2 * 100.0 / nz(s.nchcount),
|
2006-04-30 20:31:00 +00:00
|
|
|
NAMEIROW + 2, NAMEICOL + 29, 3, 0, 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
#undef nz
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-01-16 19:27:43 +00:00
|
|
|
cmdkre(const char *cmd, const char *args)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1998-09-15 08:16:45 +00:00
|
|
|
int retval;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (prefix(cmd, "run")) {
|
1998-09-15 08:16:45 +00:00
|
|
|
retval = 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
copyinfo(&s2, &s1);
|
2001-09-06 04:06:12 +00:00
|
|
|
switch (devstat_getdevs(NULL, &run)) {
|
1998-09-15 08:16:45 +00:00
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
num_devices = run.dinfo->numdevs;
|
|
|
|
generation = run.dinfo->generation;
|
|
|
|
retval = dscmd("refresh", NULL, MAXDRIVES, &cur);
|
|
|
|
if (retval == 2)
|
|
|
|
labelkre();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
state = RUN;
|
1998-09-15 08:16:45 +00:00
|
|
|
return (retval);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (prefix(cmd, "boot")) {
|
|
|
|
state = BOOT;
|
|
|
|
copyinfo(&z, &s1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (prefix(cmd, "time")) {
|
|
|
|
state = TIME;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (prefix(cmd, "zero")) {
|
1998-09-15 08:16:45 +00:00
|
|
|
retval = 1;
|
|
|
|
if (state == RUN) {
|
2001-12-12 00:13:37 +00:00
|
|
|
getinfo(&s1);
|
2001-09-06 04:06:12 +00:00
|
|
|
switch (devstat_getdevs(NULL, &run)) {
|
1998-09-15 08:16:45 +00:00
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
num_devices = run.dinfo->numdevs;
|
|
|
|
generation = run.dinfo->generation;
|
|
|
|
retval = dscmd("refresh",NULL, MAXDRIVES, &cur);
|
|
|
|
if (retval == 2)
|
|
|
|
labelkre();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (retval);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
retval = dscmd(cmd, args, MAXDRIVES, &cur);
|
|
|
|
|
|
|
|
if (retval == 2)
|
|
|
|
labelkre();
|
|
|
|
|
|
|
|
return(retval);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate number of users on the system */
|
|
|
|
static int
|
2008-01-16 19:27:43 +00:00
|
|
|
ucount(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-12 00:13:37 +00:00
|
|
|
int nusers = 0;
|
2009-12-05 20:52:11 +00:00
|
|
|
struct utmpx *ut;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2009-12-05 20:52:11 +00:00
|
|
|
setutxent();
|
|
|
|
while ((ut = getutxent()) != NULL)
|
|
|
|
if (ut->ut_type == USER_PROCESS)
|
1994-05-27 12:33:43 +00:00
|
|
|
nusers++;
|
2009-12-05 20:52:11 +00:00
|
|
|
endutxent();
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
return (nusers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float
|
2008-01-16 19:27:43 +00:00
|
|
|
cputime(int indx)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-12 00:13:37 +00:00
|
|
|
double lt;
|
|
|
|
int i;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
lt = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
for (i = 0; i < CPUSTATES; i++)
|
2001-12-12 00:13:37 +00:00
|
|
|
lt += s.time[i];
|
|
|
|
if (lt == 0.0)
|
|
|
|
lt = 1.0;
|
|
|
|
return (s.time[indx] * 100.0 / lt);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
putint(int n, int l, int lc, int w)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2006-02-14 11:57:02 +00:00
|
|
|
int snr;
|
1994-05-27 12:33:43 +00:00
|
|
|
char b[128];
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
move(l, lc);
|
2006-04-30 05:54:21 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
while (w-- > 0)
|
|
|
|
addch('*');
|
|
|
|
return;
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
if (n == 0) {
|
|
|
|
while (w-- > 0)
|
|
|
|
addch(' ');
|
|
|
|
return;
|
|
|
|
}
|
2006-02-14 11:57:02 +00:00
|
|
|
snr = snprintf(b, sizeof(b), "%*d", w, n);
|
|
|
|
if (snr != w)
|
|
|
|
snr = snprintf(b, sizeof(b), "%*dk", w - 1, n / 1000);
|
|
|
|
if (snr != w)
|
|
|
|
snr = snprintf(b, sizeof(b), "%*dM", w - 1, n / 1000000);
|
|
|
|
if (snr != w) {
|
|
|
|
while (w-- > 0)
|
|
|
|
addch('*');
|
|
|
|
return;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
addstr(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
putfloat(double f, int l, int lc, int w, int d, int nz)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2006-02-14 11:57:02 +00:00
|
|
|
int snr;
|
1994-05-27 12:33:43 +00:00
|
|
|
char b[128];
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
move(l, lc);
|
2006-04-30 05:54:21 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
while (--w >= 0)
|
|
|
|
addch('*');
|
|
|
|
return;
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
if (nz && f == 0.0) {
|
|
|
|
while (--w >= 0)
|
|
|
|
addch(' ');
|
|
|
|
return;
|
|
|
|
}
|
2006-02-14 11:57:02 +00:00
|
|
|
snr = snprintf(b, sizeof(b), "%*.*f", w, d, f);
|
|
|
|
if (snr != w)
|
|
|
|
snr = snprintf(b, sizeof(b), "%*.0f", w, f);
|
|
|
|
if (snr != w) {
|
1994-05-27 12:33:43 +00:00
|
|
|
while (--w >= 0)
|
|
|
|
addch('*');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addstr(b);
|
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
putlongdouble(long double f, int l, int lc, int w, int d, int nz)
|
1998-09-15 08:16:45 +00:00
|
|
|
{
|
2006-02-14 11:57:02 +00:00
|
|
|
int snr;
|
1998-09-15 08:16:45 +00:00
|
|
|
char b[128];
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
move(l, lc);
|
2006-04-30 05:54:21 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
while (--w >= 0)
|
|
|
|
addch('*');
|
|
|
|
return;
|
|
|
|
#endif
|
1998-09-15 08:16:45 +00:00
|
|
|
if (nz && f == 0.0) {
|
|
|
|
while (--w >= 0)
|
|
|
|
addch(' ');
|
|
|
|
return;
|
|
|
|
}
|
2006-02-14 11:57:02 +00:00
|
|
|
snr = snprintf(b, sizeof(b), "%*.*Lf", w, d, f);
|
|
|
|
if (snr != w)
|
|
|
|
snr = snprintf(b, sizeof(b), "%*.0Lf", w, f);
|
|
|
|
if (snr != w) {
|
1998-09-15 08:16:45 +00:00
|
|
|
while (--w >= 0)
|
|
|
|
addch('*');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addstr(b);
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
getinfo(struct Info *ls)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1998-09-15 08:16:45 +00:00
|
|
|
struct devinfo *tmp_dinfo;
|
2001-03-23 03:58:25 +00:00
|
|
|
size_t size;
|
|
|
|
int mib[2];
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
GETSYSCTL("kern.cp_time", ls->time);
|
2001-03-23 03:58:25 +00:00
|
|
|
GETSYSCTL("kern.cp_time", cur.cp_time);
|
2001-12-12 00:13:37 +00:00
|
|
|
GETSYSCTL("vm.stats.sys.v_swtch", ls->v_swtch);
|
|
|
|
GETSYSCTL("vm.stats.sys.v_trap", ls->v_trap);
|
|
|
|
GETSYSCTL("vm.stats.sys.v_syscall", ls->v_syscall);
|
|
|
|
GETSYSCTL("vm.stats.sys.v_intr", ls->v_intr);
|
|
|
|
GETSYSCTL("vm.stats.sys.v_soft", ls->v_soft);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_vm_faults", ls->v_vm_faults);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_cow_faults", ls->v_cow_faults);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_zfod", ls->v_zfod);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_ozfod", ls->v_ozfod);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_swapin", ls->v_swapin);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_swapout", ls->v_swapout);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_swappgsin", ls->v_swappgsin);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_swappgsout", ls->v_swappgsout);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_vnodein", ls->v_vnodein);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_vnodeout", ls->v_vnodeout);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_vnodepgsin", ls->v_vnodepgsin);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_vnodepgsout", ls->v_vnodepgsout);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_intrans", ls->v_intrans);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_reactivated", ls->v_reactivated);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_pdwakeups", ls->v_pdwakeups);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_pdpages", ls->v_pdpages);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_dfree", ls->v_dfree);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_pfree", ls->v_pfree);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_tfree", ls->v_tfree);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_page_size", ls->v_page_size);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_free_count", ls->v_free_count);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_wire_count", ls->v_wire_count);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_active_count", ls->v_active_count);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_inactive_count", ls->v_inactive_count);
|
|
|
|
GETSYSCTL("vm.stats.vm.v_cache_count", ls->v_cache_count);
|
|
|
|
GETSYSCTL("vfs.bufspace", ls->bufspace);
|
|
|
|
GETSYSCTL("kern.maxvnodes", ls->desiredvnodes);
|
2002-06-06 23:01:50 +00:00
|
|
|
GETSYSCTL("vfs.numvnodes", ls->numvnodes);
|
|
|
|
GETSYSCTL("vfs.freevnodes", ls->freevnodes);
|
2001-12-12 00:13:37 +00:00
|
|
|
GETSYSCTL("vfs.cache.nchstats", ls->nchstats);
|
|
|
|
GETSYSCTL("vfs.numdirtybuffers", ls->numdirtybuffers);
|
|
|
|
getsysctl("hw.intrcnt", ls->intrcnt, nintr * sizeof(u_long));
|
|
|
|
|
|
|
|
size = sizeof(ls->Total);
|
1994-05-27 12:33:43 +00:00
|
|
|
mib[0] = CTL_VM;
|
2003-01-11 07:29:47 +00:00
|
|
|
mib[1] = VM_TOTAL;
|
2001-12-12 00:13:37 +00:00
|
|
|
if (sysctl(mib, 2, &ls->Total, &size, NULL, 0) < 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
error("Can't get kernel info: %s\n", strerror(errno));
|
2001-12-12 00:13:37 +00:00
|
|
|
bzero(&ls->Total, sizeof(ls->Total));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1998-05-27 21:01:37 +00:00
|
|
|
size = sizeof(ncpu);
|
o Make systat/vmstat.c use sysctl() to retrieve cp_time, bufspace,
maxvnodes, numvnodes, freevnodes, nchstats, and numdirtybuffers.
o Make the hw.ncpu error checking code a little more rigorous by
sanity checking the returned data size.
o Didn't fix machine-dependent non-sysctl-exported variables:
intrnames, eintrnames, intrcnt, eintrcnt, as these variables are
defined and exported from machine-dependent kernel code in
assembly. This should probably be fixed somehow.
2000-11-25 03:53:42 +00:00
|
|
|
if (sysctlbyname("hw.ncpu", &ncpu, &size, NULL, 0) < 0 ||
|
|
|
|
size != sizeof(ncpu))
|
1998-05-27 21:01:37 +00:00
|
|
|
ncpu = 1;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
tmp_dinfo = last.dinfo;
|
|
|
|
last.dinfo = cur.dinfo;
|
|
|
|
cur.dinfo = tmp_dinfo;
|
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
last.snap_time = cur.snap_time;
|
2001-09-06 04:06:12 +00:00
|
|
|
switch (devstat_getdevs(NULL, &cur)) {
|
1998-09-15 08:16:45 +00:00
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
|
|
|
cmdkre("refresh", NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
allocinfo(struct Info *ls)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
ls->intrcnt = (long *) calloc(nintr, sizeof(long));
|
|
|
|
if (ls->intrcnt == NULL)
|
1997-08-13 06:45:11 +00:00
|
|
|
errx(2, "out of memory");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
copyinfo(struct Info *from, struct Info *to)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
long *intrcnt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* time, wds, seek, and xfer are malloc'd so we have to
|
1995-05-30 06:41:30 +00:00
|
|
|
* save the pointers before the structure copy and then
|
1994-05-27 12:33:43 +00:00
|
|
|
* copy by hand.
|
|
|
|
*/
|
1998-09-15 08:16:45 +00:00
|
|
|
intrcnt = to->intrcnt;
|
1994-05-27 12:33:43 +00:00
|
|
|
*to = *from;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-01-16 19:27:43 +00:00
|
|
|
dinfo(int dn, int lc, struct statinfo *now, struct statinfo *then)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1998-09-15 08:16:45 +00:00
|
|
|
long double transfers_per_second;
|
|
|
|
long double kb_per_transfer, mb_per_second;
|
1999-07-30 07:44:25 +00:00
|
|
|
long double elapsed_time, device_busy;
|
1998-09-15 08:16:45 +00:00
|
|
|
int di;
|
|
|
|
|
|
|
|
di = dev_select[dn].position;
|
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
if (then != NULL) {
|
|
|
|
/* Calculate relative to previous sample */
|
|
|
|
elapsed_time = now->snap_time - then->snap_time;
|
|
|
|
} else {
|
|
|
|
/* Calculate relative to device creation */
|
|
|
|
elapsed_time = now->snap_time - devstat_compute_etime(
|
|
|
|
&now->dinfo->devices[di].creation_time, NULL);
|
|
|
|
}
|
1999-07-30 07:44:25 +00:00
|
|
|
|
2001-09-06 04:06:12 +00:00
|
|
|
if (devstat_compute_statistics(&now->dinfo->devices[di], then ?
|
|
|
|
&then->dinfo->devices[di] : NULL, elapsed_time,
|
2003-04-09 07:49:43 +00:00
|
|
|
DSM_KB_PER_TRANSFER, &kb_per_transfer,
|
|
|
|
DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
|
|
|
|
DSM_MB_PER_SECOND, &mb_per_second,
|
|
|
|
DSM_BUSY_PCT, &device_busy,
|
2001-09-06 04:06:12 +00:00
|
|
|
DSM_NONE) != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
2001-12-12 00:13:37 +00:00
|
|
|
lc = DISKCOL + lc * 6;
|
|
|
|
putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0);
|
|
|
|
putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0);
|
|
|
|
putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0);
|
2003-04-09 07:49:43 +00:00
|
|
|
putlongdouble(device_busy, DISKROW + 4, lc, 5, 0, 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|