diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c index d9c2ac5eca9d..d863d35ec2a4 100644 --- a/usr.bin/systat/vmstat.c +++ b/usr.bin/systat/vmstat.c @@ -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); diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c index 6ba0c15f0bbc..769f5ce204cc 100644 --- a/usr.bin/vmstat/dkstats.c +++ b/usr.bin/vmstat/dkstats.c @@ -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 diff --git a/usr.bin/vmstat/dkstats.h b/usr.bin/vmstat/dkstats.h index f98af9a32cfe..bcb23ca5550f 100644 --- a/usr.bin/vmstat/dkstats.h +++ b/usr.bin/vmstat/dkstats.h @@ -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 /* 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); diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index b219916802b1..81fa15a66611 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -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) {