2003-03-01 10:40:58 +03:00
|
|
|
/* $NetBSD: iostat.c,v 1.34 2003/03/01 07:40:58 enami Exp $ */
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 John M. Vinopal
|
|
|
|
* 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 for the NetBSD Project
|
|
|
|
* by John M. Vinopal.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
1995-11-28 23:16:28 +03:00
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
/*-
|
1994-05-15 01:52:16 +04:00
|
|
|
* Copyright (c) 1986, 1991, 1993
|
1996-05-11 03:16:30 +04:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
*
|
|
|
|
* 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:
|
1996-05-11 03:16:30 +04:00
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
* 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-10-17 13:03:53 +04:00
|
|
|
#include <sys/cdefs.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#ifndef lint
|
1997-10-17 13:03:53 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1986, 1991, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-11-28 23:16:28 +03:00
|
|
|
#if 0
|
1997-10-17 09:06:40 +04:00
|
|
|
static char sccsid[] = "@(#)iostat.c 8.3 (Berkeley) 4/28/95";
|
1995-11-28 23:16:28 +03:00
|
|
|
#else
|
2003-03-01 10:40:58 +03:00
|
|
|
__RCSID("$NetBSD: iostat.c,v 1.34 2003/03/01 07:40:58 enami Exp $");
|
1995-11-28 23:16:28 +03:00
|
|
|
#endif
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1997-10-17 09:06:40 +04:00
|
|
|
#include <sys/types.h>
|
2000-06-04 01:00:42 +04:00
|
|
|
#include <sys/sched.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <sys/dkstat.h>
|
1996-05-11 03:16:30 +04:00
|
|
|
#include <sys/time.h>
|
1994-05-15 01:52:16 +04:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-05-15 01:52:16 +04:00
|
|
|
#include <unistd.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
#include "dkstats.h"
|
|
|
|
|
|
|
|
/* Namelist and memory files. */
|
|
|
|
char *nlistf, *memf;
|
|
|
|
|
|
|
|
int hz, reps, interval;
|
|
|
|
static int todo = 0;
|
|
|
|
|
|
|
|
#define ISSET(x, a) ((x) & (a))
|
1998-08-25 12:05:47 +04:00
|
|
|
#define SHOW_CPU 1<<0
|
|
|
|
#define SHOW_TTY 1<<1
|
|
|
|
#define SHOW_STATS_1 1<<2
|
|
|
|
#define SHOW_STATS_2 1<<3
|
|
|
|
#define SHOW_STATS_X 1<<4
|
|
|
|
#define SHOW_TOTALS 1<<7
|
|
|
|
#define SHOW_STATS_ALL (SHOW_STATS_1 | SHOW_STATS_2 | SHOW_STATS_X)
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2000-12-01 02:59:03 +03:00
|
|
|
static void cpustats(void);
|
|
|
|
static void disk_stats(double);
|
|
|
|
static void disk_stats2(double);
|
|
|
|
static void disk_statsx(double);
|
|
|
|
static void header(int);
|
|
|
|
static void usage(void);
|
|
|
|
static void display(void);
|
2003-03-01 10:40:58 +03:00
|
|
|
static int selectdrives(int, char *[]);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2003-03-01 10:40:58 +03:00
|
|
|
int main(int, char *[]);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
1994-05-15 01:52:16 +04:00
|
|
|
int
|
2000-12-01 02:59:03 +03:00
|
|
|
main(int argc, char *argv[])
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
2003-03-01 10:40:58 +03:00
|
|
|
int ch, hdrcnt, ndrives, lines;
|
2002-09-19 03:18:44 +04:00
|
|
|
struct timespec tv;
|
1996-05-11 03:16:30 +04:00
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
while ((ch = getopt(argc, argv, "Cc:dDIM:N:Tw:x")) != -1)
|
2002-11-02 09:32:10 +03:00
|
|
|
switch (ch) {
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
case 'c':
|
1994-05-15 01:52:16 +04:00
|
|
|
if ((reps = atoi(optarg)) <= 0)
|
|
|
|
errx(1, "repetition count <= 0.");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
break;
|
1996-05-11 03:16:30 +04:00
|
|
|
case 'C':
|
|
|
|
todo |= SHOW_CPU;
|
|
|
|
break;
|
|
|
|
case 'd':
|
1998-08-25 12:05:47 +04:00
|
|
|
todo &= ~SHOW_STATS_ALL;
|
1996-05-11 03:16:30 +04:00
|
|
|
todo |= SHOW_STATS_1;
|
|
|
|
break;
|
|
|
|
case 'D':
|
1998-08-25 12:05:47 +04:00
|
|
|
todo &= ~SHOW_STATS_ALL;
|
1996-05-11 03:16:30 +04:00
|
|
|
todo |= SHOW_STATS_2;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
todo |= SHOW_TOTALS;
|
|
|
|
break;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
case 'M':
|
1994-05-15 01:52:16 +04:00
|
|
|
memf = optarg;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
break;
|
|
|
|
case 'N':
|
1994-05-15 01:52:16 +04:00
|
|
|
nlistf = optarg;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
break;
|
1996-05-11 03:16:30 +04:00
|
|
|
case 'T':
|
|
|
|
todo |= SHOW_TTY;
|
|
|
|
break;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
case 'w':
|
1994-05-15 01:52:16 +04:00
|
|
|
if ((interval = atoi(optarg)) <= 0)
|
|
|
|
errx(1, "interval <= 0.");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
break;
|
1998-08-25 12:05:47 +04:00
|
|
|
case 'x':
|
|
|
|
todo &= ~SHOW_STATS_ALL;
|
|
|
|
todo |= SHOW_STATS_X;
|
|
|
|
break;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
if (!ISSET(todo, SHOW_CPU | SHOW_TTY | SHOW_STATS_ALL))
|
1996-05-11 03:16:30 +04:00
|
|
|
todo |= SHOW_CPU | SHOW_TTY | SHOW_STATS_1;
|
1998-08-25 12:05:47 +04:00
|
|
|
if (ISSET(todo, SHOW_STATS_X)) {
|
|
|
|
todo &= ~(SHOW_CPU | SHOW_TTY | SHOW_STATS_ALL);
|
|
|
|
todo |= SHOW_STATS_X;
|
|
|
|
}
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2002-01-28 05:16:56 +03:00
|
|
|
dkinit(0);
|
1996-05-11 03:16:30 +04:00
|
|
|
dkreadstats();
|
2003-03-01 10:40:58 +03:00
|
|
|
ndrives = selectdrives(argc, argv);
|
|
|
|
if (ndrives == 0) {
|
|
|
|
/* No drives are selected. No need to show disk stats. */
|
|
|
|
todo &= ~SHOW_STATS_ALL;
|
|
|
|
if (todo == 0)
|
|
|
|
errx(1, "no drives");
|
|
|
|
}
|
|
|
|
if (ISSET(todo, SHOW_STATS_X))
|
|
|
|
lines = ndrives;
|
|
|
|
else
|
|
|
|
lines = 1;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
tv.tv_sec = interval;
|
2002-09-19 03:18:44 +04:00
|
|
|
tv.tv_nsec = 0;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
/* print a new header on sigcont */
|
|
|
|
(void)signal(SIGCONT, header);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
for (hdrcnt = 1;;) {
|
2003-03-01 10:40:58 +03:00
|
|
|
if ((hdrcnt -= lines) <= 0) {
|
1996-05-11 03:16:30 +04:00
|
|
|
header(0);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
hdrcnt = 20;
|
|
|
|
}
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
if (!ISSET(todo, SHOW_TOTALS))
|
|
|
|
dkswap();
|
|
|
|
display();
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
if (reps >= 0 && --reps <= 0)
|
|
|
|
break;
|
2002-09-19 03:18:44 +04:00
|
|
|
nanosleep(&tv, NULL);
|
1996-05-11 03:16:30 +04:00
|
|
|
dkreadstats();
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
header(int signo)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-10-17 13:03:53 +04:00
|
|
|
int i;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
/* Main Headers. */
|
|
|
|
if (ISSET(todo, SHOW_STATS_X)) {
|
|
|
|
if (ISSET(todo, SHOW_TOTALS)) {
|
2002-11-02 09:32:10 +03:00
|
|
|
(void)printf(
|
|
|
|
"device read KB/t xfr time MB/s");
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" write KB/t xfr time MB/s\n");
|
|
|
|
} else {
|
2002-11-02 09:32:10 +03:00
|
|
|
(void)printf(
|
|
|
|
"device read KB/t r/s time MB/s");
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" write KB/t w/s time MB/s\n");
|
|
|
|
}
|
1998-08-25 12:05:47 +04:00
|
|
|
return;
|
2002-11-01 15:47:55 +03:00
|
|
|
}
|
1998-08-25 12:05:47 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (ISSET(todo, SHOW_TTY))
|
|
|
|
(void)printf(" tty");
|
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_STATS_1))
|
1998-08-25 12:05:47 +04:00
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
|
|
|
if (cur.dk_select[i])
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %7.7s ", cur.dk_name[i]);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_STATS_2))
|
1998-08-25 12:05:47 +04:00
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
|
|
|
if (cur.dk_select[i])
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %7.7s ", cur.dk_name[i]);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_CPU))
|
|
|
|
(void)printf(" cpu");
|
1998-08-25 12:05:47 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
printf("\n");
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* Sub-Headers. */
|
1996-05-11 03:16:30 +04:00
|
|
|
if (ISSET(todo, SHOW_TTY))
|
|
|
|
printf(" tin tout");
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
if (ISSET(todo, SHOW_STATS_1)) {
|
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
|
|
|
if (cur.dk_select[i]) {
|
|
|
|
if (ISSET(todo, SHOW_TOTALS))
|
|
|
|
(void)printf(" KB/t xfr MB ");
|
|
|
|
else
|
|
|
|
(void)printf(" KB/t t/s MB/s ");
|
|
|
|
}
|
|
|
|
}
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_STATS_2))
|
1998-08-25 12:05:47 +04:00
|
|
|
for (i = 0; i < dk_ndrive; i++)
|
|
|
|
if (cur.dk_select[i])
|
2003-03-01 10:40:58 +03:00
|
|
|
(void)printf(" KB xfr time ");
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_CPU))
|
|
|
|
(void)printf(" us ni sy in id");
|
|
|
|
printf("\n");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
disk_stats(double etime)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-10-17 13:03:53 +04:00
|
|
|
int dn;
|
1996-05-11 03:16:30 +04:00
|
|
|
double atime, mbps;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
for (dn = 0; dn < dk_ndrive; ++dn) {
|
1996-05-11 03:16:30 +04:00
|
|
|
if (!cur.dk_select[dn])
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
continue;
|
1998-08-25 12:05:47 +04:00
|
|
|
/* average Kbytes per transfer. */
|
2002-11-01 15:47:55 +03:00
|
|
|
if (cur.dk_rxfer[dn] + cur.dk_wxfer[dn])
|
2002-11-02 09:35:30 +03:00
|
|
|
mbps = ((cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) /
|
|
|
|
1024.0) / (cur.dk_rxfer[dn] + cur.dk_wxfer[dn]);
|
1996-05-11 03:16:30 +04:00
|
|
|
else
|
|
|
|
mbps = 0.0;
|
2002-06-30 04:10:33 +04:00
|
|
|
(void)printf(" %5.2f", mbps);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* average transfers per second. */
|
2002-11-02 09:32:10 +03:00
|
|
|
(void)printf(" %3.0f",
|
2002-11-02 09:35:30 +03:00
|
|
|
(cur.dk_rxfer[dn] + cur.dk_wxfer[dn]) / etime);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* time busy in disk activity */
|
1996-05-11 03:16:30 +04:00
|
|
|
atime = (double)cur.dk_time[dn].tv_sec +
|
2002-11-02 09:32:10 +03:00
|
|
|
((double)cur.dk_time[dn].tv_usec / (double)1000000);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* Megabytes per second. */
|
1996-05-11 03:16:30 +04:00
|
|
|
if (atime != 0.0)
|
2002-11-01 15:47:55 +03:00
|
|
|
mbps = (cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) /
|
|
|
|
(double)(1024 * 1024);
|
2002-06-30 04:10:33 +04:00
|
|
|
else
|
1996-05-11 03:16:30 +04:00
|
|
|
mbps = 0;
|
|
|
|
(void)printf(" %4.2f ", mbps / etime);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
disk_stats2(double etime)
|
1996-05-11 03:16:30 +04:00
|
|
|
{
|
1997-10-17 13:03:53 +04:00
|
|
|
int dn;
|
1996-05-11 03:16:30 +04:00
|
|
|
double atime;
|
|
|
|
|
|
|
|
for (dn = 0; dn < dk_ndrive; ++dn) {
|
|
|
|
if (!cur.dk_select[dn])
|
|
|
|
continue;
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* average kbytes per second. */
|
2002-11-02 09:32:10 +03:00
|
|
|
(void)printf(" %4.0f",
|
2002-11-02 09:35:30 +03:00
|
|
|
(cur.dk_rbytes[dn] + cur.dk_wbytes[dn]) / 1024.0 / etime);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* average transfers per second. */
|
2002-11-02 09:32:10 +03:00
|
|
|
(void)printf(" %3.0f",
|
2002-11-02 09:35:30 +03:00
|
|
|
(cur.dk_rxfer[dn] + cur.dk_wxfer[dn]) / etime);
|
1996-05-11 03:16:30 +04:00
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
/* average time busy in disk activity */
|
1996-05-11 03:16:30 +04:00
|
|
|
atime = (double)cur.dk_time[dn].tv_sec +
|
2002-11-02 09:32:10 +03:00
|
|
|
((double)cur.dk_time[dn].tv_usec / (double)1000000);
|
1996-05-11 03:16:30 +04:00
|
|
|
(void)printf(" %4.2f ", atime / etime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
disk_statsx(double etime)
|
1998-08-25 12:05:47 +04:00
|
|
|
{
|
|
|
|
int dn;
|
|
|
|
double atime, kbps;
|
|
|
|
|
|
|
|
for (dn = 0; dn < dk_ndrive; ++dn) {
|
2003-03-01 08:38:11 +03:00
|
|
|
if (!cur.dk_select[dn])
|
|
|
|
continue;
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
(void)printf("%-8.8s", cur.dk_name[dn]);
|
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
/* average read Kbytes per transfer */
|
|
|
|
if (cur.dk_rxfer[dn])
|
2002-11-02 09:32:10 +03:00
|
|
|
kbps = (cur.dk_rbytes[dn] / 1024.0) / cur.dk_rxfer[dn];
|
1998-08-25 12:05:47 +04:00
|
|
|
else
|
|
|
|
kbps = 0.0;
|
2002-06-30 04:10:33 +04:00
|
|
|
(void)printf(" %8.2f", kbps);
|
1998-08-25 12:05:47 +04:00
|
|
|
|
2002-11-02 09:32:10 +03:00
|
|
|
/* average read transfers
|
|
|
|
(per second) */
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %6.0f", cur.dk_rxfer[dn] / etime);
|
1998-08-25 12:05:47 +04:00
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
/* time read busy in disk activity */
|
1998-08-25 12:05:47 +04:00
|
|
|
atime = (double)cur.dk_time[dn].tv_sec +
|
2002-11-02 09:32:10 +03:00
|
|
|
((double)cur.dk_time[dn].tv_usec / (double)1000000);
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %6.2f", atime / etime);
|
1998-08-25 12:05:47 +04:00
|
|
|
|
2002-11-02 09:32:10 +03:00
|
|
|
/* average read megabytes
|
|
|
|
(per second) */
|
1998-08-27 07:17:49 +04:00
|
|
|
(void)printf(" %8.2f",
|
2002-11-01 15:47:55 +03:00
|
|
|
cur.dk_rbytes[dn] / (1024.0 * 1024) / etime);
|
|
|
|
|
1998-08-25 12:05:47 +04:00
|
|
|
|
2002-11-01 15:47:55 +03:00
|
|
|
/* average write Kbytes per transfer */
|
|
|
|
if (cur.dk_wxfer[dn])
|
2002-11-02 09:32:10 +03:00
|
|
|
kbps = (cur.dk_wbytes[dn] / 1024.0) / cur.dk_wxfer[dn];
|
2002-11-01 15:47:55 +03:00
|
|
|
else
|
|
|
|
kbps = 0.0;
|
|
|
|
(void)printf(" %8.2f", kbps);
|
|
|
|
|
2002-11-02 09:32:10 +03:00
|
|
|
/* average write transfers
|
|
|
|
(per second) */
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %6.0f", cur.dk_wxfer[dn] / etime);
|
|
|
|
|
|
|
|
/* time write busy in disk activity */
|
|
|
|
atime = (double)cur.dk_time[dn].tv_sec +
|
2002-11-02 09:32:10 +03:00
|
|
|
((double)cur.dk_time[dn].tv_usec / (double)1000000);
|
2002-11-01 15:47:55 +03:00
|
|
|
(void)printf(" %6.2f", atime / etime);
|
|
|
|
|
2002-11-02 09:32:10 +03:00
|
|
|
/* average write megabytes
|
|
|
|
(per second) */
|
2003-03-01 08:38:11 +03:00
|
|
|
(void)printf(" %8.2f\n",
|
2002-11-01 15:47:55 +03:00
|
|
|
cur.dk_wbytes[dn] / (1024.0 * 1024) / etime);
|
1998-08-25 12:05:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
cpustats(void)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-10-17 13:03:53 +04:00
|
|
|
int state;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
double time;
|
|
|
|
|
|
|
|
time = 0;
|
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
|
|
|
time += cur.cp_time[state];
|
1996-05-11 03:16:30 +04:00
|
|
|
if (!time)
|
|
|
|
time = 1.0;
|
1998-08-25 12:05:47 +04:00
|
|
|
/* States are generally never 100% and can use %3.0f. */
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
2000-05-29 15:33:43 +04:00
|
|
|
printf(" %2.0f", 100. * cur.cp_time[state] / time);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
usage(void)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1998-07-05 10:20:05 +04:00
|
|
|
|
2002-11-02 09:32:10 +03:00
|
|
|
(void)fprintf(stderr, "usage: iostat [-CdDITx] [-c count] [-M core] "
|
|
|
|
"[-N system] [-w wait] [drives]\n");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
static void
|
2000-12-01 02:59:03 +03:00
|
|
|
display(void)
|
1996-05-11 03:16:30 +04:00
|
|
|
{
|
|
|
|
double etime;
|
|
|
|
|
|
|
|
/* Sum up the elapsed ticks. */
|
2002-06-30 04:10:33 +04:00
|
|
|
etime = cur.cp_etime;
|
1996-05-11 03:16:30 +04:00
|
|
|
|
2003-03-01 10:40:58 +03:00
|
|
|
/*
|
|
|
|
* If we're showing totals only, then don't divide by the
|
1996-05-11 03:16:30 +04:00
|
|
|
* system time.
|
|
|
|
*/
|
|
|
|
if (ISSET(todo, SHOW_TOTALS))
|
|
|
|
etime = 1.0;
|
|
|
|
|
2003-03-01 10:40:58 +03:00
|
|
|
if (ISSET(todo, SHOW_STATS_X)) {
|
|
|
|
disk_statsx(etime);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (ISSET(todo, SHOW_TTY))
|
|
|
|
printf("%4.0f %4.0f", cur.tk_nin / etime, cur.tk_nout / etime);
|
2002-06-30 04:10:33 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
if (ISSET(todo, SHOW_STATS_1))
|
|
|
|
disk_stats(etime);
|
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_STATS_2))
|
|
|
|
disk_stats2(etime);
|
|
|
|
|
|
|
|
if (ISSET(todo, SHOW_CPU))
|
|
|
|
cpustats();
|
|
|
|
|
2003-03-01 10:40:58 +03:00
|
|
|
(void)printf("\n");
|
|
|
|
|
|
|
|
out:
|
1996-05-11 03:16:30 +04:00
|
|
|
(void)fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2003-03-01 10:40:58 +03:00
|
|
|
static int
|
2000-12-01 02:59:03 +03:00
|
|
|
selectdrives(int argc, char *argv[])
|
1996-05-11 03:16:30 +04:00
|
|
|
{
|
2003-03-01 10:40:58 +03:00
|
|
|
int i, maxdrives, ndrives, tried;
|
1996-05-11 03:16:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose drives to be displayed. Priority goes to (in order) drives
|
|
|
|
* supplied as arguments and default drives. If everything isn't
|
|
|
|
* filled in and there are drives not taken care of, display the first
|
|
|
|
* few that fit.
|
|
|
|
*
|
|
|
|
* The backward compatibility #ifdefs permit the syntax:
|
|
|
|
* iostat [ drives ] [ interval [ count ] ]
|
|
|
|
*/
|
1999-09-13 20:56:35 +04:00
|
|
|
|
1996-05-11 03:16:30 +04:00
|
|
|
#define BACKWARD_COMPATIBILITY
|
2003-03-01 10:40:58 +03:00
|
|
|
for (tried = ndrives = 0; *argv; ++argv) {
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
1996-05-11 03:16:30 +04:00
|
|
|
if (isdigit(**argv))
|
|
|
|
break;
|
|
|
|
#endif
|
2003-03-01 10:40:58 +03:00
|
|
|
tried++;
|
2003-03-01 08:38:11 +03:00
|
|
|
for (i = 0; i < dk_ndrive; i++) {
|
2003-03-01 10:40:58 +03:00
|
|
|
if (strcmp(cur.dk_name[i], *argv))
|
2003-03-01 08:38:11 +03:00
|
|
|
continue;
|
|
|
|
cur.dk_select[i] = 1;
|
|
|
|
++ndrives;
|
|
|
|
}
|
1996-05-11 03:16:30 +04:00
|
|
|
}
|
2003-03-01 10:40:58 +03:00
|
|
|
|
|
|
|
if (ndrives == 0 && tried == 0) {
|
|
|
|
/*
|
|
|
|
* Pick up to 4 (or all if -x is given) drives
|
|
|
|
* if none specified.
|
|
|
|
*/
|
|
|
|
maxdrives = ISSET(todo, SHOW_STATS_X) ? dk_ndrive : 4;
|
|
|
|
for (i = 0; i < maxdrives; i++) {
|
|
|
|
cur.dk_select[i] = 1;
|
|
|
|
++ndrives;
|
|
|
|
if (!ISSET(todo, SHOW_STATS_X) && ndrives == 4)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
1996-05-11 03:16:30 +04:00
|
|
|
if (*argv) {
|
|
|
|
interval = atoi(*argv);
|
|
|
|
if (*++argv)
|
|
|
|
reps = atoi(*argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (interval) {
|
|
|
|
if (!reps)
|
|
|
|
reps = -1;
|
|
|
|
} else
|
|
|
|
if (reps)
|
|
|
|
interval = 1;
|
|
|
|
|
2003-03-01 10:40:58 +03:00
|
|
|
return (ndrives);
|
1996-05-11 03:16:30 +04:00
|
|
|
}
|