[Midnightbsd-cvs] src [10740] trunk/usr.sbin/iostat/iostat.c: sync

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 18:09:39 EDT 2018


Revision: 10740
          http://svnweb.midnightbsd.org/src/?rev=10740
Author:   laffer1
Date:     2018-06-09 18:09:38 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync

Modified Paths:
--------------
    trunk/usr.sbin/iostat/Makefile
    trunk/usr.sbin/iostat/iostat.8
    trunk/usr.sbin/iostat/iostat.c

Property Changed:
----------------
    trunk/usr.sbin/iostat/iostat.8

Modified: trunk/usr.sbin/iostat/Makefile
===================================================================
--- trunk/usr.sbin/iostat/Makefile	2018-06-09 22:08:57 UTC (rev 10739)
+++ trunk/usr.sbin/iostat/Makefile	2018-06-09 22:09:38 UTC (rev 10740)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/iostat/Makefile 296995 2016-03-17 20:29:10Z asomers $
 
 PROG=	iostat
 MAN=	iostat.8
@@ -7,6 +8,4 @@
 DPADD=	${LIBDEVSTAT} ${LIBKVM} ${LIBM}
 LDADD=	-ldevstat -lkvm -lm
 
-WARNS?=	1
-
 .include <bsd.prog.mk>

Modified: trunk/usr.sbin/iostat/iostat.8
===================================================================
--- trunk/usr.sbin/iostat/iostat.8	2018-06-09 22:08:57 UTC (rev 10739)
+++ trunk/usr.sbin/iostat/iostat.8	2018-06-09 22:09:38 UTC (rev 10740)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 1997 Kenneth D. Merry.
 .\" All rights reserved.
@@ -25,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/iostat/iostat.8 284671 2015-06-21 06:54:54Z trasz $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -56,7 +57,7 @@
 .\"
 .\"	@(#)iostat.8	8.1 (Berkeley) 6/6/93
 .\"
-.Dd November 24, 2010
+.Dd May 22, 2015
 .Dt IOSTAT 8
 .Os
 .Sh NAME
@@ -366,6 +367,32 @@
 % of time the device had one or more outstanding transactions
 .El
 .Pp
+The extended
+.Nm
+device display, with the
+.Fl x
+and
+.Fl I
+flags specified, shows the following statistics:
+.Pp
+.Bl -tag -width indent -compact
+.It r/i
+read operations per time period
+.It w/i
+write operations per time period
+.It kr/i
+kilobytes read per time period
+.It kw/i
+kilobytes write per time period
+.It qlen
+transactions queue length
+.It tsvc_t/i
+total duration of transactions per time period, in seconds
+.It sb/i
+total time the device had one or more outstanding transactions per
+time period, in seconds
+.El
+.Pp
 The old-style
 .Nm
 display (using
@@ -468,6 +495,7 @@
 .Xr ps 1 ,
 .Xr systat 1 ,
 .Xr devstat 3 ,
+.Xr ctlstat 8 ,
 .Xr gstat 8 ,
 .Xr pstat 8 ,
 .Xr vmstat 8


Property changes on: trunk/usr.sbin/iostat/iostat.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/iostat/iostat.c
===================================================================
--- trunk/usr.sbin/iostat/iostat.c	2018-06-09 22:08:57 UTC (rev 10739)
+++ trunk/usr.sbin/iostat/iostat.c	2018-06-09 22:09:38 UTC (rev 10740)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1997, 1998, 2000, 2001  Kenneth D. Merry
  * All rights reserved.
@@ -25,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/iostat/iostat.c 296995 2016-03-17 20:29:10Z asomers $
  */
 /*
  * Parts of this program are derived from the original FreeBSD iostat
@@ -110,6 +111,7 @@
 #include <limits.h>
 #include <math.h>
 #include <nlist.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -116,33 +118,41 @@
 #include <termios.h>
 #include <unistd.h>
 
-struct nlist namelist[] = {
+static struct nlist namelist[] = {
 #define X_TK_NIN	0
-	{ "_tk_nin" },
+	{ .n_name = "_tk_nin",
+	  .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
 #define X_TK_NOUT	1
-	{ "_tk_nout" },
+	{ .n_name = "_tk_nout",
+	  .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
 #define X_BOOTTIME	2
-	{ "_boottime" },
+	{ .n_name = "_boottime",
+	  .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
 #define X_END		2
-	{ NULL },
+	{ .n_name = NULL,
+	  .n_type = 0, .n_other = 0, .n_desc = 0, .n_value = 0 },
 };
 
 #define	IOSTAT_DEFAULT_ROWS	20	/* Traditional default `wrows' */
 
-struct statinfo cur, last;
-int num_devices;
-struct device_selection *dev_select;
-int maxshowdevs;
-volatile sig_atomic_t headercount;
-volatile sig_atomic_t wresized;		/* Tty resized, when non-zero. */
-unsigned short wrows;			/* Current number of tty rows. */
-int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0;
-int xflag = 0, zflag = 0;
+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;
 
 /* local function declarations */
 static void usage(void);
 static void needhdr(int signo);
 static void needresize(int signo);
+static void needreturn(int signo);
+static void alarm_clock(int signo);
 static void doresize(void);
 static void phdr(void);
 static void devstats(int perf_select, long double etime, int havelast);
@@ -172,6 +182,7 @@
 	int count = 0, waittime = 0;
 	char *memf = NULL, *nlistf = NULL;
 	struct devstat_match *matches;
+	struct itimerval alarmspec;
 	int num_matches = 0;
 	char errbuf[_POSIX2_LINE_MAX];
 	kvm_t *kd = NULL;
@@ -442,10 +453,28 @@
 		wrows = IOSTAT_DEFAULT_ROWS;
 	}
 
+	/*
+	 * 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);
+
 	for (headercount = 1;;) {
 		struct devinfo *tmp_dinfo;
 		long tmp;
 		long double etime;
+		sigset_t sigmask, oldsigmask;
 
 		if (Tflag > 0) {
 			if ((readvar(kd, "kern.tty_nin", X_TK_NIN, &cur.tk_nin,
@@ -599,10 +628,23 @@
 		}
 		fflush(stdout);
 
-		if (count >= 0 && --count <= 0)
+		if ((count >= 0 && --count <= 0) || return_requested)
 			break;
 
-		usleep(waittime * 1000);
+		/*
+		 * 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);
+
 		havelast = 1;
 	}
 
@@ -613,7 +655,7 @@
  * Force a header to be prepended to the next output.
  */
 void
-needhdr(int signo)
+needhdr(int signo __unused)
 {
 
 	headercount = 1;
@@ -625,7 +667,7 @@
  * prepended to the next output.
  */
 void
-needresize(int signo)
+needresize(int signo __unused)
 {
 
 	wresized = 1;
@@ -633,6 +675,24 @@
 }
 
 /*
+ * Record the alarm so the main loop can break its sleep
+ */
+void
+alarm_clock(int signo __unused)
+{
+	alarm_rang = 1;
+}
+
+/*
+ * Request that the main loop exit soon
+ */
+void
+needreturn(int signo __unused)
+{
+	return_requested = 1;
+}
+
+/*
  * Update the global `wrows' count of terminal rows.
  */
 void
@@ -731,12 +791,12 @@
 	u_int64_t total_bytes, total_transfers, total_blocks;
 	u_int64_t total_bytes_read, total_transfers_read;
 	u_int64_t total_bytes_write, total_transfers_write;
-	long double busy_pct;
+	long double busy_pct, busy_time;
 	u_int64_t queue_len;
 	long double total_mb;
-	long double blocks_per_second, ms_per_transaction;
+	long double blocks_per_second, ms_per_transaction, total_duration;
 	int firstline = 1;
-	char *devname;
+	char *devicename;
 
 	if (xflag > 0) {
 		printf("                        extended device statistics  ");
@@ -745,14 +805,13 @@
 		if (Cflag > 0)
 			printf("           cpu ");
 		printf("\n");
-		if (Iflag == 0)
-			printf(
-		"device     r/s   w/s    kr/s    kw/s qlen svc_t  %%b  "
-			    );
-		else
-			printf(
-		"device     r/i   w/i    kr/i    kw/i qlen svc_t  %%b  "
-			    );
+		if (Iflag == 0) {
+			printf("device     r/s   w/s    kr/s    kw/s qlen "
+			    "svc_t  %%b  ");
+		} else {
+			printf("device           r/i         w/i         kr/i"
+			    "         kw/i qlen   tsvc_t/i      sb/i  ");
+		}
 		if (Tflag > 0)
 			printf("tin  tout ");
 		if (Cflag > 0)
@@ -789,6 +848,8 @@
 		    DSM_MS_PER_TRANSACTION, &ms_per_transaction,
 		    DSM_BUSY_PCT, &busy_pct,
 		    DSM_QUEUE_LENGTH, &queue_len,
+		    DSM_TOTAL_DURATION, &total_duration,
+		    DSM_TOTAL_BUSY_TIME, &busy_time,
 		    DSM_NONE) != 0)
 			errx(1, "%s", devstat_errbuf);
 
@@ -806,7 +867,7 @@
 		}
 
 		if (xflag > 0) {
-			if (asprintf(&devname, "%s%d",
+			if (asprintf(&devicename, "%s%d",
 			    cur.dinfo->devices[di].device_name,
 			    cur.dinfo->devices[di].unit_number) == -1)
 				err(1, "asprintf");
@@ -820,7 +881,8 @@
 			    busy_pct > 0.5) {
 				if (Iflag == 0)
 					printf("%-8.8s %5.1Lf %5.1Lf %7.1Lf %7.1Lf %4" PRIu64 " %5.1Lf %3.0Lf ",
-					    devname, transfers_per_second_read,
+					    devicename,
+					    transfers_per_second_read,
 					    transfers_per_second_write,
 					    mb_per_second_read * 1024,
 					    mb_per_second_write * 1024,
@@ -827,8 +889,10 @@
 					    queue_len,
 					    ms_per_transaction, busy_pct);
 				else
-					printf("%-8.8s %5.1Lf %5.1Lf %7.1Lf %7.1Lf %4" PRIu64 " %5.1Lf %3.0Lf ",
-					    devname,
+					printf("%-8.8s %11.1Lf %11.1Lf "
+					    "%12.1Lf %12.1Lf %4" PRIu64
+					    " %10.1Lf %9.1Lf ",
+					    devicename,
 					    (long double)total_transfers_read,
 					    (long double)total_transfers_write,
 					    (long double)
@@ -836,7 +900,7 @@
 					    (long double)
 					        total_bytes_write / 1024,
 					    queue_len,
-					    ms_per_transaction, busy_pct);
+					    total_duration, busy_time);
 				if (firstline) {
 					/*
 					 * If this is the first device
@@ -853,7 +917,7 @@
 				}
 				printf("\n");
 			}
-			free(devname);
+			free(devicename);
 		} else if (oflag > 0) {
 			int msdig = (ms_per_transaction < 100.0) ? 1 : 0;
 
@@ -907,15 +971,15 @@
 cpustats(void)
 {
 	int state;
-	double time;
+	double cptime;
 
-	time = 0.0;
+	cptime = 0.0;
 
 	for (state = 0; state < CPUSTATES; ++state)
-		time += cur.cp_time[state];
+		cptime += cur.cp_time[state];
 	for (state = 0; state < CPUSTATES; ++state)
 		printf(" %2.0f",
-		       rint(100. * cur.cp_time[state] / (time ? time : 1)));
+		       rint(100. * cur.cp_time[state] / (cptime ? cptime : 1)));
 }
 
 static int
@@ -930,8 +994,7 @@
 			warnx("kvm_read(%s): %s", namelist[nlid].n_name,
 			    kvm_geterr(kd));
 			return (1);
-		}
-		if (nbytes != len) {
+		} else if ((size_t)nbytes != len) {
 			warnx("kvm_read(%s): expected %zu bytes, got %zd bytes",
 			      namelist[nlid].n_name, len, nbytes);
 			return (1);



More information about the Midnightbsd-cvs mailing list