1999-06-29 22:14:15 +04:00
|
|
|
/* $NetBSD: iostat.c,v 1.12 1999/06/29 18:14:15 mjl Exp $ */
|
1995-01-20 11:51:48 +03:00
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 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.
|
|
|
|
*/
|
|
|
|
|
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[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93";
|
1995-01-20 11:51:48 +03:00
|
|
|
#endif
|
1999-06-29 22:14:15 +04:00
|
|
|
__RCSID("$NetBSD: iostat.c,v 1.12 1999/06/29 18:14:15 mjl Exp $");
|
1995-01-20 11:30:50 +03:00
|
|
|
#endif not lint
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/buf.h>
|
1996-05-11 03:16:30 +04:00
|
|
|
#include <sys/time.h>
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include "systat.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
#include "dkstats.h"
|
|
|
|
extern struct _disk cur;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
static int linesperregion;
|
|
|
|
static double etime;
|
|
|
|
static int numbers = 0; /* default display bar graphs */
|
1996-05-11 03:16:30 +04:00
|
|
|
static int secs = 0; /* default seconds shown */
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
static int barlabels __P((int));
|
|
|
|
static void histogram __P((double, int, double));
|
|
|
|
static int numlabels __P((int));
|
|
|
|
static int stats __P((int, int, int));
|
|
|
|
static void stat1 __P((int, int));
|
|
|
|
|
|
|
|
|
|
|
|
WINDOW *
|
|
|
|
openiostat()
|
|
|
|
{
|
1997-07-21 11:04:56 +04:00
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
return (subwin(stdscr, LINES-1-5, 0, 5, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
closeiostat(w)
|
|
|
|
WINDOW *w;
|
|
|
|
{
|
1997-07-21 11:04:56 +04:00
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
if (w == NULL)
|
|
|
|
return;
|
|
|
|
wclear(w);
|
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
initiostat()
|
|
|
|
{
|
1998-07-19 21:47:07 +04:00
|
|
|
extern gid_t egid;
|
1997-07-21 11:04:56 +04:00
|
|
|
|
1998-07-19 21:47:07 +04:00
|
|
|
dkinit(1, egid);
|
1996-05-11 03:16:30 +04:00
|
|
|
dkreadstats();
|
1997-07-21 11:04:56 +04:00
|
|
|
return(1);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fetchiostat()
|
|
|
|
{
|
1997-07-21 11:04:56 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (dk_ndrive == 0)
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
1996-05-11 03:16:30 +04:00
|
|
|
dkreadstats();
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
1999-06-29 22:14:15 +04:00
|
|
|
#define INSET 14
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
labeliostat()
|
|
|
|
{
|
|
|
|
int row;
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (dk_ndrive == 0) {
|
|
|
|
error("No drives defined.");
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
row = 0;
|
|
|
|
wmove(wnd, row, 0); wclrtobot(wnd);
|
|
|
|
mvwaddstr(wnd, row++, INSET,
|
|
|
|
"/0 /10 /20 /30 /40 /50 /60 /70 /80 /90 /100");
|
1999-06-29 22:14:15 +04:00
|
|
|
mvwaddstr(wnd, row++, 0, " cpu user|");
|
|
|
|
mvwaddstr(wnd, row++, 0, " nice|");
|
|
|
|
mvwaddstr(wnd, row++, 0, " system|");
|
|
|
|
mvwaddstr(wnd, row++, 0, " interrupt|");
|
|
|
|
mvwaddstr(wnd, row++, 0, " idle|");
|
1995-01-20 11:30:50 +03:00
|
|
|
if (numbers)
|
|
|
|
row = numlabels(row + 1);
|
|
|
|
else
|
|
|
|
row = barlabels(row + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
numlabels(row)
|
|
|
|
int row;
|
|
|
|
{
|
|
|
|
int i, col, regions, ndrives;
|
|
|
|
|
|
|
|
#define COLWIDTH 14
|
1997-05-24 04:48:24 +04:00
|
|
|
#define DRIVESPERLINE ((getmaxx(wnd) - INSET) / COLWIDTH)
|
1995-01-20 11:30:50 +03:00
|
|
|
for (ndrives = 0, i = 0; i < dk_ndrive; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
if (cur.dk_select[i])
|
1995-01-20 11:30:50 +03:00
|
|
|
ndrives++;
|
|
|
|
regions = howmany(ndrives, DRIVESPERLINE);
|
|
|
|
/*
|
|
|
|
* Deduct -regions for blank line after each scrolling region.
|
|
|
|
*/
|
1997-05-24 04:48:24 +04:00
|
|
|
linesperregion = (getmaxy(wnd) - row - regions) / regions;
|
1995-01-20 11:30:50 +03:00
|
|
|
/*
|
|
|
|
* Minimum region contains space for two
|
|
|
|
* label lines and one line of statistics.
|
|
|
|
*/
|
|
|
|
if (linesperregion < 3)
|
|
|
|
linesperregion = 3;
|
|
|
|
col = 0;
|
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
|
1997-05-24 04:48:24 +04:00
|
|
|
if (col + COLWIDTH >= getmaxx(wnd) - INSET) {
|
1995-01-20 11:30:50 +03:00
|
|
|
col = 0, row += linesperregion + 1;
|
1997-05-24 04:48:24 +04:00
|
|
|
if (row > getmaxy(wnd) - (linesperregion + 1))
|
1995-01-20 11:30:50 +03:00
|
|
|
break;
|
|
|
|
}
|
1996-05-11 03:16:30 +04:00
|
|
|
mvwaddstr(wnd, row, col + 4, cur.dk_name[i]);
|
1996-10-25 22:30:52 +04:00
|
|
|
mvwaddstr(wnd, row + 1, col, "KBps tps sec");
|
1995-01-20 11:30:50 +03:00
|
|
|
col += COLWIDTH;
|
|
|
|
}
|
|
|
|
if (col)
|
|
|
|
row += linesperregion + 1;
|
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
barlabels(row)
|
|
|
|
int row;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mvwaddstr(wnd, row++, INSET,
|
1996-05-11 03:16:30 +04:00
|
|
|
"/0 /10 /20 /30 /40 /50 /60 /70 /80 /90 /100");
|
|
|
|
linesperregion = 2 + secs;
|
1995-01-20 11:30:50 +03:00
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
|
1997-05-24 04:48:24 +04:00
|
|
|
if (row > getmaxy(wnd) - linesperregion)
|
1995-01-20 11:30:50 +03:00
|
|
|
break;
|
1999-06-29 22:14:15 +04:00
|
|
|
mvwprintw(wnd, row++, 0, "%7.7s KBps|", cur.dk_name[i]);
|
|
|
|
mvwaddstr(wnd, row++, 0, " tps|");
|
1996-05-11 03:16:30 +04:00
|
|
|
if (secs)
|
1999-06-29 22:14:15 +04:00
|
|
|
mvwaddstr(wnd, row++, 0, " msec|");
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
showiostat()
|
|
|
|
{
|
1997-10-20 03:36:20 +04:00
|
|
|
int i, row, col;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (dk_ndrive == 0)
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
1996-05-11 03:16:30 +04:00
|
|
|
dkswap();
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
etime = 0;
|
|
|
|
for(i = 0; i < CPUSTATES; i++) {
|
1996-05-11 03:16:30 +04:00
|
|
|
etime += cur.cp_time[i];
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
if (etime == 0.0)
|
|
|
|
etime = 1.0;
|
|
|
|
etime /= (float) hz;
|
|
|
|
row = 1;
|
|
|
|
|
|
|
|
/*
|
1995-05-17 19:51:47 +04:00
|
|
|
* Interrupt CPU state not calculated yet.
|
1995-01-20 11:30:50 +03:00
|
|
|
*/
|
1995-05-17 19:51:47 +04:00
|
|
|
for (i = 0; i < CPUSTATES; i++)
|
1995-01-20 11:30:50 +03:00
|
|
|
stat1(row++, i);
|
|
|
|
if (!numbers) {
|
|
|
|
row += 2;
|
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
|
1997-05-24 04:48:24 +04:00
|
|
|
if (row > getmaxy(wnd) - linesperregion)
|
1995-01-20 11:30:50 +03:00
|
|
|
break;
|
|
|
|
row = stats(row, INSET, i);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
col = 0;
|
|
|
|
wmove(wnd, row + linesperregion, 0);
|
|
|
|
wdeleteln(wnd);
|
|
|
|
wmove(wnd, row + 3, 0);
|
|
|
|
winsertln(wnd);
|
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
|
1997-05-24 04:48:24 +04:00
|
|
|
if (col + COLWIDTH >= getmaxx(wnd)) {
|
1995-01-20 11:30:50 +03:00
|
|
|
col = 0, row += linesperregion + 1;
|
1997-05-24 04:48:24 +04:00
|
|
|
if (row > getmaxy(wnd) - (linesperregion + 1))
|
1995-01-20 11:30:50 +03:00
|
|
|
break;
|
|
|
|
wmove(wnd, row + linesperregion, 0);
|
|
|
|
wdeleteln(wnd);
|
|
|
|
wmove(wnd, row + 3, 0);
|
|
|
|
winsertln(wnd);
|
|
|
|
}
|
|
|
|
(void) stats(row + 3, col, i);
|
|
|
|
col += COLWIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stats(row, col, dn)
|
|
|
|
int row, col, dn;
|
|
|
|
{
|
1996-05-11 03:16:30 +04:00
|
|
|
double atime, words;
|
|
|
|
|
|
|
|
/* time busy in disk activity */
|
|
|
|
atime = (double)cur.dk_time[dn].tv_sec +
|
|
|
|
((double)cur.dk_time[dn].tv_usec / (double)1000000);
|
|
|
|
|
|
|
|
words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */
|
1995-01-20 11:30:50 +03:00
|
|
|
if (numbers) {
|
1996-10-25 22:30:52 +04:00
|
|
|
mvwprintw(wnd, row, col, " %3.0f%4.0f%5.1f",
|
1996-05-11 03:16:30 +04:00
|
|
|
words / etime, cur.dk_xfer[dn] / etime, atime / etime);
|
1995-01-20 11:30:50 +03:00
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
wmove(wnd, row++, col);
|
1996-05-11 03:16:30 +04:00
|
|
|
histogram(words / etime, 50, 0.5);
|
1995-01-20 11:30:50 +03:00
|
|
|
wmove(wnd, row++, col);
|
1996-05-11 03:16:30 +04:00
|
|
|
histogram(cur.dk_xfer[dn] / etime, 50, 0.5);
|
|
|
|
if (secs) {
|
1995-01-20 11:30:50 +03:00
|
|
|
wmove(wnd, row++, col);
|
1996-05-11 03:16:30 +04:00
|
|
|
atime *= 1000; /* In milliseconds */
|
|
|
|
histogram(atime / etime, 50, 0.5);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stat1(row, o)
|
|
|
|
int row, o;
|
|
|
|
{
|
1997-10-20 03:36:20 +04:00
|
|
|
int i;
|
1995-01-20 11:30:50 +03:00
|
|
|
double time;
|
|
|
|
|
|
|
|
time = 0;
|
|
|
|
for (i = 0; i < CPUSTATES; i++)
|
1996-05-11 03:16:30 +04:00
|
|
|
time += cur.cp_time[i];
|
1995-01-20 11:30:50 +03:00
|
|
|
if (time == 0.0)
|
|
|
|
time = 1.0;
|
|
|
|
wmove(wnd, row, INSET);
|
|
|
|
#define CPUSCALE 0.5
|
1996-05-11 03:16:30 +04:00
|
|
|
histogram(100.0 * cur.cp_time[o] / time, 50, CPUSCALE);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
histogram(val, colwidth, scale)
|
|
|
|
double val;
|
|
|
|
int colwidth;
|
|
|
|
double scale;
|
|
|
|
{
|
|
|
|
char buf[10];
|
1997-10-20 03:36:20 +04:00
|
|
|
int k;
|
|
|
|
int v = (int)(val * scale) + 0.5;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
k = MIN(v, colwidth);
|
|
|
|
if (v > colwidth) {
|
1998-07-12 09:59:00 +04:00
|
|
|
snprintf(buf, sizeof buf, "%4.1f", val);
|
1995-01-20 11:30:50 +03:00
|
|
|
k -= strlen(buf);
|
|
|
|
while (k--)
|
|
|
|
waddch(wnd, 'X');
|
|
|
|
waddstr(wnd, buf);
|
1996-05-11 03:16:30 +04:00
|
|
|
wclrtoeol(wnd);
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (k--)
|
|
|
|
waddch(wnd, 'X');
|
|
|
|
wclrtoeol(wnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cmdiostat(cmd, args)
|
|
|
|
char *cmd, *args;
|
|
|
|
{
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (prefix(cmd, "secs"))
|
|
|
|
secs = !secs;
|
1995-01-20 11:30:50 +03:00
|
|
|
else if (prefix(cmd, "numbers"))
|
|
|
|
numbers = 1;
|
|
|
|
else if (prefix(cmd, "bars"))
|
|
|
|
numbers = 0;
|
|
|
|
else if (!dkcmd(cmd, args))
|
|
|
|
return (0);
|
|
|
|
wclear(wnd);
|
|
|
|
labeliostat();
|
|
|
|
refresh();
|
|
|
|
return (1);
|
|
|
|
}
|