2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp.
5 * Copyright (c) 2017 Alexander Motin <mav@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
15 * substantially similar to the "NO WARRANTY" disclaimer below
16 * ("Disclaimer") and any redistribution must be conditioned upon
17 * including a substantially similar Disclaimer requirement for further
18 * binary redistribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGES.
33 * $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.c#4 $
36 * CAM Target Layer statistics program
38 * Authors: Ken Merry <ken@FreeBSD.org>, Will Andrews <will@FreeBSD.org>
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
44 #include <sys/ioctl.h>
45 #include <sys/types.h>
46 #include <sys/param.h>
48 #include <sys/sysctl.h>
49 #include <sys/resource.h>
50 #include <sys/queue.h>
51 #include <sys/callout.h>
62 #include <bitstring.h>
63 #include <cam/scsi/scsi_all.h>
64 #include <cam/ctl/ctl.h>
65 #include <cam/ctl/ctl_io.h>
66 #include <cam/ctl/ctl_scsi_all.h>
67 #include <cam/ctl/ctl_util.h>
68 #include <cam/ctl/ctl_backend.h>
69 #include <cam/ctl/ctl_ioctl.h>
72 * The default amount of space we allocate for stats storage space.
73 * We dynamically allocate more if needed.
75 #define CTL_STAT_NUM_ITEMS 256
77 static int ctl_stat_bits;
79 static const char *ctlstat_opts = "Cc:Ddhjl:n:p:tw:";
80 static const char *ctlstat_usage = "Usage: ctlstat [-CDdjht] [-l lunnum]"
81 "[-c count] [-n numdevs] [-w wait]\n";
83 struct ctl_cpu_stats {
92 CTLSTAT_MODE_STANDARD,
97 #define CTLSTAT_FLAG_CPU (1 << 0)
98 #define CTLSTAT_FLAG_HEADER (1 << 1)
99 #define CTLSTAT_FLAG_FIRST_RUN (1 << 2)
100 #define CTLSTAT_FLAG_TOTALS (1 << 3)
101 #define CTLSTAT_FLAG_DMA_TIME (1 << 4)
102 #define CTLSTAT_FLAG_TIME_VALID (1 << 5)
103 #define CTLSTAT_FLAG_MASK (1 << 6)
104 #define CTLSTAT_FLAG_LUNS (1 << 7)
105 #define CTLSTAT_FLAG_PORTS (1 << 8)
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_TIMEVAL(ctx) ((ctx)->flags & CTLSTAT_FLAG_TIME_VALID)
112 #define F_MASK(ctx) ((ctx)->flags & CTLSTAT_FLAG_MASK)
113 #define F_LUNS(ctx) ((ctx)->flags & CTLSTAT_FLAG_LUNS)
114 #define F_PORTS(ctx) ((ctx)->flags & CTLSTAT_FLAG_PORTS)
116 struct ctlstat_context {
117 ctlstat_mode_types mode;
119 struct ctl_io_stats *cur_stats, *prev_stats;
120 struct ctl_io_stats cur_total_stats[3], prev_total_stats[3];
121 struct timespec cur_time, prev_time;
122 struct ctl_cpu_stats cur_cpu, prev_cpu;
123 uint64_t cur_total_jiffies, prev_total_jiffies;
124 uint64_t cur_idle, prev_idle;
126 int cur_items, prev_items;
127 int cur_alloc, prev_alloc;
133 #define min(x,y) (((x) < (y)) ? (x) : (y))
136 static void usage(int error);
137 static int getstats(int fd, int *alloc_items, int *num_items,
138 struct ctl_io_stats **xstats, struct timespec *cur_time, int *time_valid);
139 static int getcpu(struct ctl_cpu_stats *cpu_stats);
140 static void compute_stats(struct ctl_io_stats *cur_stats,
141 struct ctl_io_stats *prev_stats,
142 long double etime, long double *mbsec,
143 long double *kb_per_transfer,
144 long double *transfers_per_second,
145 long double *ms_per_transfer,
146 long double *ms_per_dma,
147 long double *dmas_per_second);
152 fputs(ctlstat_usage, error ? stderr : stdout);
156 getstats(int fd, int *alloc_items, int *num_items, struct ctl_io_stats **stats,
157 struct timespec *cur_time, int *flags)
159 struct ctl_get_io_stats get_stats;
160 int more_space_count = 0;
162 if (*alloc_items == 0)
163 *alloc_items = CTL_STAT_NUM_ITEMS;
166 *stats = malloc(sizeof(**stats) * *alloc_items);
168 memset(&get_stats, 0, sizeof(get_stats));
169 get_stats.alloc_len = *alloc_items * sizeof(**stats);
170 memset(*stats, 0, get_stats.alloc_len);
171 get_stats.stats = *stats;
173 if (ioctl(fd, (*flags & CTLSTAT_FLAG_PORTS) ? CTL_GET_PORT_STATS :
174 CTL_GET_LUN_STATS, &get_stats) == -1)
175 err(1, "CTL_GET_*_STATS ioctl returned error");
177 switch (get_stats.status) {
181 err(1, "CTL_GET_*_STATS ioctl returned CTL_SS_ERROR");
183 case CTL_SS_NEED_MORE_SPACE:
184 if (more_space_count >= 2)
185 errx(1, "CTL_GET_*_STATS returned NEED_MORE_SPACE again");
186 *alloc_items = get_stats.num_items * 5 / 4;
191 break; /* NOTREACHED */
193 errx(1, "CTL_GET_*_STATS ioctl returned unknown status %d",
198 *num_items = get_stats.fill_len / sizeof(**stats);
199 cur_time->tv_sec = get_stats.timestamp.tv_sec;
200 cur_time->tv_nsec = get_stats.timestamp.tv_nsec;
201 if (get_stats.flags & CTL_STATS_FLAG_TIME_VALID)
202 *flags |= CTLSTAT_FLAG_TIME_VALID;
204 *flags &= ~CTLSTAT_FLAG_TIME_VALID;
210 getcpu(struct ctl_cpu_stats *cpu_stats)
212 long cp_time[CPUSTATES];
215 cplen = sizeof(cp_time);
217 if (sysctlbyname("kern.cp_time", &cp_time, &cplen, NULL, 0) == -1) {
218 warn("sysctlbyname(kern.cp_time...) failed");
222 cpu_stats->user = cp_time[CP_USER];
223 cpu_stats->nice = cp_time[CP_NICE];
224 cpu_stats->system = cp_time[CP_SYS];
225 cpu_stats->intr = cp_time[CP_INTR];
226 cpu_stats->idle = cp_time[CP_IDLE];
232 compute_stats(struct ctl_io_stats *cur_stats,
233 struct ctl_io_stats *prev_stats, long double etime,
234 long double *mbsec, long double *kb_per_transfer,
235 long double *transfers_per_second, long double *ms_per_transfer,
236 long double *ms_per_dma, long double *dmas_per_second)
238 uint64_t total_bytes = 0, total_operations = 0, total_dmas = 0;
239 struct bintime total_time_bt, total_dma_bt;
240 struct timespec total_time_ts, total_dma_ts;
243 bzero(&total_time_bt, sizeof(total_time_bt));
244 bzero(&total_dma_bt, sizeof(total_dma_bt));
245 bzero(&total_time_ts, sizeof(total_time_ts));
246 bzero(&total_dma_ts, sizeof(total_dma_ts));
247 for (i = 0; i < CTL_STATS_NUM_TYPES; i++) {
248 total_bytes += cur_stats->bytes[i];
249 total_operations += cur_stats->operations[i];
250 total_dmas += cur_stats->dmas[i];
251 bintime_add(&total_time_bt, &cur_stats->time[i]);
252 bintime_add(&total_dma_bt, &cur_stats->dma_time[i]);
253 if (prev_stats != NULL) {
254 total_bytes -= prev_stats->bytes[i];
255 total_operations -= prev_stats->operations[i];
256 total_dmas -= prev_stats->dmas[i];
257 bintime_sub(&total_time_bt, &prev_stats->time[i]);
258 bintime_sub(&total_dma_bt, &prev_stats->dma_time[i]);
262 *mbsec = total_bytes;
263 *mbsec /= 1024 * 1024;
268 *kb_per_transfer = total_bytes;
269 *kb_per_transfer /= 1024;
270 if (total_operations > 0)
271 *kb_per_transfer /= total_operations;
273 *kb_per_transfer = 0;
274 *transfers_per_second = total_operations;
275 *dmas_per_second = total_dmas;
277 *transfers_per_second /= etime;
278 *dmas_per_second /= etime;
280 *transfers_per_second = 0;
281 *dmas_per_second = 0;
284 bintime2timespec(&total_time_bt, &total_time_ts);
285 bintime2timespec(&total_dma_bt, &total_dma_ts);
286 if (total_operations > 0) {
288 * Convert the timespec to milliseconds.
290 *ms_per_transfer = total_time_ts.tv_sec * 1000;
291 *ms_per_transfer += total_time_ts.tv_nsec / 1000000;
292 *ms_per_transfer /= total_operations;
294 *ms_per_transfer = 0;
296 if (total_dmas > 0) {
298 * Convert the timespec to milliseconds.
300 *ms_per_dma = total_dma_ts.tv_sec * 1000;
301 *ms_per_dma += total_dma_ts.tv_nsec / 1000000;
302 *ms_per_dma /= total_dmas;
307 /* The dump_stats() and json_stats() functions perform essentially the same
308 * purpose, but dump the statistics in different formats. JSON is more
309 * conducive to programming, however.
312 #define PRINT_BINTIME(bt) \
313 printf("%jd.%06ju", (intmax_t)(bt).sec, \
314 (uintmax_t)(((bt).frac >> 32) * 1000000 >> 32))
315 static const char *iotypes[] = {"NO IO", "READ", "WRITE"};
318 ctlstat_dump(struct ctlstat_context *ctx)
321 struct ctl_io_stats *stats = ctx->cur_stats;
323 for (i = n = 0; i < ctx->cur_items;i++) {
324 if (F_MASK(ctx) && bit_test(ctx->item_mask,
325 (int)stats[i].item) == 0)
327 printf("%s %d\n", F_PORTS(ctx) ? "port" : "lun", stats[i].item);
328 for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) {
329 printf(" io type %d (%s)\n", iotype, iotypes[iotype]);
330 printf(" bytes %ju\n", (uintmax_t)
331 stats[i].bytes[iotype]);
332 printf(" operations %ju\n", (uintmax_t)
333 stats[i].operations[iotype]);
334 printf(" dmas %ju\n", (uintmax_t)
335 stats[i].dmas[iotype]);
337 PRINT_BINTIME(stats[i].time[iotype]);
338 printf("\n dma time ");
339 PRINT_BINTIME(stats[i].dma_time[iotype]);
342 if (++n >= ctx->numdevs)
348 ctlstat_json(struct ctlstat_context *ctx) {
350 struct ctl_io_stats *stats = ctx->cur_stats;
352 printf("{\"%s\":[", F_PORTS(ctx) ? "ports" : "luns");
353 for (i = n = 0; i < ctx->cur_items; i++) {
354 if (F_MASK(ctx) && bit_test(ctx->item_mask,
355 (int)stats[i].item) == 0)
357 printf("{\"num\":%d,\"io\":[",
359 for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) {
360 printf("{\"type\":\"%s\",", iotypes[iotype]);
361 printf("\"bytes\":%ju,", (uintmax_t)
362 stats[i].bytes[iotype]);
363 printf("\"operations\":%ju,", (uintmax_t)
364 stats[i].operations[iotype]);
365 printf("\"dmas\":%ju,", (uintmax_t)
366 stats[i].dmas[iotype]);
367 printf("\"io time\":");
368 PRINT_BINTIME(stats[i].time[iotype]);
369 printf(",\"dma time\":");
370 PRINT_BINTIME(stats[i].dma_time[iotype]);
372 if (iotype < (CTL_STATS_NUM_TYPES - 1))
373 printf(","); /* continue io array */
376 if (++n >= ctx->numdevs)
378 if (i < (ctx->cur_items - 1))
379 printf(","); /* continue lun array */
385 ctlstat_standard(struct ctlstat_context *ctx) {
387 uint64_t delta_jiffies, delta_idle;
388 long double cpu_percentage;
393 if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0))
394 errx(1, "error returned from getcpu()");
396 etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec +
397 (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9;
400 ctx->prev_total_jiffies = ctx->cur_total_jiffies;
401 ctx->cur_total_jiffies = ctx->cur_cpu.user +
402 ctx->cur_cpu.nice + ctx->cur_cpu.system +
403 ctx->cur_cpu.intr + ctx->cur_cpu.idle;
404 delta_jiffies = ctx->cur_total_jiffies;
405 if (F_FIRST(ctx) == 0)
406 delta_jiffies -= ctx->prev_total_jiffies;
407 ctx->prev_idle = ctx->cur_idle;
408 ctx->cur_idle = ctx->cur_cpu.idle;
409 delta_idle = ctx->cur_idle - ctx->prev_idle;
411 cpu_percentage = delta_jiffies - delta_idle;
412 cpu_percentage /= delta_jiffies;
413 cpu_percentage *= 100;
417 ctx->header_interval--;
418 if (ctx->header_interval <= 0) {
420 fprintf(stdout, " CPU");
422 fprintf(stdout, "%s Read %s"
424 (F_TIMEVAL(ctx) != 0) ? " " : "",
425 (F_TIMEVAL(ctx) != 0) ? " " : "",
426 (F_TIMEVAL(ctx) != 0) ? " " : "");
429 for (i = n = 0; i < min(ctl_stat_bits,
430 ctx->cur_items); i++) {
434 * Obviously this won't work with
435 * LUN numbers greater than a signed
438 item = (int)ctx->cur_stats[i].item;
441 bit_test(ctx->item_mask, item) == 0)
443 fprintf(stdout, "%15.6s%d %s",
444 F_PORTS(ctx) ? "port" : "lun", item,
445 (F_TIMEVAL(ctx) != 0) ? " " : "");
446 if (++n >= ctx->numdevs)
449 fprintf(stdout, "\n");
452 fprintf(stdout, " ");
453 for (i = 0; i < n; i++)
454 fprintf(stdout, "%s KB/t %s MB/s",
455 (F_TIMEVAL(ctx) != 0) ? " ms" : "",
456 (F_DMA(ctx) == 0) ? "tps" : "dps");
457 fprintf(stdout, "\n");
458 ctx->header_interval = 20;
463 fprintf(stdout, "%3.0Lf%%", cpu_percentage);
464 if (F_TOTALS(ctx) != 0) {
465 long double mbsec[3];
466 long double kb_per_transfer[3];
467 long double transfers_per_sec[3];
468 long double ms_per_transfer[3];
469 long double ms_per_dma[3];
470 long double dmas_per_sec[3];
472 for (i = 0; i < 3; i++)
473 ctx->prev_total_stats[i] = ctx->cur_total_stats[i];
475 memset(&ctx->cur_total_stats, 0, sizeof(ctx->cur_total_stats));
477 /* Use macros to make the next loop more readable. */
478 #define ADD_STATS_BYTES(st, i, j) \
479 ctx->cur_total_stats[st].bytes[j] += \
480 ctx->cur_stats[i].bytes[j]
481 #define ADD_STATS_OPERATIONS(st, i, j) \
482 ctx->cur_total_stats[st].operations[j] += \
483 ctx->cur_stats[i].operations[j]
484 #define ADD_STATS_DMAS(st, i, j) \
485 ctx->cur_total_stats[st].dmas[j] += \
486 ctx->cur_stats[i].dmas[j]
487 #define ADD_STATS_TIME(st, i, j) \
488 bintime_add(&ctx->cur_total_stats[st].time[j], \
489 &ctx->cur_stats[i].time[j])
490 #define ADD_STATS_DMA_TIME(st, i, j) \
491 bintime_add(&ctx->cur_total_stats[st].dma_time[j], \
492 &ctx->cur_stats[i].dma_time[j])
494 for (i = 0; i < ctx->cur_items; i++) {
495 if (F_MASK(ctx) && bit_test(ctx->item_mask,
496 (int)ctx->cur_stats[i].item) == 0)
498 for (j = 0; j < CTL_STATS_NUM_TYPES; j++) {
499 ADD_STATS_BYTES(2, i, j);
500 ADD_STATS_OPERATIONS(2, i, j);
501 ADD_STATS_DMAS(2, i, j);
502 ADD_STATS_TIME(2, i, j);
503 ADD_STATS_DMA_TIME(2, i, j);
505 ADD_STATS_BYTES(0, i, CTL_STATS_READ);
506 ADD_STATS_OPERATIONS(0, i, CTL_STATS_READ);
507 ADD_STATS_DMAS(0, i, CTL_STATS_READ);
508 ADD_STATS_TIME(0, i, CTL_STATS_READ);
509 ADD_STATS_DMA_TIME(0, i, CTL_STATS_READ);
511 ADD_STATS_BYTES(1, i, CTL_STATS_WRITE);
512 ADD_STATS_OPERATIONS(1, i, CTL_STATS_WRITE);
513 ADD_STATS_DMAS(1, i, CTL_STATS_WRITE);
514 ADD_STATS_TIME(1, i, CTL_STATS_WRITE);
515 ADD_STATS_DMA_TIME(1, i, CTL_STATS_WRITE);
518 for (i = 0; i < 3; i++) {
519 compute_stats(&ctx->cur_total_stats[i],
520 F_FIRST(ctx) ? NULL : &ctx->prev_total_stats[i],
521 etime, &mbsec[i], &kb_per_transfer[i],
522 &transfers_per_sec[i],
523 &ms_per_transfer[i], &ms_per_dma[i],
526 fprintf(stdout, " %5.1Lf",
528 else if (F_TIMEVAL(ctx) != 0)
529 fprintf(stdout, " %5.1Lf",
531 fprintf(stdout, " %4.0Lf %5.0Lf %4.0Lf",
533 (F_DMA(ctx) == 0) ? transfers_per_sec[i] :
534 dmas_per_sec[i], mbsec[i]);
537 for (i = n = 0; i < min(ctl_stat_bits, ctx->cur_items); i++) {
538 long double mbsec, kb_per_transfer;
539 long double transfers_per_sec;
540 long double ms_per_transfer;
541 long double ms_per_dma;
542 long double dmas_per_sec;
544 if (F_MASK(ctx) && bit_test(ctx->item_mask,
545 (int)ctx->cur_stats[i].item) == 0)
547 for (j = 0; j < ctx->prev_items; j++) {
548 if (ctx->prev_stats[j].item ==
549 ctx->cur_stats[i].item)
552 if (j >= ctx->prev_items)
554 compute_stats(&ctx->cur_stats[i],
555 j >= 0 ? &ctx->prev_stats[j] : NULL,
556 etime, &mbsec, &kb_per_transfer,
557 &transfers_per_sec, &ms_per_transfer,
558 &ms_per_dma, &dmas_per_sec);
560 fprintf(stdout, " %5.1Lf",
562 else if (F_TIMEVAL(ctx) != 0)
563 fprintf(stdout, " %5.1Lf",
565 fprintf(stdout, " %4.0Lf %5.0Lf %4.0Lf",
566 kb_per_transfer, (F_DMA(ctx) == 0) ?
567 transfers_per_sec : dmas_per_sec, mbsec);
568 if (++n >= ctx->numdevs)
575 main(int argc, char **argv)
581 struct ctlstat_context ctx;
582 struct ctl_io_stats *tmp_stats;
588 memset(&ctx, 0, sizeof(ctx));
590 ctx.mode = CTLSTAT_MODE_STANDARD;
591 ctx.flags |= CTLSTAT_FLAG_CPU;
592 ctx.flags |= CTLSTAT_FLAG_FIRST_RUN;
593 ctx.flags |= CTLSTAT_FLAG_HEADER;
595 size = sizeof(ctl_stat_bits);
596 if (sysctlbyname("kern.cam.ctl.max_luns", &ctl_stat_bits, &size, NULL,
598 /* Backward compatibility for where the sysctl wasn't exposed */
599 ctl_stat_bits = 1024;
601 ctx.item_mask = bit_alloc(ctl_stat_bits);
602 if (ctx.item_mask == NULL)
603 err(1, "bit_alloc() failed");
605 while ((c = getopt(argc, argv, ctlstat_opts)) != -1) {
608 ctx.flags &= ~CTLSTAT_FLAG_CPU;
611 count = atoi(optarg);
614 ctx.flags |= CTLSTAT_FLAG_DMA_TIME;
617 ctx.mode = CTLSTAT_MODE_DUMP;
621 ctx.flags &= ~CTLSTAT_FLAG_HEADER;
624 ctx.mode = CTLSTAT_MODE_JSON;
630 cur_lun = atoi(optarg);
631 if (cur_lun > ctl_stat_bits)
632 errx(1, "Invalid LUN number %d", cur_lun);
638 bit_set(ctx.item_mask, cur_lun);
639 ctx.flags |= CTLSTAT_FLAG_MASK;
640 ctx.flags |= CTLSTAT_FLAG_LUNS;
644 ctx.numdevs = atoi(optarg);
649 cur_port = atoi(optarg);
650 if (cur_port > ctl_stat_bits)
651 errx(1, "Invalid port number %d", cur_port);
657 bit_set(ctx.item_mask, cur_port);
658 ctx.flags |= CTLSTAT_FLAG_MASK;
659 ctx.flags |= CTLSTAT_FLAG_PORTS;
663 ctx.flags |= CTLSTAT_FLAG_TOTALS;
666 waittime = atoi(optarg);
676 if (F_LUNS(&ctx) && F_PORTS(&ctx))
677 errx(1, "Options -p and -l are exclusive.");
679 if (!F_LUNS(&ctx) && !F_PORTS(&ctx)) {
681 ctx.flags |= CTLSTAT_FLAG_PORTS;
683 ctx.flags |= CTLSTAT_FLAG_LUNS;
686 if ((fd = open(CTL_DEFAULT_DEV, O_RDWR)) == -1)
687 err(1, "cannot open %s", CTL_DEFAULT_DEV);
690 tmp_stats = ctx.prev_stats;
691 ctx.prev_stats = ctx.cur_stats;
692 ctx.cur_stats = tmp_stats;
694 ctx.prev_alloc = ctx.cur_alloc;
697 ctx.prev_items = ctx.cur_items;
699 ctx.prev_time = ctx.cur_time;
700 ctx.prev_cpu = ctx.cur_cpu;
701 if (getstats(fd, &ctx.cur_alloc, &ctx.cur_items,
702 &ctx.cur_stats, &ctx.cur_time, &ctx.flags) != 0)
703 errx(1, "error returned from getstats()");
706 case CTLSTAT_MODE_STANDARD:
707 ctlstat_standard(&ctx);
709 case CTLSTAT_MODE_DUMP:
712 case CTLSTAT_MODE_JSON:
719 fprintf(stdout, "\n");
721 ctx.flags &= ~CTLSTAT_FLAG_FIRST_RUN;