2010-04-30 20:21:05 +04:00
|
|
|
/* $NetBSD: vmstat.c,v 1.77 2010/04/30 16:21:05 njoly Exp $ */
|
1995-01-20 11:51:48 +03:00
|
|
|
|
1995-01-20 11:30:50 +03: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.
|
2003-08-07 15:13:06 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1995-01-20 11:30:50 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-07-21 11:04:56 +04:00
|
|
|
#include <sys/cdefs.h>
|
1995-01-20 11:30:50 +03:00
|
|
|
#ifndef lint
|
1995-01-20 11:51:48 +03:00
|
|
|
#if 0
|
1995-01-20 11:30:50 +03:00
|
|
|
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
|
1995-01-20 11:51:48 +03:00
|
|
|
#endif
|
2010-04-30 20:21:05 +04:00
|
|
|
__RCSID("$NetBSD: vmstat.c,v 1.77 2010/04/30 16:21:05 njoly Exp $");
|
1995-01-20 11:30:50 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cursed vmstat -- from Robert Elz.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2006-05-14 06:56:27 +04:00
|
|
|
#include <sys/uio.h>
|
1995-01-20 11:30:50 +03:00
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/sysctl.h>
|
2008-02-11 06:51:17 +03:00
|
|
|
#include <sys/evcnt.h>
|
1999-03-24 08:50:49 +03:00
|
|
|
|
1998-02-07 17:08:23 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2006-05-11 16:01:33 +04:00
|
|
|
#include <errno.h>
|
1995-01-20 11:30:50 +03:00
|
|
|
#include <stdlib.h>
|
1995-03-22 18:25:56 +03:00
|
|
|
#include <string.h>
|
2002-08-08 21:06:31 +04:00
|
|
|
#include <util.h>
|
1995-03-22 18:25:56 +03:00
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
#include "systat.h"
|
|
|
|
#include "extern.h"
|
2006-04-14 17:14:06 +04:00
|
|
|
#include "drvstats.h"
|
2002-08-02 03:36:54 +04:00
|
|
|
#include "utmpentry.h"
|
2006-03-18 17:58:49 +03:00
|
|
|
#include "vmstat.h"
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
static struct Info {
|
2000-11-29 14:18:33 +03:00
|
|
|
struct uvmexp_sysctl uvmexp;
|
1995-01-20 11:30:50 +03:00
|
|
|
struct vmtotal Total;
|
|
|
|
struct nchstats nchstats;
|
|
|
|
long nchcount;
|
|
|
|
long *intrcnt;
|
2003-01-19 00:02:35 +03:00
|
|
|
u_int64_t *evcnt;
|
1995-01-20 11:30:50 +03:00
|
|
|
} s, s1, s2, z;
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
enum display_mode display_mode = TIME;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2000-07-05 15:03:20 +04:00
|
|
|
static void allocinfo(struct Info *);
|
|
|
|
static void copyinfo(struct Info *, struct Info *);
|
|
|
|
static float cputime(int);
|
2003-02-18 17:55:05 +03:00
|
|
|
static void dinfo(int, int, int);
|
2006-03-18 17:58:49 +03:00
|
|
|
static void getinfo(struct Info *);
|
2000-07-05 15:03:20 +04:00
|
|
|
static int ucount(void);
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
static char buf[26];
|
2005-02-27 01:12:33 +03:00
|
|
|
static u_int64_t temp;
|
2006-03-18 17:58:49 +03:00
|
|
|
double etime;
|
1995-01-20 11:30:50 +03:00
|
|
|
static float hertz;
|
|
|
|
static int nintr;
|
|
|
|
static long *intrloc;
|
|
|
|
static char **intrname;
|
|
|
|
static int nextintsrow;
|
2003-02-18 17:55:05 +03:00
|
|
|
static int disk_horiz = 1;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
WINDOW *
|
2000-07-05 15:03:20 +04:00
|
|
|
openvmstat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
return (stdscr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
closevmstat(WINDOW *w)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (w == NULL)
|
|
|
|
return;
|
|
|
|
wclear(w);
|
|
|
|
wrefresh(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct nlist namelist[] = {
|
2002-05-15 10:43:37 +04:00
|
|
|
#define X_NCHSTATS 0
|
2006-10-22 20:43:24 +04:00
|
|
|
{ .n_name = "_nchstats" },
|
2002-05-15 10:43:37 +04:00
|
|
|
#define X_INTRNAMES 1
|
2006-10-22 20:43:24 +04:00
|
|
|
{ .n_name = "_intrnames" },
|
2002-05-15 10:43:37 +04:00
|
|
|
#define X_EINTRNAMES 2
|
2006-10-22 20:43:24 +04:00
|
|
|
{ .n_name = "_eintrnames" },
|
2002-05-15 10:43:37 +04:00
|
|
|
#define X_INTRCNT 3
|
2006-10-22 20:43:24 +04:00
|
|
|
{ .n_name = "_intrcnt" },
|
2002-05-15 10:43:37 +04:00
|
|
|
#define X_EINTRCNT 4
|
2006-10-22 20:43:24 +04:00
|
|
|
{ .n_name = "_eintrcnt" },
|
2003-01-19 00:02:35 +03:00
|
|
|
#define X_ALLEVENTS 5
|
2006-10-22 20:43:24 +04:00
|
|
|
{ .n_name = "_allevents" },
|
|
|
|
{ .n_name = NULL }
|
1995-01-20 11:30:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These constants define where the major pieces are laid out
|
|
|
|
*/
|
|
|
|
#define STATROW 0 /* uses 1 row and 68 cols */
|
|
|
|
#define STATCOL 2
|
2003-02-17 22:30:33 +03:00
|
|
|
#define MEMROW 9 /* uses 4 rows and 31 cols */
|
1995-01-20 11:30:50 +03:00
|
|
|
#define MEMCOL 0
|
|
|
|
#define PAGEROW 2 /* uses 4 rows and 26 cols */
|
2003-02-17 22:30:33 +03:00
|
|
|
#define PAGECOL 54
|
|
|
|
#define INTSROW 9 /* uses all rows to bottom and 17 cols */
|
|
|
|
#define INTSCOL 40
|
|
|
|
#define INTSCOLEND (VMSTATCOL - 0)
|
|
|
|
#define PROCSROW 2 /* uses 2 rows and 20 cols */
|
1995-01-20 11:30:50 +03:00
|
|
|
#define PROCSCOL 0
|
2003-02-17 22:30:33 +03:00
|
|
|
#define GENSTATROW 2 /* uses 2 rows and 30 cols */
|
2005-02-22 18:13:57 +03:00
|
|
|
#define GENSTATCOL 17
|
2003-02-17 22:30:33 +03:00
|
|
|
#define VMSTATROW 7 /* uses 17 rows and 15 cols */
|
|
|
|
#define VMSTATCOL 64
|
|
|
|
#define GRAPHROW 5 /* uses 3 rows and 51 cols */
|
1995-01-20 11:30:50 +03:00
|
|
|
#define GRAPHCOL 0
|
|
|
|
#define NAMEIROW 14 /* uses 3 rows and 38 cols */
|
|
|
|
#define NAMEICOL 0
|
|
|
|
#define DISKROW 18 /* uses 5 rows and 50 cols (for 9 drives) */
|
|
|
|
#define DISKCOL 0
|
2003-02-18 17:55:05 +03:00
|
|
|
#define DISKCOLWIDTH 6
|
|
|
|
#define DISKCOLEND INTSCOL
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2003-01-19 00:02:35 +03:00
|
|
|
typedef struct intr_evcnt intr_evcnt_t;
|
|
|
|
struct intr_evcnt {
|
|
|
|
char *ie_group;
|
|
|
|
char *ie_name;
|
|
|
|
u_int64_t *ie_count; /* kernel address... */
|
|
|
|
int ie_loc; /* screen row */
|
|
|
|
} *ie_head;
|
|
|
|
int nevcnt;
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_interrupt_events(void)
|
|
|
|
{
|
|
|
|
struct evcntlist allevents;
|
|
|
|
struct evcnt evcnt, *evptr;
|
|
|
|
intr_evcnt_t *ie;
|
2003-09-19 11:08:50 +04:00
|
|
|
intr_evcnt_t *n;
|
2003-01-19 00:02:35 +03:00
|
|
|
|
|
|
|
if (!NREAD(X_ALLEVENTS, &allevents, sizeof allevents))
|
|
|
|
return;
|
2005-05-22 18:00:59 +04:00
|
|
|
evptr = TAILQ_FIRST(&allevents);
|
|
|
|
for (; evptr != NULL; evptr = TAILQ_NEXT(&evcnt, ev_list)) {
|
2003-01-19 00:02:35 +03:00
|
|
|
if (!KREAD(evptr, &evcnt, sizeof evcnt))
|
|
|
|
return;
|
|
|
|
if (evcnt.ev_type != EVCNT_TYPE_INTR)
|
|
|
|
continue;
|
2003-09-19 11:08:50 +04:00
|
|
|
n = realloc(ie_head, sizeof *ie * (nevcnt + 1));
|
|
|
|
if (n == NULL) {
|
2003-01-19 00:02:35 +03:00
|
|
|
error("realloc failed");
|
|
|
|
die(0);
|
|
|
|
}
|
2003-09-19 11:08:50 +04:00
|
|
|
ie_head = n;
|
2003-01-19 00:02:35 +03:00
|
|
|
ie = ie_head + nevcnt;
|
|
|
|
ie->ie_group = malloc(evcnt.ev_grouplen + 1);
|
|
|
|
ie->ie_name = malloc(evcnt.ev_namelen + 1);
|
|
|
|
if (ie->ie_group == NULL || ie->ie_name == NULL)
|
|
|
|
return;
|
2003-01-20 21:24:03 +03:00
|
|
|
if (!KREAD(evcnt.ev_group, ie->ie_group, evcnt.ev_grouplen + 1))
|
2003-01-19 00:02:35 +03:00
|
|
|
return;
|
2003-01-20 21:24:03 +03:00
|
|
|
if (!KREAD(evcnt.ev_name, ie->ie_name, evcnt.ev_namelen + 1))
|
2003-01-19 00:02:35 +03:00
|
|
|
return;
|
|
|
|
ie->ie_count = &evptr->ev_count;
|
|
|
|
ie->ie_loc = 0;
|
|
|
|
nevcnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
int
|
2000-07-05 15:03:20 +04:00
|
|
|
initvmstat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2006-03-20 23:36:38 +03:00
|
|
|
static char *intrnamebuf;
|
|
|
|
char *cp;
|
1995-01-20 11:30:50 +03:00
|
|
|
int i;
|
|
|
|
|
2006-03-20 23:36:38 +03:00
|
|
|
if (intrnamebuf)
|
|
|
|
free(intrnamebuf);
|
|
|
|
if (intrname)
|
|
|
|
free(intrname);
|
|
|
|
if (intrloc)
|
|
|
|
free(intrloc);
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
if (namelist[0].n_type == 0) {
|
2005-05-22 18:00:59 +04:00
|
|
|
if (kvm_nlist(kd, namelist) &&
|
|
|
|
(namelist[X_NCHSTATS].n_type == 0 ||
|
|
|
|
namelist[X_ALLEVENTS].n_type == 0)) {
|
1995-01-20 11:30:50 +03:00
|
|
|
nlisterr(namelist);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if (namelist[0].n_type == 0) {
|
|
|
|
error("No namelist");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hertz = stathz ? stathz : hz;
|
2006-04-14 17:14:06 +04:00
|
|
|
if (!drvinit(1))
|
2005-08-07 16:32:38 +04:00
|
|
|
return(0);
|
2003-01-19 00:02:35 +03:00
|
|
|
|
|
|
|
/* Old style interrupt counts - deprecated */
|
|
|
|
nintr = (namelist[X_EINTRCNT].n_value -
|
|
|
|
namelist[X_INTRCNT].n_value) / sizeof (long);
|
2005-05-22 18:00:59 +04:00
|
|
|
if (nintr) {
|
|
|
|
intrloc = calloc(nintr, sizeof (long));
|
|
|
|
intrname = calloc(nintr, sizeof (long));
|
|
|
|
intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
|
|
|
|
namelist[X_INTRNAMES].n_value);
|
|
|
|
if (intrnamebuf == NULL || intrname == 0 || intrloc == 0) {
|
|
|
|
error("Out of memory\n");
|
|
|
|
nintr = 0;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
NREAD(X_INTRNAMES, intrnamebuf, NVAL(X_EINTRNAMES) -
|
|
|
|
NVAL(X_INTRNAMES));
|
|
|
|
for (cp = intrnamebuf, i = 0; i < nintr; i++) {
|
|
|
|
intrname[i] = cp;
|
|
|
|
cp += strlen(cp) + 1;
|
|
|
|
}
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
2003-01-19 00:02:35 +03:00
|
|
|
|
|
|
|
/* event counter interrupt counts */
|
|
|
|
get_interrupt_events();
|
|
|
|
|
2003-02-17 22:30:33 +03:00
|
|
|
nextintsrow = INTSROW + 1;
|
2003-01-19 00:02:35 +03:00
|
|
|
allocinfo(&s);
|
|
|
|
allocinfo(&s1);
|
|
|
|
allocinfo(&s2);
|
|
|
|
allocinfo(&z);
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
getinfo(&s2);
|
1995-01-20 11:30:50 +03:00
|
|
|
copyinfo(&s2, &s1);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
fetchvmstat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
time(&now);
|
2003-05-15 05:00:07 +04:00
|
|
|
strlcpy(buf, ctime(&now), sizeof(buf));
|
1998-12-26 09:38:42 +03:00
|
|
|
buf[19] = '\0';
|
2006-03-18 17:58:49 +03:00
|
|
|
getinfo(&s);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
2003-01-19 00:02:35 +03:00
|
|
|
static void
|
|
|
|
print_ie_title(int i)
|
|
|
|
{
|
|
|
|
int width, name_width, group_width;
|
|
|
|
|
2003-02-17 22:30:33 +03:00
|
|
|
width = INTSCOLEND - (INTSCOL + 9);
|
2003-01-19 00:02:35 +03:00
|
|
|
if (width <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
move(ie_head[i].ie_loc, INTSCOL + 9);
|
|
|
|
group_width = strlen(ie_head[i].ie_group);
|
|
|
|
name_width = strlen(ie_head[i].ie_name);
|
|
|
|
width -= group_width + 1 + name_width;
|
|
|
|
if (width < 0) {
|
2003-02-13 11:09:33 +03:00
|
|
|
/*
|
|
|
|
* Screen to narrow for full strings
|
|
|
|
* This is all rather horrid, in some cases there are a lot
|
|
|
|
* of events in the same group, and in others the event
|
|
|
|
* name is "intr". There are also names which need 7 or 8
|
|
|
|
* columns before they become meaningful.
|
|
|
|
* This is a bad compromise.
|
|
|
|
*/
|
2003-01-19 00:02:35 +03:00
|
|
|
width = -width;
|
|
|
|
group_width -= (width + 1) / 2;
|
|
|
|
name_width -= width / 2;
|
2003-02-13 11:09:33 +03:00
|
|
|
/* some have the 'useful' name "intr", display their group */
|
|
|
|
if (strcasecmp(ie_head[i].ie_name, "intr") == 0) {
|
|
|
|
group_width += name_width + 1;
|
|
|
|
name_width = 0;
|
|
|
|
} else {
|
|
|
|
if (group_width <= 3 || name_width < 0) {
|
|
|
|
/* don't display group */
|
|
|
|
name_width += group_width + 1;
|
|
|
|
group_width = 0;
|
|
|
|
}
|
2003-01-19 00:02:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-13 11:09:33 +03:00
|
|
|
if (group_width != 0) {
|
|
|
|
printw("%-.*s", group_width, ie_head[i].ie_group);
|
|
|
|
if (name_width != 0)
|
|
|
|
printw(" ");
|
|
|
|
}
|
|
|
|
if (name_width != 0)
|
|
|
|
printw("%-.*s", name_width, ie_head[i].ie_name);
|
2003-01-19 00:02:35 +03:00
|
|
|
}
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
void
|
2006-03-18 17:58:49 +03:00
|
|
|
labelvmstat_top(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
mvprintw(STATROW, STATCOL + 4, "users Load");
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2009-03-09 22:48:02 +03:00
|
|
|
mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt");
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
mvprintw(GRAPHROW, GRAPHCOL,
|
2000-06-04 22:10:40 +04:00
|
|
|
" . %% Sy . %% Us . %% Ni . %% In . %% Id");
|
2009-10-22 01:11:57 +04:00
|
|
|
mvprintw(PROCSROW, PROCSCOL, "Proc:r d s");
|
1995-01-20 11:30:50 +03:00
|
|
|
mvprintw(GRAPHROW + 1, GRAPHCOL,
|
|
|
|
"| | | | | | | | | | |");
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
mvprintw(PAGEROW, PAGECOL + 8, "PAGING SWAPPING ");
|
|
|
|
mvprintw(PAGEROW + 1, PAGECOL, " in out in out ");
|
|
|
|
mvprintw(PAGEROW + 2, PAGECOL + 2, "ops");
|
|
|
|
mvprintw(PAGEROW + 3, PAGECOL, "pages");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
labelvmstat(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Top few lines first */
|
|
|
|
|
|
|
|
labelvmstat_top();
|
|
|
|
|
|
|
|
/* Left hand column */
|
|
|
|
|
2010-04-30 17:49:22 +04:00
|
|
|
mvprintw(MEMROW, MEMCOL, " memory totals (in kB)");
|
|
|
|
mvprintw(MEMROW + 1, MEMCOL, " real virtual free");
|
2006-03-18 17:58:49 +03:00
|
|
|
mvprintw(MEMROW + 2, MEMCOL, "Active");
|
|
|
|
mvprintw(MEMROW + 3, MEMCOL, "All");
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
mvprintw(NAMEIROW, NAMEICOL, "Namei Sys-cache Proc-cache");
|
|
|
|
mvprintw(NAMEIROW + 1, NAMEICOL,
|
|
|
|
" Calls hits %% hits %%");
|
2006-03-18 17:58:49 +03:00
|
|
|
|
2003-08-06 00:01:25 +04:00
|
|
|
mvprintw(DISKROW, DISKCOL, "Disks:");
|
2003-02-18 17:55:05 +03:00
|
|
|
if (disk_horiz) {
|
|
|
|
mvprintw(DISKROW + 1, DISKCOL + 1, "seeks");
|
|
|
|
mvprintw(DISKROW + 2, DISKCOL + 1, "xfers");
|
|
|
|
mvprintw(DISKROW + 3, DISKCOL + 1, "bytes");
|
|
|
|
mvprintw(DISKROW + 4, DISKCOL + 1, "%%busy");
|
|
|
|
} else {
|
|
|
|
mvprintw(DISKROW, DISKCOL + 1 + 1 * DISKCOLWIDTH, "seeks");
|
|
|
|
mvprintw(DISKROW, DISKCOL + 1 + 2 * DISKCOLWIDTH, "xfers");
|
|
|
|
mvprintw(DISKROW, DISKCOL + 1 + 3 * DISKCOLWIDTH, "bytes");
|
|
|
|
mvprintw(DISKROW, DISKCOL + 1 + 4 * DISKCOLWIDTH, "%%busy");
|
|
|
|
}
|
2006-03-18 17:58:49 +03:00
|
|
|
|
|
|
|
/* Middle column */
|
|
|
|
|
|
|
|
mvprintw(INTSROW, INTSCOL + 9, "Interrupts");
|
1995-01-20 11:30:50 +03:00
|
|
|
for (i = 0; i < nintr; i++) {
|
|
|
|
if (intrloc[i] == 0)
|
|
|
|
continue;
|
2003-02-13 11:09:33 +03:00
|
|
|
mvprintw(intrloc[i], INTSCOL + 9, "%-.*s",
|
2003-02-17 22:30:33 +03:00
|
|
|
INTSCOLEND - (INTSCOL + 9), intrname[i]);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
2003-01-19 00:02:35 +03:00
|
|
|
for (i = 0; i < nevcnt; i++) {
|
|
|
|
if (ie_head[i].ie_loc == 0)
|
|
|
|
continue;
|
|
|
|
print_ie_title(i);
|
|
|
|
}
|
2006-03-18 17:58:49 +03:00
|
|
|
|
|
|
|
/* Right hand column */
|
|
|
|
|
|
|
|
mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "forks");
|
|
|
|
mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "fkppw");
|
|
|
|
mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "fksvm");
|
|
|
|
mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "pwait");
|
|
|
|
mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "relck");
|
|
|
|
mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "rlkok");
|
|
|
|
mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "noram");
|
|
|
|
mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "ndcpy");
|
|
|
|
mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "fltcp");
|
|
|
|
mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "zfod");
|
|
|
|
mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "cow");
|
|
|
|
mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "fmin");
|
|
|
|
mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "ftarg");
|
|
|
|
mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "itarg");
|
|
|
|
mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "wired");
|
|
|
|
mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "pdfre");
|
|
|
|
|
|
|
|
if (LINES - 1 > VMSTATROW + 16)
|
|
|
|
mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "pdscn");
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
#define X(s, s1, fld) {temp = (s).fld[i]; (s).fld[i] -= (s1).fld[i]; \
|
|
|
|
if (display_mode == TIME) (s1).fld[i] = temp;}
|
|
|
|
#define Z(s, s1, fld) {temp = (s).nchstats.fld; \
|
|
|
|
(s).nchstats.fld -= (s1).nchstats.fld; \
|
|
|
|
if (display_mode == TIME) (s1).nchstats.fld = temp;}
|
|
|
|
#define PUTRATE(s, s1, fld, l, c, w) \
|
|
|
|
{temp = (s).fld; (s).fld -= (s1).fld; \
|
|
|
|
if (display_mode == TIME) (s1).fld = temp; \
|
|
|
|
putint((int)((float)(s).fld/etime + 0.5), l, c, w);}
|
1995-01-20 11:30:50 +03:00
|
|
|
#define MAXFAIL 5
|
|
|
|
|
2000-05-29 16:54:31 +04:00
|
|
|
static char cpuchar[CPUSTATES] = { '=' , '>', '-', '%', ' ' };
|
|
|
|
static char cpuorder[CPUSTATES] = { CP_SYS, CP_USER, CP_NICE, CP_INTR, CP_IDLE };
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
void
|
2006-03-18 17:58:49 +03:00
|
|
|
show_vmstat_top(vmtotal_t *Total, uvmexp_sysctl_t *uvm, uvmexp_sysctl_t *uvm1)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
float f1, f2;
|
2006-03-18 17:58:49 +03:00
|
|
|
int psiz;
|
|
|
|
int i, l, c;
|
|
|
|
struct {
|
|
|
|
struct uvmexp_sysctl *uvmexp;
|
|
|
|
} us, us1;
|
|
|
|
|
|
|
|
us.uvmexp = uvm;
|
|
|
|
us1.uvmexp = uvm1;
|
|
|
|
|
|
|
|
putint(ucount(), STATROW, STATCOL, 3);
|
|
|
|
putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0);
|
|
|
|
putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0);
|
|
|
|
putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0);
|
|
|
|
mvaddstr(STATROW, STATCOL + 53, buf);
|
|
|
|
|
|
|
|
putint(Total->t_rq - 1, PROCSROW + 1, PROCSCOL + 3, 3);
|
|
|
|
putint(Total->t_dw, PROCSROW + 1, PROCSCOL + 6, 3);
|
|
|
|
putint(Total->t_sl, PROCSROW + 1, PROCSCOL + 9, 3);
|
|
|
|
|
|
|
|
PUTRATE(us, us1, uvmexp->swtch, GENSTATROW + 1, GENSTATCOL - 1, 7);
|
2006-05-22 00:22:34 +04:00
|
|
|
PUTRATE(us, us1, uvmexp->traps, GENSTATROW + 1, GENSTATCOL + 7, 6);
|
|
|
|
PUTRATE(us, us1, uvmexp->syscalls, GENSTATROW + 1, GENSTATCOL + 14, 6);
|
|
|
|
PUTRATE(us, us1, uvmexp->intrs, GENSTATROW + 1, GENSTATCOL + 21, 5);
|
2009-03-09 22:48:02 +03:00
|
|
|
PUTRATE(us, us1, uvmexp->softs, GENSTATROW + 1, GENSTATCOL + 27, 6);
|
|
|
|
PUTRATE(us, us1, uvmexp->faults, GENSTATROW + 1, GENSTATCOL + 34, 6);
|
2006-03-18 17:58:49 +03:00
|
|
|
|
|
|
|
/* Last CPU state not calculated yet. */
|
|
|
|
for (f2 = 0.0, psiz = 0, c = 0; c < CPUSTATES; c++) {
|
|
|
|
i = cpuorder[c];
|
|
|
|
f1 = cputime(i);
|
|
|
|
f2 += f1;
|
|
|
|
l = (int) ((f2 + 1.0) / 2.0) - psiz;
|
|
|
|
if (c == 0)
|
|
|
|
putfloat(f1, GRAPHROW, GRAPHCOL + 1, 5, 1, 0);
|
|
|
|
else
|
|
|
|
putfloat(f1, GRAPHROW, GRAPHCOL + 10 * c + 1, 5, 1, 0);
|
|
|
|
mvhline(GRAPHROW + 2, psiz, cpuchar[c], l);
|
|
|
|
psiz += l;
|
|
|
|
}
|
|
|
|
|
|
|
|
PUTRATE(us, us1, uvmexp->pageins, PAGEROW + 2, PAGECOL + 5, 5);
|
|
|
|
PUTRATE(us, us1, uvmexp->pdpageouts, PAGEROW + 2, PAGECOL + 10, 5);
|
|
|
|
PUTRATE(us, us1, uvmexp->pgswapin, PAGEROW + 3, PAGECOL + 5, 5);
|
|
|
|
PUTRATE(us, us1, uvmexp->pgswapout, PAGEROW + 3, PAGECOL + 10, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
showvmstat(void)
|
|
|
|
{
|
|
|
|
int inttotal;
|
2003-02-18 17:55:05 +03:00
|
|
|
int i, l, r, c;
|
1995-01-20 11:30:50 +03:00
|
|
|
static int failcnt = 0;
|
2003-02-18 17:55:05 +03:00
|
|
|
static int relabel = 0;
|
|
|
|
static int last_disks = 0;
|
2005-02-27 01:12:33 +03:00
|
|
|
static char pigs[] = "pigs";
|
2003-02-18 17:55:05 +03:00
|
|
|
|
|
|
|
if (relabel) {
|
|
|
|
labelvmstat();
|
|
|
|
relabel = 0;
|
|
|
|
}
|
2002-06-30 04:10:33 +04:00
|
|
|
|
2006-02-05 12:54:50 +03:00
|
|
|
cpuswap();
|
2006-03-18 17:58:49 +03:00
|
|
|
if (display_mode == TIME) {
|
2006-04-14 17:14:06 +04:00
|
|
|
drvswap();
|
2003-01-19 00:02:35 +03:00
|
|
|
etime = cur.cp_etime;
|
|
|
|
/* < 5 ticks - ignore this trash */
|
|
|
|
if ((etime * hertz) < 1.0) {
|
2009-10-21 17:56:36 +04:00
|
|
|
if (failcnt++ <= MAXFAIL)
|
2003-01-19 00:02:35 +03:00
|
|
|
return;
|
1995-01-20 11:30:50 +03:00
|
|
|
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);
|
2005-02-27 01:12:33 +03:00
|
|
|
command(pigs);
|
2003-01-19 00:02:35 +03:00
|
|
|
return;
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
2003-01-19 00:02:35 +03:00
|
|
|
} else
|
|
|
|
etime = 1.0;
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
show_vmstat_top(&s.Total, &s.uvmexp, &s1.uvmexp);
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
/* Memory totals */
|
1998-12-19 17:34:40 +03:00
|
|
|
#define pgtokb(pg) ((pg) * (s.uvmexp.pagesize / 1024))
|
2010-04-30 17:49:22 +04:00
|
|
|
putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 6, 9);
|
1998-02-09 17:14:43 +03:00
|
|
|
putint(pgtokb(s.uvmexp.active + s.uvmexp.swpginuse), /* XXX */
|
2010-04-30 17:49:22 +04:00
|
|
|
MEMROW + 2, MEMCOL + 16, 9);
|
|
|
|
putint(pgtokb(s.uvmexp.npages - s.uvmexp.free),
|
|
|
|
MEMROW + 3, MEMCOL + 6, 9);
|
1998-02-09 17:14:43 +03:00
|
|
|
putint(pgtokb(s.uvmexp.npages - s.uvmexp.free + s.uvmexp.swpginuse),
|
2010-04-30 17:49:22 +04:00
|
|
|
MEMROW + 3, MEMCOL + 16, 9);
|
|
|
|
putint(pgtokb(s.uvmexp.free), MEMROW + 2, MEMCOL + 26, 9);
|
1998-02-09 17:14:43 +03:00
|
|
|
putint(pgtokb(s.uvmexp.free + s.uvmexp.swpages - s.uvmexp.swpginuse),
|
2010-04-30 17:49:22 +04:00
|
|
|
MEMROW + 3, MEMCOL + 26, 9);
|
2006-03-18 17:58:49 +03:00
|
|
|
#undef pgtokb
|
|
|
|
|
|
|
|
/* Namei cache */
|
|
|
|
Z(s, s1, ncs_goodhits); Z(s, s1, ncs_badhits); Z(s, s1, ncs_miss);
|
|
|
|
Z(s, s1, ncs_long); Z(s, s1, ncs_pass2); Z(s, s1, ncs_2passes);
|
|
|
|
s.nchcount = s.nchstats.ncs_goodhits + s.nchstats.ncs_badhits +
|
2010-04-30 20:21:05 +04:00
|
|
|
s.nchstats.ncs_miss + s.nchstats.ncs_long +
|
|
|
|
s.nchstats.ncs_pass2 + s.nchstats.ncs_2passes;
|
2006-03-18 17:58:49 +03:00
|
|
|
if (display_mode == TIME)
|
|
|
|
s1.nchcount = s.nchcount;
|
|
|
|
|
|
|
|
putint(s.nchcount, NAMEIROW + 2, NAMEICOL, 9);
|
|
|
|
putint(s.nchstats.ncs_goodhits, NAMEIROW + 2, NAMEICOL + 9, 9);
|
|
|
|
#define nz(x) ((x) ? (x) : 1)
|
|
|
|
putfloat(s.nchstats.ncs_goodhits * 100.0 / nz(s.nchcount),
|
|
|
|
NAMEIROW + 2, NAMEICOL + 19, 4, 0, 1);
|
|
|
|
putint(s.nchstats.ncs_pass2, NAMEIROW + 2, NAMEICOL + 23, 9);
|
|
|
|
putfloat(s.nchstats.ncs_pass2 * 100.0 / nz(s.nchcount),
|
|
|
|
NAMEIROW + 2, NAMEICOL + 34, 4, 0, 1);
|
|
|
|
#undef nz
|
|
|
|
|
|
|
|
/* Disks */
|
2005-08-07 16:32:38 +04:00
|
|
|
for (l = 0, i = 0, r = DISKROW, c = DISKCOL;
|
2009-04-14 03:20:27 +04:00
|
|
|
i < (int)ndrive; i++) {
|
2006-04-14 17:14:06 +04:00
|
|
|
if (!drv_select[i])
|
|
|
|
continue;
|
2005-08-07 16:32:38 +04:00
|
|
|
|
2003-02-18 17:55:05 +03:00
|
|
|
if (disk_horiz)
|
|
|
|
c += DISKCOLWIDTH;
|
|
|
|
else
|
|
|
|
r++;
|
|
|
|
if (c + DISKCOLWIDTH > DISKCOLEND) {
|
|
|
|
if (disk_horiz && LINES - 1 - DISKROW >
|
2005-08-07 16:32:38 +04:00
|
|
|
(DISKCOLEND - DISKCOL) / DISKCOLWIDTH) {
|
2003-02-18 17:55:05 +03:00
|
|
|
disk_horiz = 0;
|
|
|
|
relabel = 1;
|
|
|
|
}
|
|
|
|
break;
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
2003-02-18 17:55:05 +03:00
|
|
|
if (r >= LINES - 1) {
|
|
|
|
if (!disk_horiz && LINES - 1 - DISKROW <
|
2005-08-07 16:32:38 +04:00
|
|
|
(DISKCOLEND - DISKCOL) / DISKCOLWIDTH) {
|
2003-02-18 17:55:05 +03:00
|
|
|
disk_horiz = 1;
|
|
|
|
relabel = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
l++;
|
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
dinfo(i, r, c);
|
2003-02-18 17:55:05 +03:00
|
|
|
}
|
|
|
|
/* blank out if we lost any disks */
|
|
|
|
for (i = l; i < last_disks; i++) {
|
|
|
|
int j;
|
|
|
|
if (disk_horiz)
|
|
|
|
c += DISKCOLWIDTH;
|
|
|
|
else
|
|
|
|
r++;
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
if (disk_horiz)
|
2004-06-13 12:56:21 +04:00
|
|
|
mvprintw(r+j, c, "%*s", DISKCOLWIDTH, "");
|
2003-02-18 17:55:05 +03:00
|
|
|
else
|
2004-06-13 12:56:21 +04:00
|
|
|
mvprintw(r, c+j*DISKCOLWIDTH, "%*s", DISKCOLWIDTH, "");
|
2003-02-18 17:55:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
last_disks = l;
|
2006-03-18 17:58:49 +03:00
|
|
|
|
|
|
|
/* Interrupts */
|
|
|
|
failcnt = 0;
|
|
|
|
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++;
|
|
|
|
mvprintw(intrloc[i], INTSCOL + 9, "%-.*s",
|
|
|
|
INTSCOLEND - (INTSCOL + 9), intrname[i]);
|
|
|
|
}
|
|
|
|
X(s, s1, intrcnt);
|
|
|
|
l = (int)((float)s.intrcnt[i]/etime + 0.5);
|
|
|
|
inttotal += l;
|
|
|
|
putint(l, intrloc[i], INTSCOL, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nevcnt; i++) {
|
|
|
|
if (s.evcnt[i] == 0)
|
|
|
|
continue;
|
|
|
|
if (ie_head[i].ie_loc == 0) {
|
|
|
|
if (nextintsrow == LINES)
|
|
|
|
continue;
|
|
|
|
ie_head[i].ie_loc = nextintsrow++;
|
|
|
|
print_ie_title(i);
|
|
|
|
}
|
|
|
|
X(s, s1, evcnt);
|
|
|
|
l = (int)((float)s.evcnt[i]/etime + 0.5);
|
|
|
|
inttotal += l;
|
|
|
|
putint(l, ie_head[i].ie_loc, INTSCOL, 8);
|
|
|
|
}
|
|
|
|
putint(inttotal, INTSROW, INTSCOL, 8);
|
|
|
|
|
|
|
|
PUTRATE(s, s1, uvmexp.forks, VMSTATROW + 0, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.forks_ppwait, VMSTATROW + 1, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.forks_sharevm, VMSTATROW + 2, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.fltpgwait, VMSTATROW + 3, VMSTATCOL + 4, 5);
|
|
|
|
PUTRATE(s, s1, uvmexp.fltrelck, VMSTATROW + 4, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.fltrelckok, VMSTATROW + 5, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.fltnoram, VMSTATROW + 6, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.fltamcopy, VMSTATROW + 7, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.flt_prcopy, VMSTATROW + 8, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.flt_przero, VMSTATROW + 9, VMSTATCOL + 3, 6);
|
|
|
|
PUTRATE(s, s1, uvmexp.flt_acow, VMSTATROW + 10, VMSTATCOL, 9);
|
|
|
|
putint(s.uvmexp.freemin, VMSTATROW + 11, VMSTATCOL, 9);
|
|
|
|
putint(s.uvmexp.freetarg, VMSTATROW + 12, VMSTATCOL, 9);
|
|
|
|
putint(s.uvmexp.inactarg, VMSTATROW + 13, VMSTATCOL, 9);
|
|
|
|
putint(s.uvmexp.wired, VMSTATROW + 14, VMSTATCOL, 9);
|
|
|
|
PUTRATE(s, s1, uvmexp.pdfreed, VMSTATROW + 15, VMSTATCOL, 9);
|
|
|
|
if (LINES - 1 > VMSTATROW + 16)
|
|
|
|
PUTRATE(s, s1, uvmexp.pdscans, VMSTATROW + 16, VMSTATCOL, 9);
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
1999-12-20 06:45:01 +03:00
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
vmstat_boot(char *args)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
1999-12-20 06:45:01 +03:00
|
|
|
copyinfo(&z, &s1);
|
2006-03-18 17:58:49 +03:00
|
|
|
display_mode = BOOT;
|
1999-12-20 06:45:01 +03:00
|
|
|
}
|
1995-01-20 11:30:50 +03:00
|
|
|
|
1999-12-20 06:45:01 +03:00
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
vmstat_run(char *args)
|
1999-12-20 06:45:01 +03:00
|
|
|
{
|
|
|
|
copyinfo(&s1, &s2);
|
2006-03-18 17:58:49 +03:00
|
|
|
display_mode = RUN;
|
1999-12-20 06:45:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-01-19 00:02:35 +03:00
|
|
|
vmstat_time(char *args)
|
1999-12-20 06:45:01 +03:00
|
|
|
{
|
2006-03-18 17:58:49 +03:00
|
|
|
display_mode = TIME;
|
1999-12-20 06:45:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
vmstat_zero(char *args)
|
1999-12-20 06:45:01 +03:00
|
|
|
{
|
2006-03-18 17:58:49 +03:00
|
|
|
if (display_mode == RUN)
|
|
|
|
getinfo(&s1);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate number of users on the system */
|
|
|
|
static int
|
2000-07-05 15:03:20 +04:00
|
|
|
ucount(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2002-08-02 03:36:54 +04:00
|
|
|
static int onusers = -1;
|
|
|
|
int nusers = 0;
|
|
|
|
struct utmpentry *ehead;
|
|
|
|
|
|
|
|
nusers = getutentries(NULL, &ehead);
|
1995-01-20 11:30:50 +03:00
|
|
|
|
1999-10-10 05:07:03 +04:00
|
|
|
if (nusers != onusers) {
|
|
|
|
if (nusers == 1)
|
|
|
|
mvprintw(STATROW, STATCOL + 8, " ");
|
|
|
|
else
|
|
|
|
mvprintw(STATROW, STATCOL + 8, "s");
|
|
|
|
}
|
|
|
|
onusers = nusers;
|
1995-01-20 11:30:50 +03:00
|
|
|
return (nusers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float
|
2000-07-05 15:03:20 +04:00
|
|
|
cputime(int indx)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
double t;
|
1997-10-20 03:36:20 +04:00
|
|
|
int i;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
t = 0;
|
|
|
|
for (i = 0; i < CPUSTATES; i++)
|
2002-06-30 04:10:33 +04:00
|
|
|
t += cur.cp_time[i];
|
1995-01-20 11:30:50 +03:00
|
|
|
if (t == 0.0)
|
|
|
|
t = 1.0;
|
2002-06-30 04:10:33 +04:00
|
|
|
return (cur.cp_time[indx] * 100.0 / t);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
void
|
2003-01-19 00:02:35 +03:00
|
|
|
puthumanint(u_int64_t n, int l, int c, int w)
|
2002-08-08 21:06:31 +04:00
|
|
|
{
|
|
|
|
char b[128];
|
|
|
|
|
2003-02-17 22:30:33 +03:00
|
|
|
if (move(l, c) != OK)
|
|
|
|
return;
|
2002-08-08 21:06:31 +04:00
|
|
|
if (n == 0) {
|
|
|
|
hline(' ', w);
|
|
|
|
return;
|
|
|
|
}
|
2003-01-19 00:02:35 +03:00
|
|
|
if (humanize_number(b, w, n, "", HN_AUTOSCALE, HN_NOSPACE) == -1 ) {
|
2002-08-08 21:06:31 +04:00
|
|
|
hline('*', w);
|
|
|
|
return;
|
|
|
|
}
|
2006-03-18 17:58:49 +03:00
|
|
|
printw("%*s", w, b);
|
2002-08-08 21:06:31 +04:00
|
|
|
}
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
putint(int n, int l, int c, int w)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
char b[128];
|
|
|
|
|
2003-02-17 22:30:33 +03:00
|
|
|
if (move(l, c) != OK)
|
|
|
|
return;
|
1995-01-20 11:30:50 +03:00
|
|
|
if (n == 0) {
|
2000-06-04 22:29:13 +04:00
|
|
|
hline(' ', w);
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
|
|
|
}
|
1998-07-12 09:59:00 +04:00
|
|
|
(void)snprintf(b, sizeof b, "%*d", w, n);
|
2009-04-14 03:20:27 +04:00
|
|
|
if ((int)strlen(b) > w) {
|
2006-03-18 17:58:49 +03:00
|
|
|
if (display_mode == TIME)
|
|
|
|
hline('*', w);
|
|
|
|
else
|
|
|
|
puthumanint(n, l, c, w);
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
addstr(b);
|
|
|
|
}
|
|
|
|
|
2006-03-18 17:58:49 +03:00
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
putfloat(double f, int l, int c, int w, int d, int nz)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
char b[128];
|
|
|
|
|
2003-02-17 22:30:33 +03:00
|
|
|
if (move(l, c) != OK)
|
|
|
|
return;
|
1995-01-20 11:30:50 +03:00
|
|
|
if (nz && f == 0.0) {
|
2000-06-04 22:29:13 +04:00
|
|
|
hline(' ', w);
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
|
|
|
}
|
1998-07-12 09:59:00 +04:00
|
|
|
(void)snprintf(b, sizeof b, "%*.*f", w, d, f);
|
2009-04-14 03:20:27 +04:00
|
|
|
if ((int)strlen(b) > w) {
|
2000-06-04 22:29:13 +04:00
|
|
|
hline('*', w);
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
addstr(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-18 17:58:49 +03:00
|
|
|
getinfo(struct Info *stats)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
1995-04-29 09:54:42 +04:00
|
|
|
int mib[2];
|
|
|
|
size_t size;
|
2003-01-19 00:02:35 +03:00
|
|
|
int i;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2006-02-05 12:54:50 +03:00
|
|
|
cpureadstats();
|
2006-04-14 17:14:06 +04:00
|
|
|
drvreadstats();
|
2005-02-27 01:12:33 +03:00
|
|
|
NREAD(X_NCHSTATS, &stats->nchstats, sizeof stats->nchstats);
|
2005-05-22 18:00:59 +04:00
|
|
|
if (nintr)
|
|
|
|
NREAD(X_INTRCNT, stats->intrcnt, nintr * LONG);
|
2003-01-19 00:02:35 +03:00
|
|
|
for (i = 0; i < nevcnt; i++)
|
2005-05-22 18:00:59 +04:00
|
|
|
KREAD(ie_head[i].ie_count, &stats->evcnt[i],
|
|
|
|
sizeof stats->evcnt[i]);
|
2005-02-27 01:12:33 +03:00
|
|
|
size = sizeof(stats->uvmexp);
|
1998-02-07 17:08:23 +03:00
|
|
|
mib[0] = CTL_VM;
|
2000-11-29 14:18:33 +03:00
|
|
|
mib[1] = VM_UVMEXP2;
|
2005-02-27 01:12:33 +03:00
|
|
|
if (sysctl(mib, 2, &stats->uvmexp, &size, NULL, 0) < 0) {
|
1998-02-07 17:08:23 +03:00
|
|
|
error("can't get uvmexp: %s\n", strerror(errno));
|
2005-02-27 01:12:33 +03:00
|
|
|
memset(&stats->uvmexp, 0, sizeof(stats->uvmexp));
|
1998-02-07 17:08:23 +03:00
|
|
|
}
|
2005-02-27 01:12:33 +03:00
|
|
|
size = sizeof(stats->Total);
|
1995-01-20 11:30:50 +03:00
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_METER;
|
2005-02-27 01:12:33 +03:00
|
|
|
if (sysctl(mib, 2, &stats->Total, &size, NULL, 0) < 0) {
|
1995-01-20 11:30:50 +03:00
|
|
|
error("Can't get kernel info: %s\n", strerror(errno));
|
2005-02-27 01:12:33 +03:00
|
|
|
memset(&stats->Total, 0, sizeof(stats->Total));
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-02-27 01:12:33 +03:00
|
|
|
allocinfo(struct Info *stats)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
|
2005-05-22 18:00:59 +04:00
|
|
|
if (nintr &&
|
|
|
|
(stats->intrcnt = calloc(nintr, sizeof(long))) == NULL) {
|
2003-01-19 00:02:35 +03:00
|
|
|
error("calloc failed");
|
|
|
|
die(0);
|
|
|
|
}
|
2005-02-27 01:12:33 +03:00
|
|
|
if ((stats->evcnt = calloc(nevcnt, sizeof(u_int64_t))) == NULL) {
|
2003-01-19 00:02:35 +03:00
|
|
|
error("calloc failed");
|
1999-12-21 02:11:50 +03:00
|
|
|
die(0);
|
|
|
|
}
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-05 15:03:20 +04:00
|
|
|
copyinfo(struct Info *from, struct Info *to)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
long *intrcnt;
|
2003-01-19 00:02:35 +03:00
|
|
|
u_int64_t *evcnt;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
intrcnt = to->intrcnt;
|
2003-01-19 00:02:35 +03:00
|
|
|
evcnt = to->evcnt;
|
1995-01-20 11:30:50 +03:00
|
|
|
*to = *from;
|
2003-08-30 16:57:03 +04:00
|
|
|
memmove(to->intrcnt = intrcnt, from->intrcnt, nintr * sizeof *intrcnt);
|
2003-01-19 00:02:35 +03:00
|
|
|
memmove(to->evcnt = evcnt, from->evcnt, nevcnt * sizeof *evcnt);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-18 17:55:05 +03:00
|
|
|
dinfo(int dn, int r, int c)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2003-01-19 00:02:35 +03:00
|
|
|
double atime;
|
2003-02-18 17:55:05 +03:00
|
|
|
#define ADV if (disk_horiz) r++; else c += DISKCOLWIDTH
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2003-02-18 17:55:05 +03:00
|
|
|
mvprintw(r, c, "%*.*s", DISKCOLWIDTH, DISKCOLWIDTH, dr_name[dn]);
|
|
|
|
ADV;
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
putint((int)(cur.seek[dn]/etime+0.5), r, c, DISKCOLWIDTH);
|
2005-08-07 16:32:38 +04:00
|
|
|
ADV;
|
2006-04-14 17:14:06 +04:00
|
|
|
putint((int)((cur.rxfer[dn]+cur.wxfer[dn])/etime+0.5),
|
2005-08-07 16:32:38 +04:00
|
|
|
r, c, DISKCOLWIDTH);
|
|
|
|
ADV;
|
2006-04-14 17:14:06 +04:00
|
|
|
puthumanint((cur.rbytes[dn] + cur.wbytes[dn]) / etime + 0.5,
|
2005-08-07 16:32:38 +04:00
|
|
|
r, c, DISKCOLWIDTH);
|
|
|
|
ADV;
|
|
|
|
|
|
|
|
/* time busy in disk activity */
|
2006-04-14 17:14:06 +04:00
|
|
|
atime = cur.time[dn].tv_sec + cur.time[dn].tv_usec / 1000000.0;
|
2005-08-07 16:32:38 +04:00
|
|
|
atime = atime * 100.0 / etime;
|
|
|
|
if (atime >= 100)
|
|
|
|
putint(100, r, c, DISKCOLWIDTH);
|
|
|
|
else
|
|
|
|
putfloat(atime, r, c, DISKCOLWIDTH, 1, 1);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|