Update to use new kernel io statistics.

This commit is contained in:
blymn 2006-04-14 13:14:06 +00:00
parent 7d866d268b
commit e48af18bc5
4 changed files with 62 additions and 201 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.31 2005/08/07 12:32:38 blymn Exp $
# $NetBSD: Makefile,v 1.32 2006/04/14 13:14:06 blymn Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
.include <bsd.own.mk>
@ -11,7 +11,7 @@ WARNS=3
CPPFLAGS+=-I${NETBSDSRCDIR}/usr.bin/vmstat -DSUPPORT_UTMP -DSUPPORT_UTMPX \
-I${NETBSDSRCDIR}/usr.bin/who
CWARNFLAGS+= -Wno-format-y2k
SRCS= bufcache.c cmds.c cmdtab.c disks.c df.c dkstats.c tpstats.c fetch.c \
SRCS= bufcache.c cmds.c cmdtab.c disks.c df.c drvstats.c fetch.c \
globalcmds.c icmp.c iostat.c ip.c keyboard.c main.c mbufs.c \
netcmds.c netstat.c pigs.c ps.c swap.c tcp.c vmstat.c utmpentry.c
DPADD= ${LIBCURSES} ${LIBM} ${LIBKVM}

View File

@ -1,4 +1,4 @@
/* $NetBSD: disks.c,v 1.15 2005/02/26 18:58:45 dsl Exp $ */
/* $NetBSD: disks.c,v 1.16 2006/04/14 13:14:06 blymn Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: disks.c,v 1.15 2005/02/26 18:58:45 dsl Exp $");
__RCSID("$NetBSD: disks.c,v 1.16 2006/04/14 13:14:06 blymn Exp $");
#endif /* not lint */
#include <ctype.h>
@ -42,16 +42,16 @@ __RCSID("$NetBSD: disks.c,v 1.15 2005/02/26 18:58:45 dsl Exp $");
#include "systat.h"
#include "extern.h"
#include "dkstats.h"
#include "drvstats.h"
static void dkselect(char *args, int truefalse, int selections[]);
static void drvselect(char *args, int truefalse, int selections[]);
void
disks_add(char *args)
{
if (args)
dkselect(args, 1, dk_select);
drvselect(args, 1, drv_select);
}
void
@ -59,7 +59,7 @@ disks_remove(char *args)
{
if (args)
dkselect(args, 0, dk_select);
drvselect(args, 0, drv_select);
}
void
@ -68,19 +68,19 @@ disks_drives(char *args)
int i;
if (args) {
for (i = 0; i < dk_ndrive; i++)
dk_select[i] = 0;
for (i = 0; i < ndrive; i++)
drv_select[i] = 0;
disks_add(args);
} else {
move(CMDLINE, 0);
clrtoeol();
for (i = 0; i < dk_ndrive; i++)
for (i = 0; i < ndrive; i++)
printw("%s ", dr_name[i]);
}
}
static void
dkselect(char *args, int truefalse, int selections[])
drvselect(char *args, int truefalse, int selections[])
{
char *cp;
int i;
@ -98,12 +98,12 @@ dkselect(char *args, int truefalse, int selections[])
*cp++ = '\0';
if (cp - args == 0)
break;
for (i = 0; i < dk_ndrive; i++)
for (i = 0; i < ndrive; i++)
if (strcmp(args, dr_name[i]) == 0) {
selections[i] = truefalse;
break;
}
if (i >= dk_ndrive)
if (i >= ndrive)
error("%s: unknown drive", args);
args = cp;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: iostat.c,v 1.35 2006/03/18 16:48:44 dsl Exp $ */
/* $NetBSD: iostat.c,v 1.36 2006/04/14 13:14:06 blymn Exp $ */
/*
* Copyright (c) 1980, 1992, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: iostat.c,v 1.35 2006/03/18 16:48:44 dsl Exp $");
__RCSID("$NetBSD: iostat.c,v 1.36 2006/04/14 13:14:06 blymn Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -43,8 +43,7 @@ __RCSID("$NetBSD: iostat.c,v 1.35 2006/03/18 16:48:44 dsl Exp $");
#include "systat.h"
#include "extern.h"
#include "dkstats.h"
#include "tpstats.h"
#include "drvstats.h"
static int linesperregion;
static double etime;
@ -56,7 +55,6 @@ static int barlabels(int);
static void histogram(double, int, double);
static int numlabels(int);
static int stats(int, int, int);
static int tpstats(int, int, int);
static void stat1(int, int);
@ -82,11 +80,9 @@ int
initiostat(void)
{
dkinit(1);
tpinit(1);
drvinit(1);
cpureadstats();
dkreadstats();
tpreadstats();
drvreadstats();
return(1);
}
@ -96,11 +92,8 @@ fetchiostat(void)
cpureadstats();
if (dk_ndrive != 0)
dkreadstats();
if (tp_ndrive != 0)
tpreadstats();
if (ndrive != 0)
drvreadstats();
}
#define INSET 14
@ -110,7 +103,7 @@ labeliostat(void)
{
int row;
if ((dk_ndrive == 0) && (tp_ndrive == 0)) {
if (ndrive == 0) {
error("No drives defined.");
return;
}
@ -136,11 +129,8 @@ numlabels(int row)
#define COLWIDTH (9 + secs * 5 + 1 + read_write * 9 + 1)
#define DRIVESPERLINE ((getmaxx(wnd) + 1) / COLWIDTH)
for (ndrives = 0, i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i])
ndrives++;
for (i = 0; i < tp_ndrive; i++)
if (cur_tape.select[i])
for (ndrives = 0, i = 0; i < ndrive; i++)
if (cur.select[i])
ndrives++;
regions = howmany(ndrives, DRIVESPERLINE);
@ -155,21 +145,15 @@ numlabels(int row)
if (linesperregion < 3)
linesperregion = 3;
col = 0;
for (i = 0; i < (dk_ndrive + tp_ndrive); i++)
if (((i < dk_ndrive) && (cur.dk_select[i])) ||
((i >= dk_ndrive) && (cur_tape.select[i - dk_ndrive]))) {
for (i = 0; i < ndrive; i++)
if (cur.select[i]) {
if (col + COLWIDTH - 1 > getmaxx(wnd)) {
col = 0, row += linesperregion + 1;
if (row > getmaxy(wnd) - (linesperregion))
break;
}
if (i < dk_ndrive)
mvwprintw(wnd, row, col + 5, "%s",
cur.dk_name[i]);
else
mvwprintw(wnd, row, col + 5, "%s",
cur_tape.name[i - dk_ndrive]);
mvwprintw(wnd, row, col + 5, "%s", cur.name[i]);
if (read_write)
mvwprintw(wnd, row, col + 11 + secs * 5,
@ -195,26 +179,12 @@ barlabels(int row)
mvwaddstr(wnd, row++, INSET,
"/0 /10 /20 /30 /40 /50 /60 /70 /80 /90 /100");
linesperregion = 2 + secs + (read_write ? 2 : 0);
for (i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i]) {
for (i = 0; i < ndrive; i++) {
if (cur.select[i]) {
if (row > getmaxy(wnd) - linesperregion)
break;
mvwprintw(wnd, row++, 0, "%7.7s kBps|",
cur.dk_name[i]);
mvwaddstr(wnd, row++, 0, " tps|");
if (read_write) {
mvwprintw(wnd, row++, 0, " (write) kBps|");
mvwaddstr(wnd, row++, 0, " tps|");
}
if (secs)
mvwaddstr(wnd, row++, 0, " msec|");
}
for (i = 0; i < tp_ndrive; i++)
if (cur_tape.select[i]) {
if (row > getmaxy(wnd) - linesperregion)
break;
mvwprintw(wnd, row++, 0, "%7.7s kBps|",
cur_tape.name[i]);
cur.name[i]);
mvwaddstr(wnd, row++, 0, " tps|");
if (read_write) {
mvwprintw(wnd, row++, 0, " (write) kBps|");
@ -223,6 +193,8 @@ barlabels(int row)
if (secs)
mvwaddstr(wnd, row++, 0, " msec|");
}
}
return (row);
}
@ -231,11 +203,10 @@ showiostat(void)
{
int i, row, col;
if (dk_ndrive == 0)
if (ndrive == 0)
return;
dkswap();
cpuswap();
tpswap();
drvswap();
etime = cur.cp_etime;
row = 1;
@ -247,18 +218,12 @@ showiostat(void)
stat1(row++, i);
if (!numbers) {
row += 2;
for (i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i]) {
for (i = 0; i < ndrive; i++)
if (cur.select[i]) {
if (row > getmaxy(wnd) - linesperregion)
break;
row = stats(row, INSET, i);
}
for (i = 0; i < tp_ndrive; i++)
if (cur_tape.select[i]) {
if (row > getmaxy(wnd) - linesperregion)
break;
row = tpstats(row, INSET, i);
}
return;
}
col = 0;
@ -266,22 +231,8 @@ showiostat(void)
wdeleteln(wnd);
wmove(wnd, row + 3, 0);
winsertln(wnd);
for (i = 0; i < dk_ndrive; i++)
if (cur.dk_select[i]) {
if (col + COLWIDTH - 1 > getmaxx(wnd)) {
col = 0, row += linesperregion + 1;
if (row > getmaxy(wnd) - (linesperregion + 1))
break;
wmove(wnd, row + linesperregion, 0);
wdeleteln(wnd);
wmove(wnd, row + 3, 0);
winsertln(wnd);
}
(void) stats(row + 3, col, i);
col += COLWIDTH;
}
for (i = 0; i < tp_ndrive; i++)
if (cur_tape.select[i]) {
for (i = 0; i < ndrive; i++)
if (cur.select[i]) {
if (col + COLWIDTH - 1 > getmaxx(wnd)) {
col = 0, row += linesperregion + 1;
if (row > getmaxy(wnd) - (linesperregion + 1))
@ -303,16 +254,16 @@ stats(int row, int col, int dn)
uint64_t rxfer;
/* time busy in disk activity */
atime = (double)cur.dk_time[dn].tv_sec +
((double)cur.dk_time[dn].tv_usec / (double)1000000);
atime = (double)cur.time[dn].tv_sec +
((double)cur.time[dn].tv_usec / (double)1000000);
/* # of k transferred */
rwords = cur.dk_rbytes[dn] / 1024.0;
wwords = cur.dk_wbytes[dn] / 1024.0;
rxfer = cur.dk_rxfer[dn];
rwords = cur.rbytes[dn] / 1024.0;
wwords = cur.wbytes[dn] / 1024.0;
rxfer = cur.rxfer[dn];
if (!read_write) {
rwords += wwords;
rxfer += cur.dk_wxfer[dn];
rxfer += cur.wxfer[dn];
}
if (numbers) {
mvwprintw(wnd, row, col, "%5.0f%4.0f",
@ -321,7 +272,7 @@ stats(int row, int col, int dn)
wprintw(wnd, "%5.1f", atime / etime);
if (read_write)
wprintw(wnd, " %5.0f%4.0f",
wwords / etime, cur.dk_wxfer[dn] / etime);
wwords / etime, cur.wxfer[dn] / etime);
return (row);
}
@ -333,55 +284,7 @@ stats(int row, int col, int dn)
wmove(wnd, row++, col);
histogram(wwords / etime, 50, 0.5);
wmove(wnd, row++, col);
histogram(cur.dk_wxfer[dn] / etime, 50, 0.5);
}
if (secs) {
wmove(wnd, row++, col);
atime *= 1000; /* In milliseconds */
histogram(atime / etime, 50, 0.5);
}
return (row);
}
static int
tpstats(int row, int col, int dn)
{
double atime, rwords, wwords;
uint64_t rxfer;
/* time busy in disk activity */
atime = (double)cur_tape.time[dn].tv_sec +
((double)cur_tape.time[dn].tv_usec / (double)1000000);
/* # of k transferred */
rwords = cur_tape.rbytes[dn] / 1024.0;
wwords = cur_tape.wbytes[dn] / 1024.0;
rxfer = cur_tape.rxfer[dn];
if (!read_write) {
rwords = wwords;
rxfer += cur_tape.wxfer[dn];
}
if (numbers) {
mvwprintw(wnd, row, col, "%5.0f%4.0f",
rwords / etime, rxfer / etime);
if (secs)
wprintw(wnd, "%5.1f", atime / etime);
if (read_write)
wprintw(wnd, " %5.0f%4.0f",
wwords / etime, cur_tape.wxfer[dn] / etime);
return (row);
}
wmove(wnd, row++, col);
histogram(rwords / etime, 50, 0.5);
wmove(wnd, row++, col);
histogram(rxfer / etime, 50, 0.5);
if (read_write) {
wmove(wnd, row++, col);
histogram(wwords / etime, 50, 0.5);
wmove(wnd, row++, col);
histogram(cur_tape.wxfer[dn] / etime, 50, 0.5);
histogram(cur.wxfer[dn] / etime, 50, 0.5);
}
if (secs) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: vmstat.c,v 1.64 2006/03/20 20:36:38 dsl Exp $ */
/* $NetBSD: vmstat.c,v 1.65 2006/04/14 13:14:06 blymn 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.64 2006/03/20 20:36:38 dsl Exp $");
__RCSID("$NetBSD: vmstat.c,v 1.65 2006/04/14 13:14:06 blymn Exp $");
#endif /* not lint */
/*
@ -55,8 +55,7 @@ __RCSID("$NetBSD: vmstat.c,v 1.64 2006/03/20 20:36:38 dsl Exp $");
#include "systat.h"
#include "extern.h"
#include "dkstats.h"
#include "tpstats.h"
#include "drvstats.h"
#include "utmpentry.h"
#include "vmstat.h"
@ -75,7 +74,6 @@ static void allocinfo(struct Info *);
static void copyinfo(struct Info *, struct Info *);
static float cputime(int);
static void dinfo(int, int, int);
static void tinfo(int, int, int);
static void getinfo(struct Info *);
static int ucount(void);
@ -222,9 +220,7 @@ initvmstat(void)
}
}
hertz = stathz ? stathz : hz;
if (!dkinit(1))
return(0);
if (!tpinit(1))
if (!drvinit(1))
return(0);
/* Old style interrupt counts - deprecated */
@ -497,8 +493,7 @@ showvmstat(void)
cpuswap();
if (display_mode == TIME) {
dkswap();
tpswap();
drvswap();
etime = cur.cp_etime;
/* < 5 ticks - ignore this trash */
if ((etime * hertz) < 1.0) {
@ -552,14 +547,9 @@ showvmstat(void)
/* Disks */
for (l = 0, i = 0, r = DISKROW, c = DISKCOL;
i < (dk_ndrive + tp_ndrive); i++) {
if (i < dk_ndrive) {
if (!dk_select[i])
continue;
} else {
if (!tp_select[i - dk_ndrive])
continue;
}
i < ndrive; i++) {
if (!drv_select[i])
continue;
if (disk_horiz)
c += DISKCOLWIDTH;
@ -583,10 +573,7 @@ showvmstat(void)
}
l++;
if (i < dk_ndrive)
dinfo(i, r, c);
else
tinfo(i - dk_ndrive, r, c);
dinfo(i, r, c);
}
/* blank out if we lost any disks */
for (i = l; i < last_disks; i++) {
@ -793,8 +780,7 @@ getinfo(struct Info *stats)
int i;
cpureadstats();
dkreadstats();
tpreadstats();
drvreadstats();
NREAD(X_NCHSTATS, &stats->nchstats, sizeof stats->nchstats);
if (nintr)
NREAD(X_INTRCNT, stats->intrcnt, nintr * LONG);
@ -854,48 +840,20 @@ dinfo(int dn, int r, int c)
mvprintw(r, c, "%*.*s", DISKCOLWIDTH, DISKCOLWIDTH, dr_name[dn]);
ADV;
putint((int)(cur.dk_seek[dn]/etime+0.5), r, c, DISKCOLWIDTH);
putint((int)(cur.seek[dn]/etime+0.5), r, c, DISKCOLWIDTH);
ADV;
putint((int)((cur.dk_rxfer[dn]+cur.dk_wxfer[dn])/etime+0.5),
putint((int)((cur.rxfer[dn]+cur.wxfer[dn])/etime+0.5),
r, c, DISKCOLWIDTH);
ADV;
puthumanint((cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) / etime + 0.5,
puthumanint((cur.rbytes[dn] + cur.wbytes[dn]) / etime + 0.5,
r, c, DISKCOLWIDTH);
ADV;
/* time busy in disk activity */
atime = cur.dk_time[dn].tv_sec + cur.dk_time[dn].tv_usec / 1000000.0;
atime = cur.time[dn].tv_sec + cur.time[dn].tv_usec / 1000000.0;
atime = atime * 100.0 / etime;
if (atime >= 100)
putint(100, r, c, DISKCOLWIDTH);
else
putfloat(atime, r, c, DISKCOLWIDTH, 1, 1);
}
static void
tinfo(int dn, int r, int c)
{
double atime;
mvprintw(r, c, "%*.*s", DISKCOLWIDTH, DISKCOLWIDTH, tp_name[dn]);
ADV;
ADV; /* skip over the seeks column - not relevant for tape drives */
putint((int)((cur_tape.rxfer[dn]+cur_tape.wxfer[dn])/etime+0.5),
r, c, DISKCOLWIDTH);
ADV;
puthumanint((cur_tape.rbytes[dn] + cur_tape.wbytes[dn]) / etime + 0.5,
r, c, DISKCOLWIDTH);
ADV;
/* time busy in disk activity */
atime = cur_tape.time[dn].tv_sec + cur_tape.time[dn].tv_usec / 1000000.0;
atime = atime * 100.0 / etime;
if (atime >= 100)
putint(100, r, c, DISKCOLWIDTH);
else
putfloat(atime, r, c, DISKCOLWIDTH, 1, 1);
#undef ADV
}