svn commit: r308462 - head/usr.sbin/gstat

Marcelo Araujo araujo at FreeBSD.org
Wed Nov 9 07:31:40 UTC 2016


Author: araujo
Date: Wed Nov  9 07:31:39 2016
New Revision: 308462
URL: https://svnweb.freebsd.org/changeset/base/308462

Log:
  Add flag -B which does the same like batch mode but without exiting after
  print. Also add a new flag -s that add blocks size to statistics.
  
  PR:		198347, 212726
  Submitted by:	Ben RUBSON <ben.rubson at gmail.com>
  Tested by:	pi
  MFC After:	2 weeks.

Modified:
  head/usr.sbin/gstat/gstat.8
  head/usr.sbin/gstat/gstat.c

Modified: head/usr.sbin/gstat/gstat.8
==============================================================================
--- head/usr.sbin/gstat/gstat.8	Wed Nov  9 07:09:27 2016	(r308461)
+++ head/usr.sbin/gstat/gstat.8	Wed Nov  9 07:31:39 2016	(r308462)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd July 3, 2014
+.Dd November 10, 2016
 .Dt GSTAT 8
 .Os
 .Sh NAME
@@ -32,7 +32,7 @@
 .Nd print statistics about GEOM disks
 .Sh SYNOPSIS
 .Nm
-.Op Fl abcdop
+.Op Fl abBcdops
 .Op Fl f Ar filter
 .Op Fl I Ar interval
 .Sh DESCRIPTION
@@ -50,6 +50,10 @@ Only display providers that are at least
 Batch mode.
 Collect numbers, print and exit.
 Default if stdout is not a tty.
+.It Fl B
+Endless batch mode.
+Same as batch mode, but does not exit after collecting
+the first set of data.
 .It Fl c
 Enable display of
 .Xr geom 4
@@ -72,6 +76,8 @@ The format of the regular expression is 
 .It Fl o
 Enable display of statistics for other operations
 .Pq Dv BIO_FLUSH .
+.It Fl s
+Enable blocks' size statistics.
 .It Fl I Ar interval
 Refresh the
 .Nm

Modified: head/usr.sbin/gstat/gstat.c
==============================================================================
--- head/usr.sbin/gstat/gstat.c	Wed Nov  9 07:09:27 2016	(r308461)
+++ head/usr.sbin/gstat/gstat.c	Wed Nov  9 07:31:39 2016	(r308462)
@@ -51,11 +51,11 @@
 #include <sysexits.h>
 #include <unistd.h>
 
-static int flag_a, flag_b, flag_c, flag_d, flag_o, flag_p;
+static int flag_a, flag_b, flag_B, flag_c, flag_d, flag_o, flag_p, flag_s;
 static int flag_I = 1000000;
 
 #define PRINTMSG(...) do {						\
-		if (flag_b && !loop)					\
+		if ((flag_b && !loop) || (flag_B))			\
 			printf(__VA_ARGS__);				\
 		else if (!flag_b)					\
 			printw(__VA_ARGS__);				\
@@ -88,7 +88,7 @@ main(int argc, char **argv)
 	char *p;
 	char f_s[100], pf_s[100], tmp_f_s[100];
 	const char *line;
-	long double ld[13];
+	long double ld[16];
 	uint64_t u64;
 	EditLine *el;
 	History *hist;
@@ -104,7 +104,7 @@ main(int argc, char **argv)
 		flag_b = 1;
 
 	f_s[0] = '\0';
-	while ((i = getopt(argc, argv, "abdcf:I:op")) != -1) {
+	while ((i = getopt(argc, argv, "abBdcf:I:ops")) != -1) {
 		switch (i) {
 		case 'a':
 			flag_a = 1;
@@ -112,6 +112,10 @@ main(int argc, char **argv)
 		case 'b':
 			flag_b = 1;
 			break;
+		case 'B':
+			flag_B = 1;
+			flag_b = 1;
+			break;
 		case 'c':
 			flag_c = 1;
 			break;
@@ -146,6 +150,9 @@ main(int argc, char **argv)
 		case 'p':
 			flag_p = 1;
 			break;
+		case 's':
+			flag_s = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -208,7 +215,8 @@ main(int argc, char **argv)
 	
 		geom_stats_snapshot_reset(sp);
 		geom_stats_snapshot_reset(sq);
-		move(0,0);
+		if (!flag_b)
+			move(0,0);
 		PRINTMSG("dT: %5.3fs  w: %.3fs", dt, (float)flag_I / 1000000);
 		if (f_s[0] != '\0') {
 			PRINTMSG("  filter: ");
@@ -231,10 +239,20 @@ main(int argc, char **argv)
 		}
 		PRINTMSG("\n");
 		PRINTMSG(" L(q)  ops/s   ");
-		PRINTMSG(" r/s   kBps   ms/r   ");
-		PRINTMSG(" w/s   kBps   ms/w   ");
-		if (flag_d)
-			PRINTMSG(" d/s   kBps   ms/d   ");
+		if (flag_s) {
+			PRINTMSG(" r/s     kB   kBps   ms/r   ");
+			PRINTMSG(" w/s     kB   kBps   ms/w   ");
+		}
+		else {
+			PRINTMSG(" r/s   kBps   ms/r   ");
+			PRINTMSG(" w/s   kBps   ms/w   ");
+		}
+		if (flag_d) {
+			if (flag_s)
+				PRINTMSG(" d/s     kB   kBps   ms/d   ");
+			else
+				PRINTMSG(" d/s   kBps   ms/d   ");
+		}
 		if (flag_o)
 			PRINTMSG(" o/s   ms/o   ");
 		PRINTMSG("%%busy Name\n");
@@ -298,6 +316,10 @@ main(int argc, char **argv)
 			    DSM_TRANSFERS_PER_SECOND_OTHER, &ld[11],
 			    DSM_MS_PER_TRANSACTION_OTHER, &ld[12],
 
+			    DSM_KB_PER_TRANSFER_READ, &ld[13],
+			    DSM_KB_PER_TRANSFER_WRITE, &ld[14],
+			    DSM_KB_PER_TRANSFER_FREE, &ld[15],
+
 			    DSM_NONE);
 
 			if (flag_a && ld[7] < 0.1) {
@@ -308,12 +330,16 @@ main(int argc, char **argv)
 			PRINTMSG(" %4ju", (uintmax_t)u64);
 			PRINTMSG(" %6.0f", (double)ld[0]);
 			PRINTMSG(" %6.0f", (double)ld[1]);
+			if (flag_s)
+				PRINTMSG(" %6.0f", (double)ld[13]);
 			PRINTMSG(" %6.0f", (double)ld[2] * 1024);
 			if (ld[3] > 1e3) 
 				PRINTMSG(" %6.0f", (double)ld[3]);
 			else
 				PRINTMSG(" %6.1f", (double)ld[3]);
 			PRINTMSG(" %6.0f", (double)ld[4]);
+			if (flag_s)
+				PRINTMSG(" %6.0f", (double)ld[14]);
 			PRINTMSG(" %6.0f", (double)ld[5] * 1024);
 			if (ld[6] > 1e3) 
 				PRINTMSG(" %6.0f", (double)ld[6]);
@@ -322,6 +348,8 @@ main(int argc, char **argv)
 
 			if (flag_d) {
 				PRINTMSG(" %6.0f", (double)ld[8]);
+				if (flag_s)
+					PRINTMSG(" %6.0f", (double)ld[15]);
 				PRINTMSG(" %6.0f", (double)ld[9] * 1024);
 				if (ld[10] > 1e3) 
 					PRINTMSG(" %6.0f", (double)ld[10]);
@@ -373,7 +401,10 @@ main(int argc, char **argv)
 			/* We loop extra to make sure we get the information. */
 			if (!loop)
 				break;
-			loop = 0;
+			if (!flag_B)
+				loop = 0;
+			else
+				fflush(stdout);
 			usleep(flag_I);
 			continue;
 		}
@@ -452,7 +483,7 @@ main(int argc, char **argv)
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: gstat [-abcdp] [-f filter] [-I interval]\n");
+	fprintf(stderr, "usage: gstat [-abBcdps] [-f filter] [-I interval]\n");
 	exit(EX_USAGE);
         /* NOTREACHED */
 }


More information about the svn-src-all mailing list