Split dkreadstats() into dkreadstats(), tkreadstats() and cpureadstats().

Similarly for dkswap().
Allows code to only call one of these.
Rename struct _disk to _vminfo to be nearer its contents.
Change 'systat vm' so that it always shows the 'current' cpu times, even
after ':run' or ':boot' commands. The code in vmstat.c doesn't support :run.
This commit is contained in:
dsl 2006-02-05 09:54:50 +00:00
parent a6843277e3
commit 228802f437
4 changed files with 80 additions and 31 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmstat.c,v 1.61 2005/08/07 12:32:38 blymn Exp $ */
/* $NetBSD: vmstat.c,v 1.62 2006/02/05 09:54:50 dsl Exp $ */
/*-
* Copyright (c) 1983, 1989, 1992, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#endif
__RCSID("$NetBSD: vmstat.c,v 1.61 2005/08/07 12:32:38 blymn Exp $");
__RCSID("$NetBSD: vmstat.c,v 1.62 2006/02/05 09:54:50 dsl Exp $");
#endif /* not lint */
/*
@ -425,6 +425,7 @@ showvmstat(void)
relabel = 0;
}
cpuswap();
if (state == TIME) {
dkswap();
tpswap();
@ -749,6 +750,7 @@ getinfo(struct Info *stats, enum state st)
size_t size;
int i;
cpureadstats();
dkreadstats();
tpreadstats();
NREAD(X_NCHSTATS, &stats->nchstats, sizeof stats->nchstats);

View File

@ -1,4 +1,4 @@
/* $NetBSD: dkstats.c,v 1.22 2005/02/26 21:19:18 dsl Exp $ */
/* $NetBSD: dkstats.c,v 1.23 2006/02/05 09:54:50 dsl Exp $ */
/*
* Copyright (c) 1996 John M. Vinopal
@ -66,7 +66,7 @@ static struct nlist namelist[] = {
};
/* Structures to hold the statistics. */
struct _disk cur, last;
struct _vminfo cur, last;
/* Kernel pointers: nlistf and memf defined in calling program. */
static kvm_t *kd = NULL;
@ -110,12 +110,6 @@ static void deref_kptr(void *, void *, size_t);
* values, storing the present values in the 'last' structure, and
* the delta values in the 'cur' structure.
*/
void
dkswap(void)
{
double etime;
u_int64_t tmp;
int i, state;
#define SWAP(fld) do { \
tmp = cur.fld; \
@ -123,6 +117,12 @@ dkswap(void)
last.fld = tmp; \
} while (/* CONSTCOND */0)
void
dkswap(void)
{
u_int64_t tmp;
int i;
for (i = 0; i < dk_ndrive; i++) {
struct timeval tmp_timer;
@ -143,10 +143,27 @@ dkswap(void)
timerclear(&(last.dk_time[i]));
timerset(&tmp_timer, &(last.dk_time[i]));
}
for (i = 0; i < CPUSTATES; i++)
SWAP(cp_time[i]);
}
void
tkswap(void)
{
u_int64_t tmp;
SWAP(tk_nin);
SWAP(tk_nout);
}
void
cpuswap(void)
{
double etime;
u_int64_t tmp;
int i, state;
for (i = 0; i < CPUSTATES; i++)
SWAP(cp_time[i]);
etime = 0;
for (state = 0; state < CPUSTATES; ++state) {
@ -158,13 +175,11 @@ dkswap(void)
etime /= cur.cp_ncpu;
cur.cp_etime = etime;
#undef SWAP
}
#undef SWAP
/*
* Read the disk statistics for each disk in the disk list.
* Also collect statistics for tty i/o and CPU ticks.
*/
void
dkreadstats(void)
@ -193,7 +208,31 @@ dkreadstats(void)
cur.dk_time[i].tv_sec = dk_drives[i].dk_time_sec;
cur.dk_time[i].tv_usec = dk_drives[i].dk_time_usec;
}
} else {
for (i = 0; i < dk_ndrive; i++) {
deref_kptr(p, &cur_disk, sizeof(cur_disk));
cur.dk_rxfer[i] = cur_disk.dk_rxfer;
cur.dk_wxfer[i] = cur_disk.dk_wxfer;
cur.dk_seek[i] = cur_disk.dk_seek;
cur.dk_rbytes[i] = cur_disk.dk_rbytes;
cur.dk_wbytes[i] = cur_disk.dk_wbytes;
timerset(&(cur_disk.dk_time), &(cur.dk_time[i]));
p = cur_disk.dk_link.tqe_next;
}
}
}
/*
* Read collect statistics for tty i/o.
*/
void
tkreadstats(void)
{
size_t size;
int mib[3];
if (memf == NULL) {
mib[0] = CTL_KERN;
mib[1] = KERN_TKSTAT;
mib[2] = KERN_TKSTAT_NIN;
@ -206,20 +245,20 @@ dkreadstats(void)
if (sysctl(mib, 3, &cur.tk_nout, &size, NULL, 0) < 0)
cur.tk_nout = 0;
} else {
for (i = 0; i < dk_ndrive; i++) {
deref_kptr(p, &cur_disk, sizeof(cur_disk));
cur.dk_rxfer[i] = cur_disk.dk_rxfer;
cur.dk_wxfer[i] = cur_disk.dk_wxfer;
cur.dk_seek[i] = cur_disk.dk_seek;
cur.dk_rbytes[i] = cur_disk.dk_rbytes;
cur.dk_wbytes[i] = cur_disk.dk_wbytes;
timerset(&(cur_disk.dk_time), &(cur.dk_time[i]));
p = cur_disk.dk_link.tqe_next;
}
deref_nl(X_TK_NIN, &cur.tk_nin, sizeof(cur.tk_nin));
deref_nl(X_TK_NOUT, &cur.tk_nout, sizeof(cur.tk_nout));
}
}
/*
* Read collect statistics for CPU ticks.
*/
void
cpureadstats(void)
{
size_t size;
int mib[2];
/*
* XXX Need to locate the `correct' CPU when looking for this

View File

@ -1,4 +1,4 @@
/* $NetBSD: dkstats.h,v 1.6 2002/11/01 12:47:56 mrg Exp $ */
/* $NetBSD: dkstats.h,v 1.7 2006/02/05 09:54:50 dsl Exp $ */
/*
* Copyright (c) 1996 John M. Vinopal
@ -37,7 +37,7 @@
#include <unistd.h>
/* poseur disk entry to hold the information we're interested in. */
struct _disk {
struct _vminfo {
int *dk_select; /* Display stats for selected disks. */
char **dk_name; /* Disk names (sd0, wd1, etc). */
u_int64_t *dk_rxfer; /* # of read transfers. */
@ -53,10 +53,14 @@ struct _disk {
double cp_etime; /* Elapsed time */
};
extern struct _disk cur;
extern struct _vminfo cur;
extern char **dr_name;
extern int *dk_select, dk_ndrive;
int dkinit(int);
void cpureadstats(void);
void dkreadstats(void);
void tkreadstats(void);
void cpuswap(void);
void dkswap(void);
void tkswap(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmstat.c,v 1.138 2005/10/22 15:32:48 nonaka Exp $ */
/* $NetBSD: vmstat.c,v 1.139 2006/02/05 09:54:50 dsl Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
#else
__RCSID("$NetBSD: vmstat.c,v 1.138 2005/10/22 15:32:48 nonaka Exp $");
__RCSID("$NetBSD: vmstat.c,v 1.139 2006/02/05 09:54:50 dsl Exp $");
#endif
#endif /* not lint */
@ -646,6 +646,8 @@ dovmstat(struct timespec *interval, int reps)
printhdr();
/* Read new disk statistics */
dkreadstats();
cpureadstats();
tkreadstats();
kread(namelist, X_UVMEXP, &uvmexp, sizeof(uvmexp));
if (memf != NULL) {
/*
@ -889,6 +891,8 @@ dkstats(void)
/* Calculate disk stat deltas. */
dkswap();
cpuswap();
tkswap();
etime = cur.cp_etime;
for (dn = 0; dn < dk_ndrive; ++dn) {