2 * Copyright (c) 2004, 2008, 2009 Silicon Graphics International Corp.
3 * Copyright (c) 2017 Alexander Motin <mav@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * substantially similar to the "NO WARRANTY" disclaimer below
14 * ("Disclaimer") and any redistribution must be conditioned upon
15 * including a substantially similar Disclaimer requirement for further
16 * binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGES.
31 * $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.c#4 $
34 * CAM Target Layer statistics program
36 * Authors: Ken Merry <ken@FreeBSD.org>, Will Andrews <will@FreeBSD.org>
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/ioctl.h>
43 #include <sys/types.h>
44 #include <sys/param.h>
46 #include <sys/sysctl.h>
47 #include <sys/resource.h>
48 #include <sys/queue.h>
49 #include <sys/callout.h>
60 #include <bitstring.h>
61 #include <cam/scsi/scsi_all.h>
62 #include <cam/ctl/ctl.h>
63 #include <cam/ctl/ctl_io.h>
64 #include <cam/ctl/ctl_scsi_all.h>
65 #include <cam/ctl/ctl_util.h>
66 #include <cam/ctl/ctl_backend.h>
67 #include <cam/ctl/ctl_ioctl.h>
70 * The default amount of space we allocate for stats storage space.
71 * We dynamically allocate more if needed.
73 #define CTL_STAT_NUM_ITEMS 256
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_BITS 1024L
82 static const char *ctlstat_opts = "Cc:Ddhjl:n:p: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_TIME_VALID (1 << 5)
106 #define CTLSTAT_FLAG_MASK (1 << 6)
107 #define CTLSTAT_FLAG_LUNS (1 << 7)
108 #define CTLSTAT_FLAG_PORTS (1 << 8)
109 #define F_CPU(ctx) ((ctx)->flags & CTLSTAT_FLAG_CPU)
110 #define F_HDR(ctx) ((ctx)->flags & CTLSTAT_FLAG_HEADER)
111 #define F_FIRST(ctx) ((ctx)->flags & CTLSTAT_FLAG_FIRST_RUN)
112 #define F_TOTALS(ctx) ((ctx)->flags & CTLSTAT_FLAG_TOTALS)
113 #define F_DMA(ctx) ((ctx)->flags & CTLSTAT_FLAG_DMA_TIME)
114 #define F_TIMEVAL(ctx) ((ctx)->flags & CTLSTAT_FLAG_TIME_VALID)
115 #define F_MASK(ctx) ((ctx)->flags & CTLSTAT_FLAG_MASK)
116 #define F_LUNS(ctx) ((ctx)->flags & CTLSTAT_FLAG_LUNS)
117 #define F_PORTS(ctx) ((ctx)->flags & CTLSTAT_FLAG_PORTS)
119 struct ctlstat_context {
120 ctlstat_mode_types mode;
122 struct ctl_io_stats *cur_stats, *prev_stats;
123 struct ctl_io_stats cur_total_stats[3], prev_total_stats[3];
124 struct timespec cur_time, prev_time;
125 struct ctl_cpu_stats cur_cpu, prev_cpu;
126 uint64_t cur_total_jiffies, prev_total_jiffies;
127 uint64_t cur_idle, prev_idle;
128 bitstr_t bit_decl(item_mask, CTL_STAT_BITS);
129 int cur_items, prev_items;
130 int cur_alloc, prev_alloc;
136 #define min(x,y) (((x) < (y)) ? (x) : (y))
139 static void usage(int error);
140 static int getstats(int fd, int *alloc_items, int *num_items,
141 struct ctl_io_stats **xstats, struct timespec *cur_time, int *time_valid);
142 static int getcpu(struct ctl_cpu_stats *cpu_stats);
143 static void compute_stats(struct ctl_io_stats *cur_stats,
144 struct ctl_io_stats *prev_stats,
145 long double etime, long double *mbsec,
146 long double *kb_per_transfer,
147 long double *transfers_per_second,
148 long double *ms_per_transfer,
149 long double *ms_per_dma,
150 long double *dmas_per_second);
155 fputs(ctlstat_usage, error ? stderr : stdout);
159 getstats(int fd, int *alloc_items, int *num_items, struct ctl_io_stats **stats,
160 struct timespec *cur_time, int *flags)
162 struct ctl_get_io_stats get_stats;
163 int more_space_count = 0;
165 if (*alloc_items == 0)
166 *alloc_items = CTL_STAT_NUM_ITEMS;
169 *stats = malloc(sizeof(**stats) * *alloc_items);
171 memset(&get_stats, 0, sizeof(get_stats));
172 get_stats.alloc_len = *alloc_items * sizeof(**stats);
173 memset(*stats, 0, get_stats.alloc_len);
174 get_stats.stats = *stats;
176 if (ioctl(fd, (*flags & CTLSTAT_FLAG_PORTS) ? CTL_GET_PORT_STATS :
177 CTL_GET_LUN_STATS, &get_stats) == -1)
178 err(1, "CTL_GET_*_STATS ioctl returned error");
180 switch (get_stats.status) {
184 err(1, "CTL_GET_*_STATS ioctl returned CTL_SS_ERROR");
186 case CTL_SS_NEED_MORE_SPACE:
187 if (more_space_count >= 2)
188 errx(1, "CTL_GET_*_STATS returned NEED_MORE_SPACE again");
189 *alloc_items = get_stats.num_items * 5 / 4;
194 break; /* NOTREACHED */
196 errx(1, "CTL_GET_*_STATS ioctl returned unknown status %d",
201 *num_items = get_stats.fill_len / sizeof(**stats);
202 cur_time->tv_sec = get_stats.timestamp.tv_sec;
203 cur_time->tv_nsec = get_stats.timestamp.tv_nsec;
204 if (get_stats.flags & CTL_STATS_FLAG_TIME_VALID)
205 *flags |= CTLSTAT_FLAG_TIME_VALID;
207 *flags &= ~CTLSTAT_FLAG_TIME_VALID;
213 getcpu(struct ctl_cpu_stats *cpu_stats)
215 long cp_time[CPUSTATES];
218 cplen = sizeof(cp_time);
220 if (sysctlbyname("kern.cp_time", &cp_time, &cplen, NULL, 0) == -1) {
221 warn("sysctlbyname(kern.cp_time...) failed");
225 cpu_stats->user = cp_time[CP_USER];
226 cpu_stats->nice = cp_time[CP_NICE];
227 cpu_stats->system = cp_time[CP_SYS];
228 cpu_stats->intr = cp_time[CP_INTR];
229 cpu_stats->idle = cp_time[CP_IDLE];
235 compute_stats(struct ctl_io_stats *cur_stats,
236 struct ctl_io_stats *prev_stats, long double etime,
237 long double *mbsec, long double *kb_per_transfer,
238 long double *transfers_per_second, long double *ms_per_transfer,
239 long double *ms_per_dma, long double *dmas_per_second)
241 uint64_t total_bytes = 0, total_operations = 0, total_dmas = 0;
242 struct bintime total_time_bt, total_dma_bt;
243 struct timespec total_time_ts, total_dma_ts;
246 bzero(&total_time_bt, sizeof(total_time_bt));
247 bzero(&total_dma_bt, sizeof(total_dma_bt));
248 bzero(&total_time_ts, sizeof(total_time_ts));
249 bzero(&total_dma_ts, sizeof(total_dma_ts));
250 for (i = 0; i < CTL_STATS_NUM_TYPES; i++) {
251 total_bytes += cur_stats->bytes[i];
252 total_operations += cur_stats->operations[i];
253 total_dmas += cur_stats->dmas[i];
254 bintime_add(&total_time_bt, &cur_stats->time[i]);
255 bintime_add(&total_dma_bt, &cur_stats->dma_time[i]);
256 if (prev_stats != NULL) {
257 total_bytes -= prev_stats->bytes[i];
258 total_operations -= prev_stats->operations[i];
259 total_dmas -= prev_stats->dmas[i];
260 bintime_sub(&total_time_bt, &prev_stats->time[i]);
261 bintime_sub(&total_dma_bt, &prev_stats->dma_time[i]);
265 *mbsec = total_bytes;
266 *mbsec /= 1024 * 1024;
271 *kb_per_transfer = total_bytes;
272 *kb_per_transfer /= 1024;
273 if (total_operations > 0)
274 *kb_per_transfer /= total_operations;
276 *kb_per_transfer = 0;
277 *transfers_per_second = total_operations;
278 *dmas_per_second = total_dmas;
280 *transfers_per_second /= etime;
281 *dmas_per_second /= etime;
283 *transfers_per_second = 0;
284 *dmas_per_second = 0;
287 bintime2timespec(&total_time_bt, &total_time_ts);
288 bintime2timespec(&total_dma_bt, &total_dma_ts);
289 if (total_operations > 0) {
291 * Convert the timespec to milliseconds.
293 *ms_per_transfer = total_time_ts.tv_sec * 1000;
294 *ms_per_transfer += total_time_ts.tv_nsec / 1000000;
295 *ms_per_transfer /= total_operations;
297 *ms_per_transfer = 0;
299 if (total_dmas > 0) {
301 * Convert the timespec to milliseconds.
303 *ms_per_dma = total_dma_ts.tv_sec * 1000;
304 *ms_per_dma += total_dma_ts.tv_nsec / 1000000;
305 *ms_per_dma /= total_dmas;
310 /* The dump_stats() and json_stats() functions perform essentially the same
311 * purpose, but dump the statistics in different formats. JSON is more
312 * conducive to programming, however.
315 #define PRINT_BINTIME(bt) \
316 printf("%jd.%06ju", (intmax_t)(bt).sec, \
317 (uintmax_t)(((bt).frac >> 32) * 1000000 >> 32))
318 static const char *iotypes[] = {"NO IO", "READ", "WRITE"};
321 ctlstat_dump(struct ctlstat_context *ctx)
324 struct ctl_io_stats *stats = ctx->cur_stats;
326 for (i = 0; i < ctx->cur_items;i++) {
327 if (F_MASK(ctx) && bit_test(ctx->item_mask, i) == 0)
329 printf("%s %d\n", F_PORTS(ctx) ? "port" : "lun", stats[i].item);
330 for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) {
331 printf(" io type %d (%s)\n", iotype, iotypes[iotype]);
332 printf(" bytes %ju\n", (uintmax_t)
333 stats[i].bytes[iotype]);
334 printf(" operations %ju\n", (uintmax_t)
335 stats[i].operations[iotype]);
336 printf(" dmas %ju\n", (uintmax_t)
337 stats[i].dmas[iotype]);
339 PRINT_BINTIME(stats[i].time[iotype]);
340 printf("\n dma time ");
341 PRINT_BINTIME(stats[i].dma_time[iotype]);
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 = 0; i < ctx->cur_items; i++) {
354 if (F_MASK(ctx) && bit_test(ctx->item_mask, i) == 0)
356 printf("{\"num\":%d,\"io\":[",
358 for (iotype = 0; iotype < CTL_STATS_NUM_TYPES; iotype++) {
359 printf("{\"type\":\"%s\",", iotypes[iotype]);
360 printf("\"bytes\":%ju,", (uintmax_t)
361 stats[i].bytes[iotype]);
362 printf("\"operations\":%ju,", (uintmax_t)
363 stats[i].operations[iotype]);
364 printf("\"dmas\":%ju,", (uintmax_t)
365 stats[i].dmas[iotype]);
366 printf("\"io time\":");
367 PRINT_BINTIME(stats[i].time[iotype]);
368 printf(",\"dma time\":");
369 PRINT_BINTIME(stats[i].dma_time[iotype]);
371 if (iotype < (CTL_STATS_NUM_TYPES - 1))
372 printf(","); /* continue io array */
375 if (i < (ctx->cur_items - 1))
376 printf(","); /* continue lun array */
382 ctlstat_standard(struct ctlstat_context *ctx) {
384 uint64_t delta_jiffies, delta_idle;
385 long double cpu_percentage;
390 if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0))
391 errx(1, "error returned from getcpu()");
393 etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec +
394 (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9;
397 ctx->prev_total_jiffies = ctx->cur_total_jiffies;
398 ctx->cur_total_jiffies = ctx->cur_cpu.user +
399 ctx->cur_cpu.nice + ctx->cur_cpu.system +
400 ctx->cur_cpu.intr + ctx->cur_cpu.idle;
401 delta_jiffies = ctx->cur_total_jiffies;
402 if (F_FIRST(ctx) == 0)
403 delta_jiffies -= ctx->prev_total_jiffies;
404 ctx->prev_idle = ctx->cur_idle;
405 ctx->cur_idle = ctx->cur_cpu.idle;
406 delta_idle = ctx->cur_idle - ctx->prev_idle;
408 cpu_percentage = delta_jiffies - delta_idle;
409 cpu_percentage /= delta_jiffies;
410 cpu_percentage *= 100;
414 ctx->header_interval--;
415 if (ctx->header_interval <= 0) {
421 fprintf(stdout, " CPU");
423 fprintf(stdout, "%s Read %s"
425 (F_TIMEVAL(ctx) != 0) ? " " : "",
426 (F_TIMEVAL(ctx) != 0) ? " " : "",
427 (F_TIMEVAL(ctx) != 0) ? " " : "");
430 for (i = 0; i < min(CTL_STAT_BITS,
431 ctx->cur_items); i++) {
435 * Obviously this won't work with
436 * LUN numbers greater than a signed
439 item = (int)ctx->cur_stats[i].item;
442 bit_test(ctx->item_mask, item) == 0)
444 fprintf(stdout, "%15.6s%d %s",
445 F_PORTS(ctx) ? "port" : "lun", item,
446 (F_TIMEVAL(ctx) != 0) ? " " : "");
449 fprintf(stdout, "\n");
452 fprintf(stdout, " ");
453 for (i = 0; i < hdr_devs; 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 = 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);
573 main(int argc, char **argv)
578 struct ctlstat_context ctx;
579 struct ctl_io_stats *tmp_stats;
585 memset(&ctx, 0, sizeof(ctx));
587 ctx.mode = CTLSTAT_MODE_STANDARD;
588 ctx.flags |= CTLSTAT_FLAG_CPU;
589 ctx.flags |= CTLSTAT_FLAG_FIRST_RUN;
590 ctx.flags |= CTLSTAT_FLAG_HEADER;
592 while ((c = getopt(argc, argv, ctlstat_opts)) != -1) {
595 ctx.flags &= ~CTLSTAT_FLAG_CPU;
598 count = atoi(optarg);
601 ctx.flags |= CTLSTAT_FLAG_DMA_TIME;
604 ctx.mode = CTLSTAT_MODE_DUMP;
608 ctx.flags &= ~CTLSTAT_FLAG_HEADER;
611 ctx.mode = CTLSTAT_MODE_JSON;
617 cur_lun = atoi(optarg);
618 if (cur_lun > CTL_STAT_BITS)
619 errx(1, "Invalid LUN number %d", cur_lun);
625 bit_set(ctx.item_mask, cur_lun);
626 ctx.flags |= CTLSTAT_FLAG_MASK;
627 ctx.flags |= CTLSTAT_FLAG_LUNS;
631 ctx.numdevs = atoi(optarg);
636 cur_port = atoi(optarg);
637 if (cur_port > CTL_STAT_BITS)
638 errx(1, "Invalid port number %d", cur_port);
644 bit_set(ctx.item_mask, cur_port);
645 ctx.flags |= CTLSTAT_FLAG_MASK;
646 ctx.flags |= CTLSTAT_FLAG_PORTS;
650 ctx.flags |= CTLSTAT_FLAG_TOTALS;
653 waittime = atoi(optarg);
663 if (F_LUNS(&ctx) && F_PORTS(&ctx))
664 errx(1, "Options -p and -l are exclusive.");
666 if (!F_LUNS(&ctx) && !F_PORTS(&ctx)) {
668 ctx.flags |= CTLSTAT_FLAG_PORTS;
670 ctx.flags |= CTLSTAT_FLAG_LUNS;
673 if (!F_TOTALS(&ctx) && !F_MASK(&ctx)) {
675 * Note that this just selects the first N LUNs to display,
676 * but at this point we have no knoweledge of which LUN
677 * numbers actually exist. So we may select LUNs that
680 bit_nset(ctx.item_mask, 0, min(ctx.numdevs - 1,
682 ctx.flags |= CTLSTAT_FLAG_MASK;
685 if ((fd = open(CTL_DEFAULT_DEV, O_RDWR)) == -1)
686 err(1, "cannot open %s", CTL_DEFAULT_DEV);
689 tmp_stats = ctx.prev_stats;
690 ctx.prev_stats = ctx.cur_stats;
691 ctx.cur_stats = tmp_stats;
693 ctx.prev_alloc = ctx.cur_alloc;
696 ctx.prev_items = ctx.cur_items;
698 ctx.prev_time = ctx.cur_time;
699 ctx.prev_cpu = ctx.cur_cpu;
700 if (getstats(fd, &ctx.cur_alloc, &ctx.cur_items,
701 &ctx.cur_stats, &ctx.cur_time, &ctx.flags) != 0)
702 errx(1, "error returned from getstats()");
705 case CTLSTAT_MODE_STANDARD:
706 ctlstat_standard(&ctx);
708 case CTLSTAT_MODE_DUMP:
711 case CTLSTAT_MODE_JSON:
718 fprintf(stdout, "\n");
719 ctx.flags &= ~CTLSTAT_FLAG_FIRST_RUN;