2 * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGES.
30 * $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.c#4 $
33 * CAM Target Layer statistics program
35 * Authors: Ken Merry <ken@FreeBSD.org>, Will Andrews <will@FreeBSD.org>
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/ioctl.h>
42 #include <sys/types.h>
43 #include <sys/param.h>
45 #include <sys/sysctl.h>
46 #include <sys/resource.h>
47 #include <sys/queue.h>
48 #include <sys/callout.h>
59 #include <bitstring.h>
60 #include <cam/scsi/scsi_all.h>
61 #include <cam/ctl/ctl.h>
62 #include <cam/ctl/ctl_io.h>
63 #include <cam/ctl/ctl_scsi_all.h>
64 #include <cam/ctl/ctl_util.h>
65 #include <cam/ctl/ctl_frontend_internal.h>
66 #include <cam/ctl/ctl_backend.h>
67 #include <cam/ctl/ctl_ioctl.h>
70 * The default amount of space we allocate for LUN storage space. We
71 * dynamically allocate more if needed.
73 #define CTL_STAT_NUM_LUNS 30
76 * The default number of LUN selection bits we allocate. This is large
77 * because we don't currently increase it if the user specifies a LUN
78 * number of 1024 or larger.
80 #define CTL_STAT_LUN_BITS 1024L
82 static const char *ctlstat_opts = "Cc:Ddhjl:n:tw:";
83 static const char *ctlstat_usage = "Usage: ctlstat [-CDdjht] [-l lunnum]"
84 "[-c count] [-n numdevs] [-w wait]\n";
86 struct ctl_cpu_stats {
95 CTLSTAT_MODE_STANDARD,
100 #define CTLSTAT_FLAG_CPU (1 << 0)
101 #define CTLSTAT_FLAG_HEADER (1 << 1)
102 #define CTLSTAT_FLAG_FIRST_RUN (1 << 2)
103 #define CTLSTAT_FLAG_TOTALS (1 << 3)
104 #define CTLSTAT_FLAG_DMA_TIME (1 << 4)
105 #define CTLSTAT_FLAG_LUN_TIME_VALID (1 << 5)
106 #define F_CPU(ctx) ((ctx)->flags & CTLSTAT_FLAG_CPU)
107 #define F_HDR(ctx) ((ctx)->flags & CTLSTAT_FLAG_HEADER)
108 #define F_FIRST(ctx) ((ctx)->flags & CTLSTAT_FLAG_FIRST_RUN)
109 #define F_TOTALS(ctx) ((ctx)->flags & CTLSTAT_FLAG_TOTALS)
110 #define F_DMA(ctx) ((ctx)->flags & CTLSTAT_FLAG_DMA_TIME)
111 #define F_LUNVAL(ctx) ((ctx)->flags & CTLSTAT_FLAG_LUN_TIME_VALID)
113 struct ctlstat_context {
114 ctlstat_mode_types mode;
116 struct ctl_lun_io_stats *cur_lun_stats, *prev_lun_stats,
118 struct ctl_lun_io_stats cur_total_stats[3], prev_total_stats[3];
119 struct timespec cur_time, prev_time;
120 struct ctl_cpu_stats cur_cpu, prev_cpu;
121 uint64_t cur_total_jiffies, prev_total_jiffies;
122 uint64_t cur_idle, prev_idle;
123 bitstr_t bit_decl(lun_mask, CTL_STAT_LUN_BITS);
130 #define min(x,y) (((x) < (y)) ? (x) : (y))
133 static void usage(int error);
134 static int getstats(int fd, int *num_luns, struct ctl_lun_io_stats **xlun_stats,
135 struct timespec *cur_time, int *lun_time_valid);
136 static int getcpu(struct ctl_cpu_stats *cpu_stats);
137 static void compute_stats(struct ctl_lun_io_stats *cur_stats,
138 struct ctl_lun_io_stats *prev_stats,
139 long double etime, long double *mbsec,
140 long double *kb_per_transfer,
141 long double *transfers_per_second,
142 long double *ms_per_transfer,
143 long double *ms_per_dma,
144 long double *dmas_per_second);
149 fputs(ctlstat_usage, error ? stderr : stdout);
153 getstats(int fd, int *num_luns, struct ctl_lun_io_stats **xlun_stats,
154 struct timespec *cur_time, int *flags)
156 struct ctl_lun_io_stats *lun_stats;
157 struct ctl_stats stats;
158 int more_space_count;
160 more_space_count = 0;
163 *num_luns = CTL_STAT_NUM_LUNS;
165 lun_stats = *xlun_stats;
168 if (lun_stats == NULL) {
169 lun_stats = (struct ctl_lun_io_stats *)malloc(
170 sizeof(*lun_stats) * *num_luns);
173 memset(&stats, 0, sizeof(stats));
174 stats.alloc_len = *num_luns * sizeof(*lun_stats);
175 memset(lun_stats, 0, stats.alloc_len);
176 stats.lun_stats = lun_stats;
178 if (ioctl(fd, CTL_GETSTATS, &stats) == -1)
179 err(1, "error returned from CTL_GETSTATS ioctl");
181 switch (stats.status) {
185 err(1, "CTL_SS_ERROR returned from CTL_GETSTATS ioctl");
187 case CTL_SS_NEED_MORE_SPACE:
188 if (more_space_count > 0) {
189 errx(1, "CTL_GETSTATS returned NEED_MORE_SPACE again");
191 *num_luns = stats.num_luns;
196 break; /* NOTREACHED */
198 errx(1, "unknown status %d returned from CTL_GETSTATS ioctl",
203 *xlun_stats = lun_stats;
204 *num_luns = stats.num_luns;
205 cur_time->tv_sec = stats.timestamp.tv_sec;
206 cur_time->tv_nsec = stats.timestamp.tv_nsec;
207 if (stats.flags & CTL_STATS_FLAG_TIME_VALID)
208 *flags |= CTLSTAT_FLAG_LUN_TIME_VALID;
210 *flags &= ~CTLSTAT_FLAG_LUN_TIME_VALID;
216 getcpu(struct ctl_cpu_stats *cpu_stats)
218 long cp_time[CPUSTATES];
221 cplen = sizeof(cp_time);
223 if (sysctlbyname("kern.cp_time", &cp_time, &cplen, NULL, 0) == -1) {
224 warn("sysctlbyname(kern.cp_time...) failed");
228 cpu_stats->user = cp_time[CP_USER];
229 cpu_stats->nice = cp_time[CP_NICE];
230 cpu_stats->system = cp_time[CP_SYS];
231 cpu_stats->intr = cp_time[CP_INTR];
232 cpu_stats->idle = cp_time[CP_IDLE];
238 compute_stats(struct ctl_lun_io_stats *cur_stats,
239 struct ctl_lun_io_stats *prev_stats, long double etime,
240 long double *mbsec, long double *kb_per_transfer,
241 long double *transfers_per_second, long double *ms_per_transfer,
242 long double *ms_per_dma, long double *dmas_per_second)
244 uint64_t total_bytes = 0, total_operations = 0, total_dmas = 0;
246 struct bintime total_time_bt, total_dma_bt;
247 struct timespec total_time_ts, total_dma_ts;
250 bzero(&total_time_bt, sizeof(total_time_bt));
251 bzero(&total_dma_bt, sizeof(total_dma_bt));
252 bzero(&total_time_ts, sizeof(total_time_ts));
253 bzero(&total_dma_ts, sizeof(total_dma_ts));
254 for (port = 0; port < CTL_MAX_PORTS; port++) {
255 for (i = 0; i < CTL_STATS_NUM_TYPES; i++) {
256 total_bytes += cur_stats->ports[port].bytes[i];
258 cur_stats->ports[port].operations[i];
259 total_dmas += cur_stats->ports[port].num_dmas[i];
260 bintime_add(&total_time_bt,
261 &cur_stats->ports[port].time[i]);
262 bintime_add(&total_dma_bt,
263 &cur_stats->ports[port].dma_time[i]);
264 if (prev_stats != NULL) {
266 prev_stats->ports[port].bytes[i];
268 prev_stats->ports[port].operations[i];
270 prev_stats->ports[port].num_dmas[i];
271 bintime_sub(&total_time_bt,
272 &prev_stats->ports[port].time[i]);
273 bintime_sub(&total_dma_bt,
274 &prev_stats->ports[port].dma_time[i]);
279 *mbsec = total_bytes;
280 *mbsec /= 1024 * 1024;
285 *kb_per_transfer = total_bytes;
286 *kb_per_transfer /= 1024;
287 if (total_operations > 0)
288 *kb_per_transfer /= total_operations;
290 *kb_per_transfer = 0;
291 *transfers_per_second = total_operations;
292 *dmas_per_second = total_dmas;
294 *transfers_per_second /= etime;
295 *dmas_per_second /= etime;
297 *transfers_per_second = 0;
298 *dmas_per_second = 0;
301 bintime2timespec(&total_time_bt, &total_time_ts);
302 bintime2timespec(&total_dma_bt, &total_dma_ts);
303 if (total_operations > 0) {
305 * Convert the timespec to milliseconds.
307 *ms_per_transfer = total_time_ts.tv_sec * 1000;
308 *ms_per_transfer += total_time_ts.tv_nsec / 1000000;
309 *ms_per_transfer /= total_operations;
311 *ms_per_transfer = 0;
313 if (total_dmas > 0) {
315 * Convert the timespec to milliseconds.
317 *ms_per_dma = total_dma_ts.tv_sec * 1000;
318 *ms_per_dma += total_dma_ts.tv_nsec / 1000000;
319 *ms_per_dma /= total_dmas;
324 /* The dump_stats() and json_stats() functions perform essentially the same
325 * purpose, but dump the statistics in different formats. JSON is more
326 * conducive to programming, however.
329 #define PRINT_BINTIME(prefix, bt) \
330 printf("%s %jd s %ju frac\n", prefix, (intmax_t)(bt).sec, \
331 (uintmax_t)(bt).frac)
332 static const char *iotypes[] = {"NO IO", "READ", "WRITE"};
335 ctlstat_dump(struct ctlstat_context *ctx) {
336 int iotype, lun, port;
337 struct ctl_lun_io_stats *stats = ctx->cur_lun_stats;
339 for (lun = 0; lun < ctx->num_luns;lun++) {
340 printf("lun %d\n", lun);
341 for (port = 0; port < CTL_MAX_PORTS; port++) {
343 stats[lun].ports[port].targ_port);
344 for (iotype = 0; iotype < CTL_STATS_NUM_TYPES;
346 printf(" io type %d (%s)\n", iotype,
348 printf(" bytes %ju\n", (uintmax_t)
349 stats[lun].ports[port].bytes[iotype]);
350 printf(" operations %ju\n", (uintmax_t)
351 stats[lun].ports[port].operations[iotype]);
352 PRINT_BINTIME(" io time",
353 stats[lun].ports[port].time[iotype]);
354 printf(" num dmas %ju\n", (uintmax_t)
355 stats[lun].ports[port].num_dmas[iotype]);
356 PRINT_BINTIME(" dma time",
357 stats[lun].ports[port].dma_time[iotype]);
363 #define JSON_BINTIME(prefix, bt) \
364 printf("\"%s\":{\"sec\":%jd,\"frac\":%ju},", \
365 prefix, (intmax_t)(bt).sec, (uintmax_t)(bt).frac)
368 ctlstat_json(struct ctlstat_context *ctx) {
369 int iotype, lun, port;
370 struct ctl_lun_io_stats *stats = ctx->cur_lun_stats;
372 printf("{\"luns\":[");
373 for (lun = 0; lun < ctx->num_luns; lun++) {
374 printf("{\"ports\":[");
375 for (port = 0; port < CTL_MAX_PORTS;port++) {
376 printf("{\"num\":%d,\"io\":[",
377 stats[lun].ports[port].targ_port);
378 for (iotype = 0; iotype < CTL_STATS_NUM_TYPES;
380 printf("{\"type\":\"%s\",", iotypes[iotype]);
381 printf("\"bytes\":%ju,", (uintmax_t)stats[
382 lun].ports[port].bytes[iotype]);
383 printf("\"operations\":%ju,", (uintmax_t)stats[
384 lun].ports[port].operations[iotype]);
385 JSON_BINTIME("io time",
386 stats[lun].ports[port].time[iotype]);
387 JSON_BINTIME("dma time",
388 stats[lun].ports[port].dma_time[iotype]);
389 printf("\"num dmas\":%ju}", (uintmax_t)
390 stats[lun].ports[port].num_dmas[iotype]);
391 if (iotype < (CTL_STATS_NUM_TYPES - 1))
392 printf(","); /* continue io array */
394 printf("]}"); /* close port */
395 if (port < (CTL_MAX_PORTS - 1))
396 printf(","); /* continue port array */
398 printf("]}"); /* close lun */
399 if (lun < (ctx->num_luns - 1))
400 printf(","); /* continue lun array */
402 printf("]}"); /* close luns and toplevel */
406 ctlstat_standard(struct ctlstat_context *ctx) {
408 uint64_t delta_jiffies, delta_idle;
410 long double cpu_percentage;
416 if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0))
417 errx(1, "error returned from getcpu()");
419 etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec +
420 (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9;
423 ctx->prev_total_jiffies = ctx->cur_total_jiffies;
424 ctx->cur_total_jiffies = ctx->cur_cpu.user +
425 ctx->cur_cpu.nice + ctx->cur_cpu.system +
426 ctx->cur_cpu.intr + ctx->cur_cpu.idle;
427 delta_jiffies = ctx->cur_total_jiffies;
428 if (F_FIRST(ctx) == 0)
429 delta_jiffies -= ctx->prev_total_jiffies;
430 ctx->prev_idle = ctx->cur_idle;
431 ctx->cur_idle = ctx->cur_cpu.idle;
432 delta_idle = ctx->cur_idle - ctx->prev_idle;
434 cpu_percentage = delta_jiffies - delta_idle;
435 cpu_percentage /= delta_jiffies;
436 cpu_percentage *= 100;
440 ctx->header_interval--;
441 if (ctx->header_interval <= 0) {
447 fprintf(stdout, "%s System Read %s"
448 "System Write %sSystem Total%s\n",
449 (F_LUNVAL(ctx) != 0) ? " " : "",
450 (F_LUNVAL(ctx) != 0) ? " " : "",
451 (F_LUNVAL(ctx) != 0) ? " " : "",
452 (F_CPU(ctx)) ? " CPU" : "");
456 fprintf(stdout, " CPU ");
457 for (i = 0; i < min(CTL_STAT_LUN_BITS,
458 ctx->num_luns); i++) {
462 * Obviously this won't work with
463 * LUN numbers greater than a signed
466 lun = (int)ctx->cur_lun_stats[i
469 if (bit_test(ctx->lun_mask, lun) == 0)
471 fprintf(stdout, "%15.6s%d %s",
473 (F_LUNVAL(ctx) != 0) ? " " : "");
476 fprintf(stdout, "\n");
478 for (i = 0; i < hdr_devs; i++)
479 fprintf(stdout, "%s %sKB/t %s MB/s ",
480 ((F_CPU(ctx) != 0) && (i == 0) &&
481 (F_TOTALS(ctx) == 0)) ? " " : "",
482 (F_LUNVAL(ctx) != 0) ? " ms " : "",
483 (F_DMA(ctx) == 0) ? "tps" : "dps");
484 fprintf(stdout, "\n");
485 ctx->header_interval = 20;
489 if (F_TOTALS(ctx) != 0) {
490 long double mbsec[3];
491 long double kb_per_transfer[3];
492 long double transfers_per_sec[3];
493 long double ms_per_transfer[3];
494 long double ms_per_dma[3];
495 long double dmas_per_sec[3];
497 for (i = 0; i < 3; i++)
498 ctx->prev_total_stats[i] = ctx->cur_total_stats[i];
500 memset(&ctx->cur_total_stats, 0, sizeof(ctx->cur_total_stats));
502 /* Use macros to make the next loop more readable. */
503 #define ADD_STATS_BYTES(st, p, i, j) \
504 ctx->cur_total_stats[st].ports[p].bytes[j] += \
505 ctx->cur_lun_stats[i].ports[p].bytes[j]
506 #define ADD_STATS_OPERATIONS(st, p, i, j) \
507 ctx->cur_total_stats[st].ports[p].operations[j] += \
508 ctx->cur_lun_stats[i].ports[p].operations[j]
509 #define ADD_STATS_NUM_DMAS(st, p, i, j) \
510 ctx->cur_total_stats[st].ports[p].num_dmas[j] += \
511 ctx->cur_lun_stats[i].ports[p].num_dmas[j]
512 #define ADD_STATS_TIME(st, p, i, j) \
513 bintime_add(&ctx->cur_total_stats[st].ports[p].time[j], \
514 &ctx->cur_lun_stats[i].ports[p].time[j])
515 #define ADD_STATS_DMA_TIME(st, p, i, j) \
516 bintime_add(&ctx->cur_total_stats[st].ports[p].dma_time[j], \
517 &ctx->cur_lun_stats[i].ports[p].dma_time[j])
519 for (i = 0; i < ctx->num_luns; i++) {
520 for (port = 0; port < CTL_MAX_PORTS; port++) {
521 for (j = 0; j < CTL_STATS_NUM_TYPES; j++) {
522 ADD_STATS_BYTES(2, port, i, j);
523 ADD_STATS_OPERATIONS(2, port, i, j);
524 ADD_STATS_NUM_DMAS(2, port, i, j);
525 ADD_STATS_TIME(2, port, i, j);
526 ADD_STATS_DMA_TIME(2, port, i, j);
528 ADD_STATS_BYTES(0, port, i, CTL_STATS_READ);
529 ADD_STATS_OPERATIONS(0, port, i,
531 ADD_STATS_NUM_DMAS(0, port, i, CTL_STATS_READ);
532 ADD_STATS_TIME(0, port, i, CTL_STATS_READ);
533 ADD_STATS_DMA_TIME(0, port, i, CTL_STATS_READ);
535 ADD_STATS_BYTES(1, port, i, CTL_STATS_WRITE);
536 ADD_STATS_OPERATIONS(1, port, i,
538 ADD_STATS_NUM_DMAS(1, port, i, CTL_STATS_WRITE);
539 ADD_STATS_TIME(1, port, i, CTL_STATS_WRITE);
540 ADD_STATS_DMA_TIME(1, port, i, CTL_STATS_WRITE);
544 for (i = 0; i < 3; i++) {
545 compute_stats(&ctx->cur_total_stats[i],
546 F_FIRST(ctx) ? NULL : &ctx->prev_total_stats[i],
547 etime, &mbsec[i], &kb_per_transfer[i],
548 &transfers_per_sec[i],
549 &ms_per_transfer[i], &ms_per_dma[i],
552 fprintf(stdout, " %2.2Lf",
554 else if (F_LUNVAL(ctx) != 0)
555 fprintf(stdout, " %2.2Lf",
557 fprintf(stdout, " %5.2Lf %3.0Lf %5.2Lf ",
559 (F_DMA(ctx) == 0) ? transfers_per_sec[i] :
560 dmas_per_sec[i], mbsec[i]);
563 fprintf(stdout, " %5.1Lf%%", cpu_percentage);
566 fprintf(stdout, "%5.1Lf%% ", cpu_percentage);
568 for (i = 0; i < min(CTL_STAT_LUN_BITS, ctx->num_luns); i++) {
569 long double mbsec, kb_per_transfer;
570 long double transfers_per_sec;
571 long double ms_per_transfer;
572 long double ms_per_dma;
573 long double dmas_per_sec;
575 if (bit_test(ctx->lun_mask,
576 (int)ctx->cur_lun_stats[i].lun_number) == 0)
578 compute_stats(&ctx->cur_lun_stats[i], F_FIRST(ctx) ?
579 NULL : &ctx->prev_lun_stats[i], etime,
580 &mbsec, &kb_per_transfer,
581 &transfers_per_sec, &ms_per_transfer,
582 &ms_per_dma, &dmas_per_sec);
584 fprintf(stdout, " %2.2Lf",
586 else if (F_LUNVAL(ctx) != 0)
587 fprintf(stdout, " %2.2Lf",
589 fprintf(stdout, " %5.2Lf %3.0Lf %5.2Lf ",
590 kb_per_transfer, (F_DMA(ctx) == 0) ?
591 transfers_per_sec : dmas_per_sec, mbsec);
597 main(int argc, char **argv)
603 struct ctlstat_context ctx;
609 memset(&ctx, 0, sizeof(ctx));
611 ctx.mode = CTLSTAT_MODE_STANDARD;
612 ctx.flags |= CTLSTAT_FLAG_CPU;
613 ctx.flags |= CTLSTAT_FLAG_FIRST_RUN;
614 ctx.flags |= CTLSTAT_FLAG_HEADER;
616 while ((c = getopt(argc, argv, ctlstat_opts)) != -1) {
619 ctx.flags &= ~CTLSTAT_FLAG_CPU;
622 count = atoi(optarg);
625 ctx.flags |= CTLSTAT_FLAG_DMA_TIME;
628 ctx.mode = CTLSTAT_MODE_DUMP;
632 ctx.flags &= ~CTLSTAT_FLAG_HEADER;
635 ctx.mode = CTLSTAT_MODE_JSON;
641 cur_lun = atoi(optarg);
642 if (cur_lun > CTL_STAT_LUN_BITS)
643 errx(1, "Invalid LUN number %d", cur_lun);
645 bit_ffs(ctx.lun_mask, CTL_STAT_LUN_BITS, &set_lun);
650 bit_set(ctx.lun_mask, cur_lun);
654 ctx.numdevs = atoi(optarg);
657 ctx.flags |= CTLSTAT_FLAG_TOTALS;
661 waittime = atoi(optarg);
671 bit_ffs(ctx.lun_mask, CTL_STAT_LUN_BITS, &set_lun);
674 && (set_lun != -1)) {
675 errx(1, "Total Mode (-t) is incompatible with individual "
677 } else if (set_lun == -1) {
679 * Note that this just selects the first N LUNs to display,
680 * but at this point we have no knoweledge of which LUN
681 * numbers actually exist. So we may select LUNs that
684 bit_nset(ctx.lun_mask, 0, min(ctx.numdevs - 1,
685 CTL_STAT_LUN_BITS - 1));
688 if ((fd = open(CTL_DEFAULT_DEV, O_RDWR)) == -1)
689 err(1, "cannot open %s", CTL_DEFAULT_DEV);
692 ctx.tmp_lun_stats = ctx.prev_lun_stats;
693 ctx.prev_lun_stats = ctx.cur_lun_stats;
694 ctx.cur_lun_stats = ctx.tmp_lun_stats;
695 ctx.prev_time = ctx.cur_time;
696 ctx.prev_cpu = ctx.cur_cpu;
697 if (getstats(fd, &ctx.num_luns, &ctx.cur_lun_stats,
698 &ctx.cur_time, &ctx.flags) != 0)
699 errx(1, "error returned from getstats()");
702 case CTLSTAT_MODE_STANDARD:
703 ctlstat_standard(&ctx);
705 case CTLSTAT_MODE_DUMP:
708 case CTLSTAT_MODE_JSON:
715 fprintf(stdout, "\n");
716 ctx.flags &= ~CTLSTAT_FLAG_FIRST_RUN;