2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2001-08-23 03:19:54 +00:00
|
|
|
* Copyright (c) 1997, 1998, 2000, 2001 Kenneth D. Merry
|
1998-09-15 08:16:45 +00:00
|
|
|
* 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. 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 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 AUTHOR 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.
|
2000-01-24 22:08:19 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1998-09-15 08:16:45 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Parts of this program are derived from the original FreeBSD iostat
|
|
|
|
* program:
|
|
|
|
*/
|
1994-05-26 05:23:31 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1986, 1991, 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.
|
|
|
|
* 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.
|
|
|
|
*/
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* Ideas for the new iostat statistics output modes taken from the NetBSD
|
|
|
|
* version of iostat:
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
1998-09-15 08:16:45 +00:00
|
|
|
#include <sys/errno.h>
|
2003-02-16 16:01:52 +00:00
|
|
|
#include <sys/resource.h>
|
2001-08-04 18:30:54 +00:00
|
|
|
#include <sys/sysctl.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
2011-12-17 20:25:23 +00:00
|
|
|
#include <devstat.h>
|
|
|
|
#include <err.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <fcntl.h>
|
2011-12-17 20:25:23 +00:00
|
|
|
#include <inttypes.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <kvm.h>
|
2011-12-17 20:25:23 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
2002-08-18 17:35:55 +00:00
|
|
|
#include <nlist.h>
|
2015-12-09 18:07:26 +00:00
|
|
|
#include <signal.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-01-22 11:18:51 +00:00
|
|
|
#include <termios.h>
|
1994-05-26 05:23:31 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-02-18 20:08:01 +00:00
|
|
|
static struct nlist namelist[] = {
|
2013-11-25 22:55:47 +00:00
|
|
|
#define X_TTY_NIN 0
|
2016-02-18 20:08:01 +00:00
|
|
|
{ .n_name = "_tty_nin",
|
|
|
|
.n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
|
2013-11-25 22:55:47 +00:00
|
|
|
#define X_TTY_NOUT 1
|
2016-02-18 20:08:01 +00:00
|
|
|
{ .n_name = "_tty_nout",
|
|
|
|
.n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
|
2008-08-19 21:33:09 +00:00
|
|
|
#define X_BOOTTIME 2
|
2016-02-18 20:08:01 +00:00
|
|
|
{ .n_name = "_boottime",
|
|
|
|
.n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
|
2008-08-19 21:33:09 +00:00
|
|
|
#define X_END 2
|
2016-02-18 20:08:01 +00:00
|
|
|
{ .n_name = NULL,
|
|
|
|
.n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
|
1994-05-26 05:23:31 +00:00
|
|
|
};
|
|
|
|
|
2008-01-22 11:18:51 +00:00
|
|
|
#define IOSTAT_DEFAULT_ROWS 20 /* Traditional default `wrows' */
|
|
|
|
|
2016-02-18 20:08:01 +00:00
|
|
|
static struct statinfo cur, last;
|
|
|
|
static int num_devices;
|
|
|
|
static struct device_selection *dev_select;
|
|
|
|
static int maxshowdevs;
|
|
|
|
static volatile sig_atomic_t headercount;
|
|
|
|
static volatile sig_atomic_t wresized; /* Tty resized, when non-zero. */
|
|
|
|
static volatile sig_atomic_t alarm_rang;
|
|
|
|
static volatile sig_atomic_t return_requested;
|
|
|
|
static unsigned short wrows; /* Current number of tty rows. */
|
|
|
|
static int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0;
|
|
|
|
static int xflag = 0, zflag = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/* local function declarations */
|
|
|
|
static void usage(void);
|
2001-09-26 19:35:03 +00:00
|
|
|
static void needhdr(int signo);
|
2008-01-22 11:18:51 +00:00
|
|
|
static void needresize(int signo);
|
2015-12-09 18:07:26 +00:00
|
|
|
static void needreturn(int signo);
|
|
|
|
static void alarm_clock(int signo);
|
2008-01-22 11:18:51 +00:00
|
|
|
static void doresize(void);
|
2001-09-26 19:35:03 +00:00
|
|
|
static void phdr(void);
|
2001-08-23 03:19:54 +00:00
|
|
|
static void devstats(int perf_select, long double etime, int havelast);
|
1998-09-15 08:16:45 +00:00
|
|
|
static void cpustats(void);
|
2001-08-23 03:19:54 +00:00
|
|
|
static int readvar(kvm_t *kd, const char *name, int nlid, void *ptr,
|
|
|
|
size_t len);
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We also support the following 'traditional' syntax:
|
|
|
|
* iostat [drives] [wait [count]]
|
|
|
|
* This isn't mentioned in the man page, or the usage statement,
|
|
|
|
* but it is supported.
|
|
|
|
*/
|
2006-04-16 22:23:39 +00:00
|
|
|
fprintf(stderr, "usage: iostat [-CdhIKoTxz?] [-c count] [-M core]"
|
2000-01-24 22:08:19 +00:00
|
|
|
" [-n devs] [-N system]\n"
|
|
|
|
"\t [-t type,if,pass] [-w wait] [drives]\n");
|
1998-09-15 08:16:45 +00:00
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
int
|
1998-09-15 08:16:45 +00:00
|
|
|
main(int argc, char **argv)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2006-04-16 22:30:24 +00:00
|
|
|
int c, i;
|
1998-09-15 08:16:45 +00:00
|
|
|
int tflag = 0, hflag = 0, cflag = 0, wflag = 0, nflag = 0;
|
|
|
|
int count = 0, waittime = 0;
|
|
|
|
char *memf = NULL, *nlistf = NULL;
|
|
|
|
struct devstat_match *matches;
|
2015-12-09 18:07:26 +00:00
|
|
|
struct itimerval alarmspec;
|
1998-09-15 08:16:45 +00:00
|
|
|
int num_matches = 0;
|
2006-04-16 22:28:04 +00:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
2001-08-04 18:30:54 +00:00
|
|
|
kvm_t *kd = NULL;
|
1998-09-20 00:11:23 +00:00
|
|
|
long generation;
|
1998-09-15 08:16:45 +00:00
|
|
|
int num_devices_specified;
|
1998-09-20 00:11:23 +00:00
|
|
|
int num_selected, num_selections;
|
|
|
|
long select_generation;
|
1998-09-15 08:16:45 +00:00
|
|
|
char **specified_devices;
|
|
|
|
devstat_select_mode select_mode;
|
2010-05-21 17:10:52 +00:00
|
|
|
float f;
|
2001-08-23 03:19:54 +00:00
|
|
|
int havelast = 0;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
matches = NULL;
|
|
|
|
maxshowdevs = 3;
|
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:xz?")) != -1) {
|
1998-09-15 08:16:45 +00:00
|
|
|
switch(c) {
|
|
|
|
case 'c':
|
|
|
|
cflag++;
|
|
|
|
count = atoi(optarg);
|
|
|
|
if (count < 1)
|
|
|
|
errx(1, "count %d is < 1", count);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
Cflag++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
dflag++;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
hflag++;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
Iflag++;
|
|
|
|
break;
|
1998-09-16 23:14:47 +00:00
|
|
|
case 'K':
|
|
|
|
Kflag++;
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nflag++;
|
|
|
|
maxshowdevs = atoi(optarg);
|
|
|
|
if (maxshowdevs < 0)
|
2000-01-23 20:19:34 +00:00
|
|
|
errx(1, "number of devices %d is < 0",
|
1998-09-15 08:16:45 +00:00
|
|
|
maxshowdevs);
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
oflag++;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tflag++;
|
2006-04-16 22:28:04 +00:00
|
|
|
if (devstat_buildmatch(optarg, &matches,
|
2001-08-04 18:30:54 +00:00
|
|
|
&num_matches) != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
Tflag++;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
wflag++;
|
2010-05-21 17:10:52 +00:00
|
|
|
f = atof(optarg);
|
|
|
|
waittime = f * 1000;
|
1998-09-15 08:16:45 +00:00
|
|
|
if (waittime < 1)
|
2010-05-21 17:10:52 +00:00
|
|
|
errx(1, "wait time is < 1ms");
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
2006-04-16 22:23:39 +00:00
|
|
|
case 'x':
|
|
|
|
xflag++;
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
zflag++;
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
default:
|
|
|
|
usage();
|
2000-01-24 22:08:19 +00:00
|
|
|
exit(1);
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
}
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (nlistf != NULL || memf != NULL) {
|
2001-08-04 18:30:54 +00:00
|
|
|
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
2006-04-16 22:28:04 +00:00
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (kd == NULL)
|
2001-08-04 18:30:54 +00:00
|
|
|
errx(1, "kvm_openfiles: %s", errbuf);
|
2006-04-16 22:28:04 +00:00
|
|
|
|
2001-08-04 18:30:54 +00:00
|
|
|
if (kvm_nlist(kd, namelist) == -1)
|
|
|
|
errx(1, "kvm_nlist: %s", kvm_geterr(kd));
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* Make sure that the userland devstat version matches the kernel
|
2006-04-16 22:28:04 +00:00
|
|
|
* devstat version. If not, exit and print a message informing
|
1998-09-15 08:16:45 +00:00
|
|
|
* the user of his mistake.
|
|
|
|
*/
|
2001-08-04 18:30:54 +00:00
|
|
|
if (devstat_checkversion(kd) < 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
/*
|
|
|
|
* Make sure Tflag and/or Cflag are set if dflag == 0. If dflag is
|
|
|
|
* greater than 0, they may be 0 or non-zero.
|
|
|
|
*/
|
2006-04-16 22:23:39 +00:00
|
|
|
if (dflag == 0 && xflag == 0) {
|
2001-08-23 03:19:54 +00:00
|
|
|
Cflag = 1;
|
|
|
|
Tflag = 1;
|
|
|
|
}
|
|
|
|
|
2007-08-03 15:45:55 +00:00
|
|
|
/* find out how many devices we have */
|
|
|
|
if ((num_devices = devstat_getnumdevs(kd)) < 0)
|
|
|
|
err(1, "can't get number of devices");
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* Figure out how many devices we should display.
|
|
|
|
*/
|
|
|
|
if (nflag == 0) {
|
2007-08-03 15:45:55 +00:00
|
|
|
if (xflag > 0)
|
|
|
|
maxshowdevs = num_devices;
|
|
|
|
else if (oflag > 0) {
|
1998-09-15 08:16:45 +00:00
|
|
|
if ((dflag > 0) && (Cflag == 0) && (Tflag == 0))
|
|
|
|
maxshowdevs = 5;
|
|
|
|
else if ((dflag > 0) && (Tflag > 0) && (Cflag == 0))
|
|
|
|
maxshowdevs = 5;
|
|
|
|
else
|
|
|
|
maxshowdevs = 4;
|
|
|
|
} else {
|
|
|
|
if ((dflag > 0) && (Cflag == 0))
|
2006-04-16 22:28:04 +00:00
|
|
|
maxshowdevs = 4;
|
1998-09-15 08:16:45 +00:00
|
|
|
else
|
|
|
|
maxshowdevs = 3;
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
2009-05-21 23:00:20 +00:00
|
|
|
cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
|
2001-08-23 03:19:54 +00:00
|
|
|
if (cur.dinfo == NULL)
|
2009-05-21 23:00:20 +00:00
|
|
|
err(1, "calloc failed");
|
2001-08-23 03:19:54 +00:00
|
|
|
|
2009-05-21 23:00:20 +00:00
|
|
|
last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo));
|
2001-08-23 03:19:54 +00:00
|
|
|
if (last.dinfo == NULL)
|
2009-05-21 23:00:20 +00:00
|
|
|
err(1, "calloc failed");
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab all the devices. We don't look to see if the list has
|
|
|
|
* changed here, since it almost certainly has. We only look for
|
|
|
|
* errors.
|
|
|
|
*/
|
2001-08-04 18:30:54 +00:00
|
|
|
if (devstat_getdevs(kd, &cur) == -1)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
|
|
|
/*
|
1998-09-15 08:16:45 +00:00
|
|
|
* If the user specified any devices on the command line, see if
|
|
|
|
* they are in the list of devices we have now.
|
1994-05-26 05:23:31 +00:00
|
|
|
*/
|
2001-08-23 03:19:54 +00:00
|
|
|
specified_devices = (char **)malloc(sizeof(char *));
|
|
|
|
if (specified_devices == NULL)
|
|
|
|
err(1, "malloc failed");
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
for (num_devices_specified = 0; *argv; ++argv) {
|
1994-05-26 05:23:31 +00:00
|
|
|
if (isdigit(**argv))
|
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
num_devices_specified++;
|
|
|
|
specified_devices = (char **)realloc(specified_devices,
|
|
|
|
sizeof(char *) *
|
|
|
|
num_devices_specified);
|
2001-08-23 03:19:54 +00:00
|
|
|
if (specified_devices == NULL)
|
|
|
|
err(1, "realloc failed");
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
specified_devices[num_devices_specified - 1] = *argv;
|
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1998-09-16 18:03:44 +00:00
|
|
|
if (nflag == 0 && maxshowdevs < num_devices_specified)
|
|
|
|
maxshowdevs = num_devices_specified;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
dev_select = NULL;
|
|
|
|
|
|
|
|
if ((num_devices_specified == 0) && (num_matches == 0))
|
|
|
|
select_mode = DS_SELECT_ADD;
|
|
|
|
else
|
|
|
|
select_mode = DS_SELECT_ONLY;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, selectdevs will almost surely indicate that the
|
|
|
|
* device list has changed, so we don't look for return values of 0
|
|
|
|
* or 1. If we get back -1, though, there is an error.
|
|
|
|
*/
|
2001-08-04 18:30:54 +00:00
|
|
|
if (devstat_selectdevs(&dev_select, &num_selected,
|
|
|
|
&num_selections, &select_generation, generation,
|
|
|
|
cur.dinfo->devices, num_devices, matches,
|
|
|
|
num_matches, specified_devices,
|
|
|
|
num_devices_specified, select_mode, maxshowdevs,
|
|
|
|
hflag) == -1)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for the traditional wait time and count arguments.
|
|
|
|
*/
|
1994-05-26 05:23:31 +00:00
|
|
|
if (*argv) {
|
2010-05-21 17:10:52 +00:00
|
|
|
f = atof(*argv);
|
|
|
|
waittime = f * 1000;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/* Let the user know he goofed, but keep going anyway */
|
2006-04-16 22:28:04 +00:00
|
|
|
if (wflag != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
warnx("discarding previous wait interval, using"
|
2010-05-21 17:10:52 +00:00
|
|
|
" %g instead", waittime / 1000.0);
|
1998-09-15 08:16:45 +00:00
|
|
|
wflag++;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
if (*++argv) {
|
|
|
|
count = atoi(*argv);
|
|
|
|
if (cflag != 0)
|
|
|
|
warnx("discarding previous count, using %d"
|
|
|
|
" instead", count);
|
|
|
|
cflag++;
|
|
|
|
} else
|
|
|
|
count = -1;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* If the user specified a count, but not an interval, we default
|
|
|
|
* to an interval of 1 second.
|
|
|
|
*/
|
|
|
|
if ((wflag == 0) && (cflag > 0))
|
2010-05-21 17:10:52 +00:00
|
|
|
waittime = 1 * 1000;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user specified a wait time, but not a count, we want to
|
|
|
|
* go on ad infinitum. This can be redundant if the user uses the
|
|
|
|
* traditional method of specifying the wait, since in that case we
|
|
|
|
* already set count = -1 above. Oh well.
|
|
|
|
*/
|
|
|
|
if ((wflag > 0) && (cflag == 0))
|
|
|
|
count = -1;
|
|
|
|
|
2008-08-19 20:33:59 +00:00
|
|
|
bzero(cur.cp_time, sizeof(cur.cp_time));
|
2001-08-23 03:19:54 +00:00
|
|
|
cur.tk_nout = 0;
|
|
|
|
cur.tk_nin = 0;
|
|
|
|
|
|
|
|
/*
|
2006-04-16 22:28:04 +00:00
|
|
|
* Set the snap time to the system boot time (ie: zero), so the
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
* stats are calculated since system boot.
|
2001-08-23 03:19:54 +00:00
|
|
|
*/
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
cur.snap_time = 0;
|
2001-08-23 03:19:54 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
/*
|
|
|
|
* If the user stops the program (control-Z) and then resumes it,
|
|
|
|
* print out the header again.
|
|
|
|
*/
|
2001-09-26 19:35:03 +00:00
|
|
|
(void)signal(SIGCONT, needhdr);
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2008-01-22 11:18:51 +00:00
|
|
|
/*
|
|
|
|
* If our standard output is a tty, then install a SIGWINCH handler
|
|
|
|
* and set wresized so that our first iteration through the main
|
|
|
|
* iostat loop will peek at the terminal's current rows to find out
|
|
|
|
* how many lines can fit in a screenful of output.
|
|
|
|
*/
|
|
|
|
if (isatty(fileno(stdout)) != 0) {
|
|
|
|
wresized = 1;
|
|
|
|
(void)signal(SIGWINCH, needresize);
|
|
|
|
} else {
|
|
|
|
wresized = 0;
|
|
|
|
wrows = IOSTAT_DEFAULT_ROWS;
|
|
|
|
}
|
|
|
|
|
2015-12-09 18:07:26 +00:00
|
|
|
/*
|
|
|
|
* Register a SIGINT handler so that we can print out final statistics
|
|
|
|
* when we get that signal
|
|
|
|
*/
|
|
|
|
(void)signal(SIGINT, needreturn);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a SIGALRM handler to implement sleeps if the user uses the
|
|
|
|
* -c or -w options
|
|
|
|
*/
|
|
|
|
(void)signal(SIGALRM, alarm_clock);
|
|
|
|
alarmspec.it_interval.tv_sec = waittime / 1000;
|
|
|
|
alarmspec.it_interval.tv_usec = 1000 * (waittime % 1000);
|
|
|
|
alarmspec.it_value.tv_sec = waittime / 1000;
|
|
|
|
alarmspec.it_value.tv_usec = 1000 * (waittime % 1000);
|
|
|
|
setitimer(ITIMER_REAL, &alarmspec, NULL);
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
for (headercount = 1;;) {
|
|
|
|
struct devinfo *tmp_dinfo;
|
|
|
|
long tmp;
|
2001-08-23 03:19:54 +00:00
|
|
|
long double etime;
|
2015-12-09 18:07:26 +00:00
|
|
|
sigset_t sigmask, oldsigmask;
|
2001-08-23 03:19:54 +00:00
|
|
|
|
|
|
|
if (Tflag > 0) {
|
2013-11-25 22:55:47 +00:00
|
|
|
if ((readvar(kd, "kern.tty_nin", X_TTY_NIN, &cur.tk_nin,
|
2001-08-23 03:19:54 +00:00
|
|
|
sizeof(cur.tk_nin)) != 0)
|
2013-11-25 22:55:47 +00:00
|
|
|
|| (readvar(kd, "kern.tty_nout", X_TTY_NOUT,
|
2001-08-23 03:19:54 +00:00
|
|
|
&cur.tk_nout, sizeof(cur.tk_nout))!= 0)) {
|
|
|
|
Tflag = 0;
|
|
|
|
warnx("disabling TTY statistics");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cflag > 0) {
|
2008-08-19 21:33:09 +00:00
|
|
|
if (kd == NULL) {
|
|
|
|
if (readvar(kd, "kern.cp_time", 0,
|
|
|
|
&cur.cp_time, sizeof(cur.cp_time)) != 0)
|
|
|
|
Cflag = 0;
|
|
|
|
} else {
|
|
|
|
if (kvm_getcptime(kd, cur.cp_time) < 0) {
|
|
|
|
warnx("kvm_getcptime: %s",
|
|
|
|
kvm_geterr(kd));
|
|
|
|
Cflag = 0;
|
|
|
|
}
|
2001-08-23 03:19:54 +00:00
|
|
|
}
|
2008-08-19 21:33:09 +00:00
|
|
|
if (Cflag == 0)
|
|
|
|
warnx("disabling CPU time statistics");
|
2001-08-23 03:19:54 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
if (!--headercount) {
|
2001-09-26 19:35:03 +00:00
|
|
|
phdr();
|
2008-01-22 11:18:51 +00:00
|
|
|
if (wresized != 0)
|
|
|
|
doresize();
|
|
|
|
headercount = wrows;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
tmp_dinfo = last.dinfo;
|
|
|
|
last.dinfo = cur.dinfo;
|
|
|
|
cur.dinfo = tmp_dinfo;
|
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
last.snap_time = cur.snap_time;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Here what we want to do is refresh our device stats.
|
2001-08-04 18:30:54 +00:00
|
|
|
* devstat_getdevs() returns 1 when the device list has changed.
|
1998-09-15 08:16:45 +00:00
|
|
|
* If the device list has changed, we want to go through
|
|
|
|
* the selection process again, in case a device that we
|
|
|
|
* were previously displaying has gone away.
|
|
|
|
*/
|
2001-08-04 18:30:54 +00:00
|
|
|
switch (devstat_getdevs(kd, &cur)) {
|
1998-09-15 08:16:45 +00:00
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1: {
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
num_devices = cur.dinfo->numdevs;
|
|
|
|
generation = cur.dinfo->generation;
|
2001-08-04 18:30:54 +00:00
|
|
|
retval = devstat_selectdevs(&dev_select, &num_selected,
|
|
|
|
&num_selections,
|
|
|
|
&select_generation,
|
|
|
|
generation,
|
|
|
|
cur.dinfo->devices,
|
|
|
|
num_devices, matches,
|
|
|
|
num_matches,
|
|
|
|
specified_devices,
|
|
|
|
num_devices_specified,
|
|
|
|
select_mode, maxshowdevs,
|
|
|
|
hflag);
|
1998-09-15 08:16:45 +00:00
|
|
|
switch(retval) {
|
|
|
|
case -1:
|
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1:
|
2001-09-26 19:35:03 +00:00
|
|
|
phdr();
|
2008-01-22 11:18:51 +00:00
|
|
|
if (wresized != 0)
|
|
|
|
doresize();
|
|
|
|
headercount = wrows;
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only want to re-select devices if we're in 'top'
|
|
|
|
* mode. This is the only mode where the devices selected
|
|
|
|
* could actually change.
|
|
|
|
*/
|
|
|
|
if (hflag > 0) {
|
|
|
|
int retval;
|
2001-08-04 18:30:54 +00:00
|
|
|
retval = devstat_selectdevs(&dev_select, &num_selected,
|
|
|
|
&num_selections,
|
|
|
|
&select_generation,
|
|
|
|
generation,
|
|
|
|
cur.dinfo->devices,
|
|
|
|
num_devices, matches,
|
|
|
|
num_matches,
|
|
|
|
specified_devices,
|
|
|
|
num_devices_specified,
|
|
|
|
select_mode, maxshowdevs,
|
|
|
|
hflag);
|
1998-09-15 08:16:45 +00:00
|
|
|
switch(retval) {
|
|
|
|
case -1:
|
|
|
|
errx(1,"%s", devstat_errbuf);
|
|
|
|
break;
|
|
|
|
case 1:
|
2001-09-26 19:35:03 +00:00
|
|
|
phdr();
|
2008-01-22 11:18:51 +00:00
|
|
|
if (wresized != 0)
|
|
|
|
doresize();
|
|
|
|
headercount = wrows;
|
1998-09-15 08:16:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (Tflag > 0) {
|
|
|
|
tmp = cur.tk_nin;
|
|
|
|
cur.tk_nin -= last.tk_nin;
|
|
|
|
last.tk_nin = tmp;
|
|
|
|
tmp = cur.tk_nout;
|
|
|
|
cur.tk_nout -= last.tk_nout;
|
|
|
|
last.tk_nout = tmp;
|
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
etime = cur.snap_time - last.snap_time;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (etime == 0.0)
|
|
|
|
etime = 1.0;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
for (i = 0; i < CPUSTATES; i++) {
|
2001-08-23 03:19:54 +00:00
|
|
|
tmp = cur.cp_time[i];
|
|
|
|
cur.cp_time[i] -= last.cp_time[i];
|
|
|
|
last.cp_time[i] = tmp;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2001-08-23 03:19:54 +00:00
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
if (xflag == 0 && Tflag > 0)
|
2009-08-15 17:57:21 +00:00
|
|
|
printf("%4.0Lf %5.0Lf", cur.tk_nin / etime,
|
2006-04-16 22:23:39 +00:00
|
|
|
cur.tk_nout / etime);
|
2001-08-23 03:19:54 +00:00
|
|
|
|
2001-08-04 18:30:54 +00:00
|
|
|
devstats(hflag, etime, havelast);
|
2001-08-23 03:19:54 +00:00
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
if (xflag == 0) {
|
|
|
|
if (Cflag > 0)
|
|
|
|
cpustats();
|
2001-08-23 03:19:54 +00:00
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
fflush(stdout);
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2015-12-09 18:07:26 +00:00
|
|
|
if ((count >= 0 && --count <= 0) || return_requested)
|
1994-05-26 05:23:31 +00:00
|
|
|
break;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
2015-12-09 18:07:26 +00:00
|
|
|
/*
|
|
|
|
* Use sigsuspend to safely sleep until either signal is
|
|
|
|
* received
|
|
|
|
*/
|
|
|
|
alarm_rang = 0;
|
|
|
|
sigemptyset(&sigmask);
|
|
|
|
sigaddset(&sigmask, SIGINT);
|
|
|
|
sigaddset(&sigmask, SIGALRM);
|
|
|
|
sigprocmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
|
|
|
while (! (alarm_rang || return_requested) ) {
|
|
|
|
sigsuspend(&oldsigmask);
|
|
|
|
}
|
|
|
|
sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
|
|
|
|
|
2001-08-04 18:30:54 +00:00
|
|
|
havelast = 1;
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2001-09-26 19:35:03 +00:00
|
|
|
/*
|
|
|
|
* Force a header to be prepended to the next output.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-18 20:08:01 +00:00
|
|
|
needhdr(int signo __unused)
|
2001-09-01 07:40:19 +00:00
|
|
|
{
|
2006-04-16 22:28:04 +00:00
|
|
|
|
|
|
|
headercount = 1;
|
2001-09-01 07:40:19 +00:00
|
|
|
}
|
|
|
|
|
2008-01-22 11:18:51 +00:00
|
|
|
/*
|
|
|
|
* When the terminal is resized, force an update of the maximum number of rows
|
|
|
|
* printed between each header repetition. Then force a new header to be
|
|
|
|
* prepended to the next output.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-18 20:08:01 +00:00
|
|
|
needresize(int signo __unused)
|
2008-01-22 11:18:51 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
wresized = 1;
|
|
|
|
headercount = 1;
|
|
|
|
}
|
|
|
|
|
2015-12-09 18:07:26 +00:00
|
|
|
/*
|
|
|
|
* Record the alarm so the main loop can break its sleep
|
|
|
|
*/
|
|
|
|
void
|
2016-02-18 20:08:01 +00:00
|
|
|
alarm_clock(int signo __unused)
|
2015-12-09 18:07:26 +00:00
|
|
|
{
|
|
|
|
alarm_rang = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request that the main loop exit soon
|
|
|
|
*/
|
|
|
|
void
|
2016-02-18 20:08:01 +00:00
|
|
|
needreturn(int signo __unused)
|
2015-12-09 18:07:26 +00:00
|
|
|
{
|
|
|
|
return_requested = 1;
|
|
|
|
}
|
|
|
|
|
2008-01-22 11:18:51 +00:00
|
|
|
/*
|
|
|
|
* Update the global `wrows' count of terminal rows.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doresize(void)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct winsize w;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
status = ioctl(fileno(stdout), TIOCGWINSZ, &w);
|
|
|
|
if (status == -1 && errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else if (status == -1)
|
|
|
|
err(1, "ioctl");
|
|
|
|
if (w.ws_row > 3)
|
|
|
|
wrows = w.ws_row - 3;
|
|
|
|
else
|
|
|
|
wrows = IOSTAT_DEFAULT_ROWS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inhibit doresize() calls until we are rescheduled by SIGWINCH.
|
|
|
|
*/
|
|
|
|
wresized = 0;
|
|
|
|
}
|
|
|
|
|
2001-09-01 07:40:19 +00:00
|
|
|
static void
|
2001-09-26 19:35:03 +00:00
|
|
|
phdr(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2006-04-16 22:30:24 +00:00
|
|
|
int i, printed;
|
2008-09-11 09:55:54 +00:00
|
|
|
char devbuf[256];
|
2006-04-16 22:28:04 +00:00
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
/*
|
|
|
|
* If xflag is set, we need a per-loop header, not a page header, so
|
|
|
|
* just return. We'll print the header in devstats().
|
|
|
|
*/
|
|
|
|
if (xflag > 0)
|
|
|
|
return;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (Tflag > 0)
|
2009-08-15 17:57:21 +00:00
|
|
|
(void)printf(" tty");
|
1998-09-15 08:16:45 +00:00
|
|
|
for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){
|
|
|
|
int di;
|
|
|
|
if ((dev_select[i].selected != 0)
|
|
|
|
&& (dev_select[i].selected <= maxshowdevs)) {
|
|
|
|
di = dev_select[i].position;
|
2008-09-11 09:55:54 +00:00
|
|
|
snprintf(devbuf, sizeof(devbuf), "%s%d",
|
1998-09-15 08:16:45 +00:00
|
|
|
cur.dinfo->devices[di].device_name,
|
|
|
|
cur.dinfo->devices[di].unit_number);
|
2008-09-11 09:55:54 +00:00
|
|
|
if (oflag > 0)
|
|
|
|
(void)printf("%13.6s ", devbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
else
|
2008-09-11 09:55:54 +00:00
|
|
|
printf("%16.6s ", devbuf);
|
1998-09-15 08:16:45 +00:00
|
|
|
printed++;
|
|
|
|
}
|
|
|
|
}
|
2001-08-23 03:19:54 +00:00
|
|
|
if (Cflag > 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
(void)printf(" cpu\n");
|
|
|
|
else
|
|
|
|
(void)printf("\n");
|
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (Tflag > 0)
|
2009-08-15 17:57:21 +00:00
|
|
|
(void)printf(" tin tout");
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
for (i=0, printed = 0;(i < num_devices) && (printed < maxshowdevs);i++){
|
|
|
|
if ((dev_select[i].selected != 0)
|
|
|
|
&& (dev_select[i].selected <= maxshowdevs)) {
|
1998-09-16 18:03:44 +00:00
|
|
|
if (oflag > 0) {
|
1998-09-15 08:16:45 +00:00
|
|
|
if (Iflag == 0)
|
|
|
|
(void)printf(" sps tps msps ");
|
|
|
|
else
|
|
|
|
(void)printf(" blk xfr msps ");
|
1998-09-16 18:03:44 +00:00
|
|
|
} else {
|
1998-09-15 08:16:45 +00:00
|
|
|
if (Iflag == 0)
|
|
|
|
printf(" KB/t tps MB/s ");
|
|
|
|
else
|
|
|
|
printf(" KB/t xfrs MB ");
|
1998-09-16 18:03:44 +00:00
|
|
|
}
|
1998-09-15 08:16:45 +00:00
|
|
|
printed++;
|
|
|
|
}
|
|
|
|
}
|
2001-08-23 03:19:54 +00:00
|
|
|
if (Cflag > 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
(void)printf(" us ni sy in id\n");
|
|
|
|
else
|
|
|
|
printf("\n");
|
2001-09-26 19:35:03 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
static void
|
2001-08-23 03:19:54 +00:00
|
|
|
devstats(int perf_select, long double etime, int havelast)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2006-04-16 22:30:24 +00:00
|
|
|
int dn;
|
2015-01-23 15:55:03 +00:00
|
|
|
long double transfers_per_second, transfers_per_second_read;
|
|
|
|
long double transfers_per_second_write;
|
|
|
|
long double kb_per_transfer, mb_per_second, mb_per_second_read;
|
|
|
|
long double mb_per_second_write;
|
1998-09-15 08:16:45 +00:00
|
|
|
u_int64_t total_bytes, total_transfers, total_blocks;
|
2007-05-12 09:28:34 +00:00
|
|
|
u_int64_t total_bytes_read, total_transfers_read;
|
|
|
|
u_int64_t total_bytes_write, total_transfers_write;
|
2012-12-15 18:21:09 +00:00
|
|
|
long double busy_pct, busy_time;
|
2006-04-16 22:23:39 +00:00
|
|
|
u_int64_t queue_len;
|
2015-01-23 15:55:03 +00:00
|
|
|
long double total_mb, blocks_per_second, total_duration;
|
|
|
|
long double ms_per_other, ms_per_read, ms_per_write, ms_per_transaction;
|
2006-04-16 22:23:39 +00:00
|
|
|
int firstline = 1;
|
2016-02-22 21:40:53 +00:00
|
|
|
char *devicename;
|
2006-04-16 22:23:39 +00:00
|
|
|
|
|
|
|
if (xflag > 0) {
|
|
|
|
printf(" extended device statistics ");
|
|
|
|
if (Tflag > 0)
|
2009-08-15 17:57:21 +00:00
|
|
|
printf(" tty ");
|
2006-04-16 22:23:39 +00:00
|
|
|
if (Cflag > 0)
|
|
|
|
printf(" cpu ");
|
|
|
|
printf("\n");
|
2012-12-15 18:21:09 +00:00
|
|
|
if (Iflag == 0) {
|
2016-09-21 11:22:19 +00:00
|
|
|
printf("device r/s w/s kr/s kw/s "
|
2015-01-23 15:55:03 +00:00
|
|
|
" ms/r ms/w ms/o ms/t qlen %%b ");
|
2012-12-15 18:21:09 +00:00
|
|
|
} else {
|
|
|
|
printf("device r/i w/i kr/i"
|
|
|
|
" kw/i qlen tsvc_t/i sb/i ");
|
|
|
|
}
|
2006-04-16 22:23:39 +00:00
|
|
|
if (Tflag > 0)
|
2009-08-15 17:57:21 +00:00
|
|
|
printf("tin tout ");
|
2006-04-16 22:23:39 +00:00
|
|
|
if (Cflag > 0)
|
|
|
|
printf("us ni sy in id ");
|
|
|
|
printf("\n");
|
|
|
|
}
|
2006-04-16 22:28:04 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
for (dn = 0; dn < num_devices; dn++) {
|
|
|
|
int di;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
if (((perf_select == 0) && (dev_select[dn].selected == 0))
|
|
|
|
|| (dev_select[dn].selected > maxshowdevs))
|
1994-05-26 05:23:31 +00:00
|
|
|
continue;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
di = dev_select[dn].position;
|
|
|
|
|
2001-08-04 18:30:54 +00:00
|
|
|
if (devstat_compute_statistics(&cur.dinfo->devices[di],
|
2001-08-23 03:19:54 +00:00
|
|
|
havelast ? &last.dinfo->devices[di] : NULL, etime,
|
2001-08-04 18:30:54 +00:00
|
|
|
DSM_TOTAL_BYTES, &total_bytes,
|
2007-05-12 09:28:34 +00:00
|
|
|
DSM_TOTAL_BYTES_READ, &total_bytes_read,
|
|
|
|
DSM_TOTAL_BYTES_WRITE, &total_bytes_write,
|
2001-08-04 18:30:54 +00:00
|
|
|
DSM_TOTAL_TRANSFERS, &total_transfers,
|
2007-05-12 09:28:34 +00:00
|
|
|
DSM_TOTAL_TRANSFERS_READ, &total_transfers_read,
|
|
|
|
DSM_TOTAL_TRANSFERS_WRITE, &total_transfers_write,
|
2001-08-04 18:30:54 +00:00
|
|
|
DSM_TOTAL_BLOCKS, &total_blocks,
|
|
|
|
DSM_KB_PER_TRANSFER, &kb_per_transfer,
|
|
|
|
DSM_TRANSFERS_PER_SECOND, &transfers_per_second,
|
2006-04-16 22:23:39 +00:00
|
|
|
DSM_TRANSFERS_PER_SECOND_READ, &transfers_per_second_read,
|
|
|
|
DSM_TRANSFERS_PER_SECOND_WRITE, &transfers_per_second_write,
|
2006-04-16 22:28:04 +00:00
|
|
|
DSM_MB_PER_SECOND, &mb_per_second,
|
|
|
|
DSM_MB_PER_SECOND_READ, &mb_per_second_read,
|
|
|
|
DSM_MB_PER_SECOND_WRITE, &mb_per_second_write,
|
2001-08-04 18:30:54 +00:00
|
|
|
DSM_BLOCKS_PER_SECOND, &blocks_per_second,
|
|
|
|
DSM_MS_PER_TRANSACTION, &ms_per_transaction,
|
2015-01-23 15:55:03 +00:00
|
|
|
DSM_MS_PER_TRANSACTION_READ, &ms_per_read,
|
|
|
|
DSM_MS_PER_TRANSACTION_WRITE, &ms_per_write,
|
|
|
|
DSM_MS_PER_TRANSACTION_OTHER, &ms_per_other,
|
2006-04-16 22:23:39 +00:00
|
|
|
DSM_BUSY_PCT, &busy_pct,
|
|
|
|
DSM_QUEUE_LENGTH, &queue_len,
|
2012-12-15 18:21:09 +00:00
|
|
|
DSM_TOTAL_DURATION, &total_duration,
|
|
|
|
DSM_TOTAL_BUSY_TIME, &busy_time,
|
2001-08-04 18:30:54 +00:00
|
|
|
DSM_NONE) != 0)
|
1998-09-15 08:16:45 +00:00
|
|
|
errx(1, "%s", devstat_errbuf);
|
|
|
|
|
|
|
|
if (perf_select != 0) {
|
|
|
|
dev_select[dn].bytes = total_bytes;
|
|
|
|
if ((dev_select[dn].selected == 0)
|
|
|
|
|| (dev_select[dn].selected > maxshowdevs))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
if (Kflag > 0 || xflag > 0) {
|
1998-09-16 18:03:44 +00:00
|
|
|
int block_size = cur.dinfo->devices[di].block_size;
|
1998-09-16 23:14:47 +00:00
|
|
|
total_blocks = total_blocks * (block_size ?
|
|
|
|
block_size : 512) / 1024;
|
1998-09-16 18:03:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-16 22:23:39 +00:00
|
|
|
if (xflag > 0) {
|
2016-02-22 21:40:53 +00:00
|
|
|
if (asprintf(&devicename, "%s%d",
|
2006-04-16 22:23:39 +00:00
|
|
|
cur.dinfo->devices[di].device_name,
|
2008-01-12 20:57:19 +00:00
|
|
|
cur.dinfo->devices[di].unit_number) == -1)
|
|
|
|
err(1, "asprintf");
|
2006-04-16 22:23:39 +00:00
|
|
|
/*
|
|
|
|
* If zflag is set, skip any devices with zero I/O.
|
|
|
|
*/
|
|
|
|
if (zflag == 0 || transfers_per_second_read > 0.05 ||
|
|
|
|
transfers_per_second_write > 0.05 ||
|
|
|
|
mb_per_second_read > ((long double).0005)/1024 ||
|
|
|
|
mb_per_second_write > ((long double).0005)/1024 ||
|
|
|
|
busy_pct > 0.5) {
|
2007-05-12 09:28:34 +00:00
|
|
|
if (Iflag == 0)
|
2016-09-21 11:22:19 +00:00
|
|
|
printf("%-8.8s %7d %7d %8.1Lf "
|
2015-01-23 15:55:03 +00:00
|
|
|
"%8.1Lf %5d %5d %5d %5d "
|
|
|
|
"%4" PRIu64 " %3.0Lf ",
|
2016-02-22 21:40:53 +00:00
|
|
|
devicename,
|
2015-01-23 15:55:03 +00:00
|
|
|
(int)transfers_per_second_read,
|
|
|
|
(int)transfers_per_second_write,
|
2007-05-12 09:28:34 +00:00
|
|
|
mb_per_second_read * 1024,
|
2007-05-12 16:42:01 +00:00
|
|
|
mb_per_second_write * 1024,
|
2015-01-23 15:55:03 +00:00
|
|
|
(int)ms_per_read, (int)ms_per_write,
|
|
|
|
(int)ms_per_other,
|
|
|
|
(int)ms_per_transaction,
|
|
|
|
queue_len, busy_pct);
|
2007-05-12 09:28:34 +00:00
|
|
|
else
|
2012-12-15 18:21:09 +00:00
|
|
|
printf("%-8.8s %11.1Lf %11.1Lf "
|
|
|
|
"%12.1Lf %12.1Lf %4" PRIu64
|
|
|
|
" %10.1Lf %9.1Lf ",
|
2016-02-22 21:40:53 +00:00
|
|
|
devicename,
|
2007-05-12 16:42:01 +00:00
|
|
|
(long double)total_transfers_read,
|
2007-05-12 09:28:34 +00:00
|
|
|
(long double)total_transfers_write,
|
2007-05-12 16:42:01 +00:00
|
|
|
(long double)
|
|
|
|
total_bytes_read / 1024,
|
|
|
|
(long double)
|
|
|
|
total_bytes_write / 1024,
|
|
|
|
queue_len,
|
2012-12-15 18:21:09 +00:00
|
|
|
total_duration, busy_time);
|
2006-04-16 22:23:39 +00:00
|
|
|
if (firstline) {
|
|
|
|
/*
|
|
|
|
* If this is the first device
|
|
|
|
* we're printing, also print
|
|
|
|
* CPU or TTY stats if requested.
|
|
|
|
*/
|
|
|
|
firstline = 0;
|
|
|
|
if (Tflag > 0)
|
|
|
|
printf("%4.0Lf%5.0Lf",
|
|
|
|
cur.tk_nin / etime,
|
|
|
|
cur.tk_nout / etime);
|
|
|
|
if (Cflag > 0)
|
|
|
|
cpustats();
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2016-02-22 21:40:53 +00:00
|
|
|
free(devicename);
|
2006-04-16 22:23:39 +00:00
|
|
|
} else if (oflag > 0) {
|
1998-09-16 18:03:44 +00:00
|
|
|
int msdig = (ms_per_transaction < 100.0) ? 1 : 0;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
|
|
|
if (Iflag == 0)
|
1998-09-16 18:03:44 +00:00
|
|
|
printf("%4.0Lf%4.0Lf%5.*Lf ",
|
1998-09-15 08:16:45 +00:00
|
|
|
blocks_per_second,
|
|
|
|
transfers_per_second,
|
1998-09-16 18:03:44 +00:00
|
|
|
msdig,
|
1998-09-15 08:16:45 +00:00
|
|
|
ms_per_transaction);
|
2006-04-16 22:28:04 +00:00
|
|
|
else
|
2011-12-17 20:25:23 +00:00
|
|
|
printf("%4.1" PRIu64 "%4.1" PRIu64 "%5.*Lf ",
|
1998-09-15 08:16:45 +00:00
|
|
|
total_blocks,
|
|
|
|
total_transfers,
|
1998-09-16 18:03:44 +00:00
|
|
|
msdig,
|
1998-09-15 08:16:45 +00:00
|
|
|
ms_per_transaction);
|
|
|
|
} else {
|
|
|
|
if (Iflag == 0)
|
2006-04-16 22:28:04 +00:00
|
|
|
printf(" %5.2Lf %3.0Lf %5.2Lf ",
|
1998-09-15 08:16:45 +00:00
|
|
|
kb_per_transfer,
|
|
|
|
transfers_per_second,
|
|
|
|
mb_per_second);
|
|
|
|
else {
|
|
|
|
total_mb = total_bytes;
|
|
|
|
total_mb /= 1024 * 1024;
|
|
|
|
|
2011-12-17 20:25:23 +00:00
|
|
|
printf(" %5.2Lf %3.1" PRIu64 " %5.2Lf ",
|
1998-09-15 08:16:45 +00:00
|
|
|
kb_per_transfer,
|
|
|
|
total_transfers,
|
|
|
|
total_mb);
|
|
|
|
}
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2006-04-16 22:23:39 +00:00
|
|
|
if (xflag > 0 && zflag > 0 && firstline == 1 &&
|
|
|
|
(Tflag > 0 || Cflag > 0)) {
|
|
|
|
/*
|
|
|
|
* If zflag is set and we did not print any device
|
|
|
|
* lines I/O because they were all zero,
|
|
|
|
* print TTY/CPU stats.
|
|
|
|
*/
|
|
|
|
printf("%52s","");
|
|
|
|
if (Tflag > 0)
|
2009-08-15 17:57:21 +00:00
|
|
|
printf("%4.0Lf %5.0Lf", cur.tk_nin / etime,
|
2006-04-16 22:23:39 +00:00
|
|
|
cur.tk_nout / etime);
|
|
|
|
if (Cflag > 0)
|
|
|
|
cpustats();
|
|
|
|
printf("\n");
|
|
|
|
}
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 08:16:45 +00:00
|
|
|
static void
|
|
|
|
cpustats(void)
|
1994-05-26 05:23:31 +00:00
|
|
|
{
|
2006-04-16 22:30:24 +00:00
|
|
|
int state;
|
2016-02-22 21:40:53 +00:00
|
|
|
double cptime;
|
1994-05-26 05:23:31 +00:00
|
|
|
|
2016-02-22 21:40:53 +00:00
|
|
|
cptime = 0.0;
|
1998-09-15 08:16:45 +00:00
|
|
|
|
1994-05-26 05:23:31 +00:00
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
2016-02-22 21:40:53 +00:00
|
|
|
cptime += cur.cp_time[state];
|
1994-05-26 05:23:31 +00:00
|
|
|
for (state = 0; state < CPUSTATES; ++state)
|
2002-08-18 17:51:14 +00:00
|
|
|
printf(" %2.0f",
|
2016-02-22 21:40:53 +00:00
|
|
|
rint(100. * cur.cp_time[state] / (cptime ? cptime : 1)));
|
1994-05-26 05:23:31 +00:00
|
|
|
}
|
2001-08-04 18:30:54 +00:00
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
static int
|
|
|
|
readvar(kvm_t *kd, const char *name, int nlid, void *ptr, size_t len)
|
2001-08-04 18:30:54 +00:00
|
|
|
{
|
2001-08-23 03:19:54 +00:00
|
|
|
if (kd != NULL) {
|
|
|
|
ssize_t nbytes;
|
|
|
|
|
2007-02-06 20:29:40 +00:00
|
|
|
nbytes = kvm_read(kd, namelist[nlid].n_value, ptr, len);
|
2001-08-23 03:19:54 +00:00
|
|
|
|
2007-02-06 20:29:40 +00:00
|
|
|
if (nbytes < 0) {
|
|
|
|
warnx("kvm_read(%s): %s", namelist[nlid].n_name,
|
|
|
|
kvm_geterr(kd));
|
2001-08-23 03:19:54 +00:00
|
|
|
return (1);
|
2016-02-18 20:08:01 +00:00
|
|
|
} else if ((size_t)nbytes != len) {
|
2007-02-06 20:29:40 +00:00
|
|
|
warnx("kvm_read(%s): expected %zu bytes, got %zd bytes",
|
|
|
|
namelist[nlid].n_name, len, nbytes);
|
2001-08-23 03:19:54 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
size_t nlen = len;
|
2006-04-16 22:28:04 +00:00
|
|
|
|
2001-08-23 03:19:54 +00:00
|
|
|
if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) {
|
|
|
|
warn("sysctl(%s...) failed", name);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (nlen != len) {
|
|
|
|
warnx("sysctl(%s...): expected %lu, got %lu", name,
|
|
|
|
(unsigned long)len, (unsigned long)nlen);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
2001-08-04 18:30:54 +00:00
|
|
|
}
|