From owner-svn-src-head@freebsd.org Mon Nov 27 15:24:15 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1070DE54B46; Mon, 27 Nov 2017 15:24:15 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DBCA076DD8; Mon, 27 Nov 2017 15:24:14 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vARFODXb006542; Mon, 27 Nov 2017 15:24:13 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vARFODsM006541; Mon, 27 Nov 2017 15:24:13 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201711271524.vARFODsM006541@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 27 Nov 2017 15:24:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326273 - head/usr.bin/ctlstat X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: head/usr.bin/ctlstat X-SVN-Commit-Revision: 326273 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Nov 2017 15:24:15 -0000 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)