Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Nov 2017 15:24:13 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r326273 - head/usr.bin/ctlstat
Message-ID:  <201711271524.vARFODsM006541@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Nov 27 15:24:13 2017
New Revision: 326273
URL: https://svnweb.freebsd.org/changeset/base/326273

Log:
  Make ctlstat -n option work reasonably for sparse LUN list.
  
  MFC after:	2 weeks
  Sponsored by:	iXsystems, Inc.

Modified:
  head/usr.bin/ctlstat/ctlstat.c

Modified: head/usr.bin/ctlstat/ctlstat.c
==============================================================================
--- head/usr.bin/ctlstat/ctlstat.c	Mon Nov 27 15:23:17 2017	(r326272)
+++ head/usr.bin/ctlstat/ctlstat.c	Mon Nov 27 15:24:13 2017	(r326273)
@@ -320,11 +320,12 @@ static const char *iotypes[] = {"NO IO", "READ", "WRIT
 static void
 ctlstat_dump(struct ctlstat_context *ctx)
 {
-	int iotype, i;
+	int iotype, i, n;
 	struct ctl_io_stats *stats = ctx->cur_stats;
 
-	for (i = 0; i < ctx->cur_items;i++) {
-		if (F_MASK(ctx) && bit_test(ctx->item_mask, i) == 0)
+	for (i = n = 0; i < ctx->cur_items;i++) {
+		if (F_MASK(ctx) && bit_test(ctx->item_mask,
+		    (int)stats[i].item) == 0)
 			continue;
 		printf("%s %d\n", F_PORTS(ctx) ? "port" : "lun", stats[i].item);
 		for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) {
@@ -341,17 +342,20 @@ ctlstat_dump(struct ctlstat_context *ctx)
 			PRINT_BINTIME(stats[i].dma_time[iotype]);
 			printf("\n");
 		}
+		if (++n >= ctx->numdevs)
+			break;
 	}
 }
 
 static void
 ctlstat_json(struct ctlstat_context *ctx) {
-	int iotype, i;
+	int iotype, i, n;
 	struct ctl_io_stats *stats = ctx->cur_stats;
 
 	printf("{\"%s\":[", F_PORTS(ctx) ? "ports" : "luns");
-	for (i = 0; i < ctx->cur_items; i++) {
-		if (F_MASK(ctx) && bit_test(ctx->item_mask, i) == 0)
+	for (i = n = 0; i < ctx->cur_items; i++) {
+		if (F_MASK(ctx) && bit_test(ctx->item_mask,
+		    (int)stats[i].item) == 0)
 			continue;
 		printf("{\"num\":%d,\"io\":[",
 		    stats[i].item);
@@ -372,6 +376,8 @@ ctlstat_json(struct ctlstat_context *ctx) {
 				printf(","); /* continue io array */
 		}
 		printf("]}");
+		if (++n >= ctx->numdevs)
+			break;
 		if (i < (ctx->cur_items - 1))
 			printf(","); /* continue lun array */
 	}
@@ -383,7 +389,7 @@ ctlstat_standard(struct ctlstat_context *ctx) {
 	long double etime;
 	uint64_t delta_jiffies, delta_idle;
 	long double cpu_percentage;
-	int i, j;
+	int i, j, n;
 
 	cpu_percentage = 0;
 
@@ -413,10 +419,6 @@ ctlstat_standard(struct ctlstat_context *ctx) {
 	if (F_HDR(ctx)) {
 		ctx->header_interval--;
 		if (ctx->header_interval <= 0) {
-			int hdr_devs;
-
-			hdr_devs = 0;
-
 			if (F_CPU(ctx))
 				fprintf(stdout, " CPU");
 			if (F_TOTALS(ctx)) {
@@ -425,9 +427,9 @@ ctlstat_standard(struct ctlstat_context *ctx) {
 					(F_TIMEVAL(ctx) != 0) ? "      " : "",
 					(F_TIMEVAL(ctx) != 0) ? "      " : "",
 					(F_TIMEVAL(ctx) != 0) ? "      " : "");
-				hdr_devs = 3;
+				n = 3;
 			} else {
-				for (i = 0; i < min(CTL_STAT_BITS,
+				for (i = n = 0; i < min(CTL_STAT_BITS,
 				     ctx->cur_items); i++) {
 					int item;
 
@@ -444,13 +446,14 @@ ctlstat_standard(struct ctlstat_context *ctx) {
 					fprintf(stdout, "%15.6s%d %s",
 					    F_PORTS(ctx) ? "port" : "lun", item,
 					    (F_TIMEVAL(ctx) != 0) ? "     " : "");
-					hdr_devs++;
+					if (++n >= ctx->numdevs)
+						break;
 				}
 				fprintf(stdout, "\n");
 			}
 			if (F_CPU(ctx))
 				fprintf(stdout, "    ");
-			for (i = 0; i < hdr_devs; i++)
+			for (i = 0; i < n; i++)
 				fprintf(stdout, "%s KB/t   %s MB/s",
 					(F_TIMEVAL(ctx) != 0) ? "    ms" : "",
 					(F_DMA(ctx) == 0) ? "tps" : "dps");
@@ -534,7 +537,7 @@ ctlstat_standard(struct ctlstat_context *ctx) {
 				dmas_per_sec[i], mbsec[i]);
 		}
 	} else {
-		for (i = 0; i < min(CTL_STAT_BITS, ctx->cur_items); i++) {
+		for (i = n = 0; i < min(CTL_STAT_BITS, ctx->cur_items); i++) {
 			long double mbsec, kb_per_transfer;
 			long double transfers_per_sec;
 			long double ms_per_transfer;
@@ -565,6 +568,8 @@ ctlstat_standard(struct ctlstat_context *ctx) {
 			fprintf(stdout, " %4.0Lf %5.0Lf %4.0Lf",
 				kb_per_transfer, (F_DMA(ctx) == 0) ?
 				transfers_per_sec : dmas_per_sec, mbsec);
+			if (++n >= ctx->numdevs)
+				break;
 		}
 	}
 }
@@ -668,18 +673,6 @@ main(int argc, char **argv)
 			ctx.flags |= CTLSTAT_FLAG_PORTS;
 		else
 			ctx.flags |= CTLSTAT_FLAG_LUNS;
-	}
-
-	if (!F_TOTALS(&ctx) && !F_MASK(&ctx)) {
-		/*
-		 * Note that this just selects the first N LUNs to display,
-		 * but at this point we have no knoweledge of which LUN
-		 * numbers actually exist.  So we may select LUNs that
-		 * aren't there.
-		 */
-		bit_nset(ctx.item_mask, 0, min(ctx.numdevs - 1,
-			 CTL_STAT_BITS - 1));
-		ctx.flags |= CTLSTAT_FLAG_MASK;
 	}
 
 	if ((fd = open(CTL_DEFAULT_DEV, O_RDWR)) == -1)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711271524.vARFODsM006541>