2009-04-14 03:20:27 +04:00
|
|
|
/* $NetBSD: iostat.c,v 1.37 2009/04/13 23:20:27 lukem 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.
|
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[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93";
|
1995-01-20 11:51:48 +03:00
|
|
|
#endif
|
2009-04-14 03:20:27 +04:00
|
|
|
__RCSID("$NetBSD: iostat.c,v 1.37 2009/04/13 23:20:27 lukem Exp $");
|
2001-01-16 05:50:27 +03:00
|
|
|
#endif /* not lint */
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
2000-12-01 05:19:43 +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"
|
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 */
|
2002-11-01 15:47:55 +03:00
|
|
|
static int read_write = 0; /* default read/write shown */
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2000-07-05 15:03:20 +04:00
|
|
|
static int barlabels(int);
|
|
|
|
static void histogram(double, int, double);
|
|
|
|
static int numlabels(int);
|
|
|
|
static int stats(int, int, int);
|
|
|
|
static void stat1(int, int);
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
WINDOW *
|
2000-07-05 15:03:20 +04:00
|
|
|
openiostat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
1997-07-21 11:04:56 +04:00
|
|
|
|
2003-02-24 13:10:00 +03:00
|
|
|
return (subwin(stdscr, -1, 0, 5, 0));
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
closeiostat(WINDOW *w)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
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
|
2000-07-05 15:03:20 +04:00
|
|
|
initiostat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
1997-07-21 11:04:56 +04:00
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
drvinit(1);
|
2006-02-05 12:58:39 +03:00
|
|
|
cpureadstats();
|
2006-04-14 17:14:06 +04:00
|
|
|
drvreadstats();
|
1997-07-21 11:04:56 +04:00
|
|
|
return(1);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
fetchiostat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
1997-07-21 11:04:56 +04:00
|
|
|
|
2006-02-05 12:58:39 +03:00
|
|
|
cpureadstats();
|
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
if (ndrive != 0)
|
|
|
|
drvreadstats();
|
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
|
2000-07-05 15:03:20 +04:00
|
|
|
labeliostat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
|
|
|
int row;
|
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
if (ndrive == 0) {
|
1996-05-11 03:16:30 +04:00
|
|
|
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");
|
2004-02-13 14:36:08 +03:00
|
|
|
mvwaddstr(wnd, row++, 0, " CPU user|");
|
1999-06-29 22:14:15 +04:00
|
|
|
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
|
2000-07-05 15:03:20 +04:00
|
|
|
numlabels(int row)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2009-04-14 03:20:27 +04:00
|
|
|
int col, regions;
|
|
|
|
size_t i, ndrives;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2005-02-27 01:28:23 +03:00
|
|
|
#define COLWIDTH (9 + secs * 5 + 1 + read_write * 9 + 1)
|
2003-08-12 21:16:53 +04:00
|
|
|
#define DRIVESPERLINE ((getmaxx(wnd) + 1) / COLWIDTH)
|
2006-04-14 17:14:06 +04:00
|
|
|
for (ndrives = 0, i = 0; i < ndrive; i++)
|
|
|
|
if (cur.select[i])
|
2005-08-07 16:32:38 +04:00
|
|
|
ndrives++;
|
2006-04-14 17:14:06 +04:00
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
regions = howmany(ndrives, DRIVESPERLINE);
|
|
|
|
/*
|
|
|
|
* Deduct -regions for blank line after each scrolling region.
|
|
|
|
*/
|
2003-08-12 21:16:53 +04:00
|
|
|
linesperregion = (getmaxy(wnd) - row - regions + 1) / 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;
|
2006-04-14 17:14:06 +04:00
|
|
|
for (i = 0; i < ndrive; i++)
|
|
|
|
if (cur.select[i]) {
|
2003-08-12 21:16:53 +04:00
|
|
|
if (col + COLWIDTH - 1 > getmaxx(wnd)) {
|
1995-01-20 11:30:50 +03:00
|
|
|
col = 0, row += linesperregion + 1;
|
2003-08-12 21:16:53 +04:00
|
|
|
if (row > getmaxy(wnd) - (linesperregion))
|
1995-01-20 11:30:50 +03:00
|
|
|
break;
|
|
|
|
}
|
2005-08-07 16:32:38 +04:00
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
mvwprintw(wnd, row, col + 5, "%s", cur.name[i]);
|
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
if (read_write)
|
2005-02-27 01:28:23 +03:00
|
|
|
mvwprintw(wnd, row, col + 11 + secs * 5,
|
2005-02-27 01:11:06 +03:00
|
|
|
"(write)");
|
2005-02-27 01:28:23 +03:00
|
|
|
mvwprintw(wnd, row + 1, col, " kBps %s",
|
2005-02-27 01:11:06 +03:00
|
|
|
read_write ? "r/s" : "tps");
|
|
|
|
if (secs)
|
|
|
|
waddstr(wnd, " sec");
|
|
|
|
if (read_write)
|
2005-02-27 01:28:23 +03:00
|
|
|
waddstr(wnd, " kBps w/s");
|
1995-01-20 11:30:50 +03:00
|
|
|
col += COLWIDTH;
|
|
|
|
}
|
|
|
|
if (col)
|
|
|
|
row += linesperregion + 1;
|
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-07-05 15:03:20 +04:00
|
|
|
barlabels(int row)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2009-04-14 03:20:27 +04:00
|
|
|
size_t i;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
|
|
|
mvwaddstr(wnd, row++, INSET,
|
1996-05-11 03:16:30 +04:00
|
|
|
"/0 /10 /20 /30 /40 /50 /60 /70 /80 /90 /100");
|
2002-11-01 15:47:55 +03:00
|
|
|
linesperregion = 2 + secs + (read_write ? 2 : 0);
|
2006-04-14 17:14:06 +04:00
|
|
|
for (i = 0; i < ndrive; i++) {
|
|
|
|
if (cur.select[i]) {
|
2005-08-07 16:32:38 +04:00
|
|
|
if (row > getmaxy(wnd) - linesperregion)
|
|
|
|
break;
|
|
|
|
mvwprintw(wnd, row++, 0, "%7.7s kBps|",
|
2006-04-14 17:14:06 +04:00
|
|
|
cur.name[i]);
|
2005-08-07 16:32:38 +04:00
|
|
|
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|");
|
|
|
|
}
|
2006-04-14 17:14:06 +04:00
|
|
|
}
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
showiostat(void)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2009-04-14 03:20:27 +04:00
|
|
|
int row, col;
|
|
|
|
size_t i;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2006-04-14 17:14:06 +04:00
|
|
|
if (ndrive == 0)
|
1995-01-20 11:30:50 +03:00
|
|
|
return;
|
2006-02-05 12:58:39 +03:00
|
|
|
cpuswap();
|
2006-04-14 17:14:06 +04:00
|
|
|
drvswap();
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2002-06-30 04:10:33 +04:00
|
|
|
etime = cur.cp_etime;
|
1995-01-20 11:30:50 +03:00
|
|
|
row = 1;
|
|
|
|
|
|
|
|
/*
|
1995-05-17 19:51:47 +04:00
|
|
|
* Interrupt CPU state not calculated yet.
|
2002-06-30 04:10:33 +04: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;
|
2006-04-14 17:14:06 +04:00
|
|
|
for (i = 0; i < ndrive; i++)
|
|
|
|
if (cur.select[i]) {
|
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);
|
2006-04-14 17:14:06 +04:00
|
|
|
for (i = 0; i < ndrive; i++)
|
|
|
|
if (cur.select[i]) {
|
2005-08-07 16:32:38 +04:00
|
|
|
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;
|
|
|
|
}
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-07-05 15:03:20 +04:00
|
|
|
stats(int row, int col, int dn)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2002-11-01 15:47:55 +03:00
|
|
|
double atime, rwords, wwords;
|
2005-02-27 01:11:06 +03:00
|
|
|
uint64_t rxfer;
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
/* time busy in disk activity */
|
2006-04-14 17:14:06 +04:00
|
|
|
atime = (double)cur.time[dn].tv_sec +
|
|
|
|
((double)cur.time[dn].tv_usec / (double)1000000);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
/* # of k transferred */
|
2006-04-14 17:14:06 +04:00
|
|
|
rwords = cur.rbytes[dn] / 1024.0;
|
|
|
|
wwords = cur.wbytes[dn] / 1024.0;
|
|
|
|
rxfer = cur.rxfer[dn];
|
2005-02-27 01:11:06 +03:00
|
|
|
if (!read_write) {
|
2006-03-18 19:48:44 +03:00
|
|
|
rwords += wwords;
|
2006-04-14 17:14:06 +04:00
|
|
|
rxfer += cur.wxfer[dn];
|
2005-08-07 16:32:38 +04:00
|
|
|
}
|
|
|
|
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",
|
2006-04-14 17:14:06 +04:00
|
|
|
wwords / etime, cur.wxfer[dn] / etime);
|
2005-08-07 16:32:38 +04:00
|
|
|
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);
|
2006-04-14 17:14:06 +04:00
|
|
|
histogram(cur.wxfer[dn] / etime, 50, 0.5);
|
2005-08-07 16:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (secs) {
|
|
|
|
wmove(wnd, row++, col);
|
|
|
|
atime *= 1000; /* In milliseconds */
|
|
|
|
histogram(atime / etime, 50, 0.5);
|
|
|
|
}
|
|
|
|
return (row);
|
|
|
|
}
|
|
|
|
|
1995-01-20 11:30:50 +03:00
|
|
|
static void
|
2000-07-05 15:03:20 +04:00
|
|
|
stat1(int row, int o)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2009-04-14 03:20:27 +04:00
|
|
|
size_t i;
|
2005-02-27 01:11:06 +03:00
|
|
|
double total_time;
|
1995-01-20 11:30:50 +03:00
|
|
|
|
2005-02-27 01:11:06 +03:00
|
|
|
total_time = 0;
|
1995-01-20 11:30:50 +03:00
|
|
|
for (i = 0; i < CPUSTATES; i++)
|
2005-02-27 01:11:06 +03:00
|
|
|
total_time += cur.cp_time[i];
|
|
|
|
if (total_time == 0.0)
|
|
|
|
total_time = 1.0;
|
1995-01-20 11:30:50 +03:00
|
|
|
wmove(wnd, row, INSET);
|
|
|
|
#define CPUSCALE 0.5
|
2005-02-27 01:11:06 +03:00
|
|
|
histogram(100.0 * cur.cp_time[o] / total_time, 50, CPUSCALE);
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-05 15:03:20 +04:00
|
|
|
histogram(double val, int colwidth, double scale)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
2003-02-01 22:12:30 +03:00
|
|
|
int v = (int)(val * scale + 0.5);
|
|
|
|
int factor = 1;
|
|
|
|
int y, x;
|
|
|
|
|
|
|
|
while (v > colwidth) {
|
|
|
|
v = (v + 5) / 10;
|
|
|
|
factor *= 10;
|
1995-01-20 11:30:50 +03:00
|
|
|
}
|
2003-02-01 22:12:30 +03:00
|
|
|
getyx(wnd, y, x);
|
1995-01-20 11:30:50 +03:00
|
|
|
wclrtoeol(wnd);
|
2003-02-01 22:12:30 +03:00
|
|
|
whline(wnd, 'X', v);
|
|
|
|
if (factor != 1)
|
|
|
|
mvwprintw(wnd, y, x + colwidth + 1, "* %d ", factor);
|
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
|
|
|
iostat_bars(char *args)
|
1995-01-20 11:30:50 +03:00
|
|
|
{
|
1999-12-20 06:45:01 +03:00
|
|
|
numbers = 0;
|
|
|
|
wclear(wnd);
|
|
|
|
labeliostat();
|
|
|
|
refresh();
|
|
|
|
}
|
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
|
|
|
iostat_numbers(char *args)
|
1999-12-20 06:45:01 +03:00
|
|
|
{
|
|
|
|
numbers = 1;
|
|
|
|
wclear(wnd);
|
|
|
|
labeliostat();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
iostat_secs(char *args)
|
1999-12-20 06:45:01 +03:00
|
|
|
{
|
|
|
|
secs = !secs;
|
1995-01-20 11:30:50 +03:00
|
|
|
wclear(wnd);
|
|
|
|
labeliostat();
|
|
|
|
refresh();
|
|
|
|
}
|
2002-11-01 15:47:55 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
iostat_rw(char *args)
|
|
|
|
{
|
2005-02-27 01:11:06 +03:00
|
|
|
read_write ^= 1;
|
2002-11-01 15:47:55 +03:00
|
|
|
wclear(wnd);
|
|
|
|
labeliostat();
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
iostat_all(char *args)
|
|
|
|
{
|
|
|
|
read_write = 0;
|
|
|
|
wclear(wnd);
|
|
|
|
labeliostat();
|
|
|
|
refresh();
|
|
|
|
}
|