Lines Matching +full:wait +full:- +full:retry +full:- +full:us
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
33 * $Id: //depot/users/kenm/FreeBSD-test2/usr.bin/ctlstat/ctlstat.c#4 $
82 static const char *ctlstat_usage = "Usage: ctlstat [-CDPdjht] [-l lunnum]"
83 "[-c count] [-n numdevs] [-w wait]\n";
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)
178 retry: in getstats()
188 &get_stats) == -1) in getstats()
204 goto retry; in getstats()
213 cur_time->tv_sec = get_stats.timestamp.tv_sec; in getstats()
214 cur_time->tv_nsec = get_stats.timestamp.tv_nsec; in getstats()
231 if (sysctlbyname("kern.cp_time", &cp_time, &cplen, NULL, 0) == -1) { in getcpu()
236 cpu_stats->user = cp_time[CP_USER]; in getcpu()
237 cpu_stats->nice = cp_time[CP_NICE]; in getcpu()
238 cpu_stats->system = cp_time[CP_SYS]; in getcpu()
239 cpu_stats->intr = cp_time[CP_INTR]; in getcpu()
240 cpu_stats->idle = cp_time[CP_IDLE]; in getcpu()
262 total_bytes += cur_stats->bytes[i]; in compute_stats()
263 total_operations += cur_stats->operations[i]; in compute_stats()
264 total_dmas += cur_stats->dmas[i]; in compute_stats()
265 bintime_add(&total_time_bt, &cur_stats->time[i]); in compute_stats()
266 bintime_add(&total_dma_bt, &cur_stats->dma_time[i]); in compute_stats()
268 total_bytes -= prev_stats->bytes[i]; in compute_stats()
269 total_operations -= prev_stats->operations[i]; in compute_stats()
270 total_dmas -= prev_stats->dmas[i]; in compute_stats()
271 bintime_sub(&total_time_bt, &prev_stats->time[i]); in compute_stats()
272 bintime_sub(&total_dma_bt, &prev_stats->dma_time[i]); in compute_stats()
335 struct ctl_io_stats *stats = ctx->cur_stats; in ctlstat_dump()
337 for (i = n = 0; i < ctx->cur_items;i++) { in ctlstat_dump()
338 if (F_MASK(ctx) && bit_test(ctx->item_mask, in ctlstat_dump()
356 if (++n >= ctx->numdevs) in ctlstat_dump()
364 struct ctl_io_stats *stats = ctx->cur_stats; in ctlstat_json()
367 for (i = n = 0; i < ctx->cur_items; i++) { in ctlstat_json()
368 if (F_MASK(ctx) && bit_test(ctx->item_mask, in ctlstat_json()
386 if (iotype < (CTL_STATS_NUM_TYPES - 1)) in ctlstat_json()
390 if (++n >= ctx->numdevs) in ctlstat_json()
392 if (i < (ctx->cur_items - 1)) in ctlstat_json()
399 for (i = n = 0; i < ctx->cur_items; i++) { \
400 if (F_MASK(ctx) && bit_test(ctx->item_mask, \
425 for (i = n = 0; i < ctx->cur_items; i++) { \
426 if (F_MASK(ctx) && bit_test(ctx->item_mask, \
430 uint64_t us; \
444 us = ts.tv_sec * 1000000 + ts.tv_nsec / 1000; \
449 idx, target, iotypes[iotype], us); \
458 targdata->level++; in cctl_start_pelement()
459 if ((u_int)targdata->level >= (sizeof(targdata->cur_sb) / in cctl_start_pelement()
460 sizeof(targdata->cur_sb[0]))) in cctl_start_pelement()
462 sizeof(targdata->cur_sb) / sizeof(targdata->cur_sb[0])); in cctl_start_pelement()
464 targdata->cur_sb[targdata->level] = sbuf_new_auto(); in cctl_start_pelement()
465 if (targdata->cur_sb[targdata->level] == NULL) in cctl_start_pelement()
471 targdata->lun = -1; in cctl_start_pelement()
472 targdata->id = -1; in cctl_start_pelement()
473 free(targdata->target); in cctl_start_pelement()
474 targdata->target = NULL; in cctl_start_pelement()
478 * Well-formed XML always pairs keys with in cctl_start_pelement()
482 targdata->id = atoi(attr[i + 1]); in cctl_start_pelement()
495 sbuf_bcat(targdata->cur_sb[targdata->level], str, len); in cctl_char_phandler()
504 if (targdata->cur_sb[targdata->level] == NULL) in cctl_end_pelement()
506 targdata->level, name); in cctl_end_pelement()
508 if (sbuf_finish(targdata->cur_sb[targdata->level]) != 0) in cctl_end_pelement()
510 str = strdup(sbuf_data(targdata->cur_sb[targdata->level])); in cctl_end_pelement()
513 sbuf_len(targdata->cur_sb[targdata->level])); in cctl_end_pelement()
515 sbuf_delete(targdata->cur_sb[targdata->level]); in cctl_end_pelement()
516 targdata->cur_sb[targdata->level] = NULL; in cctl_end_pelement()
517 targdata->level--; in cctl_end_pelement()
520 free(targdata->target); in cctl_end_pelement()
521 targdata->target = str; in cctl_end_pelement()
523 if (targdata->id >= 0 && targdata->target != NULL) { in cctl_end_pelement()
524 if (targdata->id >= targdata->ntargets) { in cctl_end_pelement()
529 targdata->ntargets = MAX(targdata->ntargets * 2, in cctl_end_pelement()
530 targdata->id + 1); in cctl_end_pelement()
531 size_t newsize = targdata->ntargets * in cctl_end_pelement()
533 targdata->targets = rallocx(targdata->targets, in cctl_end_pelement()
536 free(targdata->targets[targdata->id]); in cctl_end_pelement()
537 targdata->targets[targdata->id] = targdata->target; in cctl_end_pelement()
538 targdata->target = NULL; in cctl_end_pelement()
548 struct ctl_io_stats *stats = ctx->cur_stats; in ctlstat_prometheus()
558 targdata.ntargets = ctx->cur_items; in ctlstat_prometheus()
560 retry: in ctlstat_prometheus()
566 if (ioctl(fd, CTL_PORT_LIST, &list) == -1) in ctlstat_prometheus()
573 goto retry; in ctlstat_prometheus()
601 printf("# HELP iscsi_%s_time Cumulative operation time in us\n" in ctlstat_prometheus()
604 printf("# HELP iscsi_%s_dma_time Cumulative DMA time in us\n" in ctlstat_prometheus()
625 if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0)) in ctlstat_standard()
628 etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec + in ctlstat_standard()
629 (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; in ctlstat_standard()
632 ctx->prev_total_jiffies = ctx->cur_total_jiffies; in ctlstat_standard()
633 ctx->cur_total_jiffies = ctx->cur_cpu.user + in ctlstat_standard()
634 ctx->cur_cpu.nice + ctx->cur_cpu.system + in ctlstat_standard()
635 ctx->cur_cpu.intr + ctx->cur_cpu.idle; in ctlstat_standard()
636 delta_jiffies = ctx->cur_total_jiffies; in ctlstat_standard()
638 delta_jiffies -= ctx->prev_total_jiffies; in ctlstat_standard()
639 ctx->prev_idle = ctx->cur_idle; in ctlstat_standard()
640 ctx->cur_idle = ctx->cur_cpu.idle; in ctlstat_standard()
641 delta_idle = ctx->cur_idle - ctx->prev_idle; in ctlstat_standard()
643 cpu_percentage = delta_jiffies - delta_idle; in ctlstat_standard()
649 ctx->header_interval--; in ctlstat_standard()
650 if (ctx->header_interval <= 0) { in ctlstat_standard()
662 ctx->cur_items); i++) { in ctlstat_standard()
670 item = (int)ctx->cur_stats[i].item; in ctlstat_standard()
673 bit_test(ctx->item_mask, item) == 0) in ctlstat_standard()
678 if (++n >= ctx->numdevs) in ctlstat_standard()
690 ctx->header_interval = 20; in ctlstat_standard()
705 ctx->prev_total_stats[i] = ctx->cur_total_stats[i]; in ctlstat_standard()
707 memset(&ctx->cur_total_stats, 0, sizeof(ctx->cur_total_stats)); in ctlstat_standard()
711 ctx->cur_total_stats[st].bytes[j] += \ in ctlstat_standard()
712 ctx->cur_stats[i].bytes[j] in ctlstat_standard()
714 ctx->cur_total_stats[st].operations[j] += \ in ctlstat_standard()
715 ctx->cur_stats[i].operations[j] in ctlstat_standard()
717 ctx->cur_total_stats[st].dmas[j] += \ in ctlstat_standard()
718 ctx->cur_stats[i].dmas[j] in ctlstat_standard()
720 bintime_add(&ctx->cur_total_stats[st].time[j], \ in ctlstat_standard()
721 &ctx->cur_stats[i].time[j]) in ctlstat_standard()
723 bintime_add(&ctx->cur_total_stats[st].dma_time[j], \ in ctlstat_standard()
724 &ctx->cur_stats[i].dma_time[j]) in ctlstat_standard()
726 for (i = 0; i < ctx->cur_items; i++) { in ctlstat_standard()
727 if (F_MASK(ctx) && bit_test(ctx->item_mask, in ctlstat_standard()
728 (int)ctx->cur_stats[i].item) == 0) in ctlstat_standard()
751 compute_stats(&ctx->cur_total_stats[i], in ctlstat_standard()
752 F_FIRST(ctx) ? NULL : &ctx->prev_total_stats[i], in ctlstat_standard()
769 for (i = n = 0; i < min(ctl_stat_bits, ctx->cur_items); i++) { in ctlstat_standard()
776 if (F_MASK(ctx) && bit_test(ctx->item_mask, in ctlstat_standard()
777 (int)ctx->cur_stats[i].item) == 0) in ctlstat_standard()
779 for (j = 0; j < ctx->prev_items; j++) { in ctlstat_standard()
780 if (ctx->prev_stats[j].item == in ctlstat_standard()
781 ctx->cur_stats[i].item) in ctlstat_standard()
784 if (j >= ctx->prev_items) in ctlstat_standard()
785 j = -1; in ctlstat_standard()
786 compute_stats(&ctx->cur_stats[i], in ctlstat_standard()
787 j >= 0 ? &ctx->prev_stats[j] : NULL, in ctlstat_standard()
800 if (++n >= ctx->numdevs) in ctlstat_standard()
812 tmp_stats = ctx->prev_stats; in get_and_print_stats()
813 ctx->prev_stats = ctx->cur_stats; in get_and_print_stats()
814 ctx->cur_stats = tmp_stats; in get_and_print_stats()
815 c = ctx->prev_alloc; in get_and_print_stats()
816 ctx->prev_alloc = ctx->cur_alloc; in get_and_print_stats()
817 ctx->cur_alloc = c; in get_and_print_stats()
818 c = ctx->prev_items; in get_and_print_stats()
819 ctx->prev_items = ctx->cur_items; in get_and_print_stats()
820 ctx->cur_items = c; in get_and_print_stats()
821 ctx->prev_time = ctx->cur_time; in get_and_print_stats()
822 ctx->prev_cpu = ctx->cur_cpu; in get_and_print_stats()
823 if (getstats(fd, &ctx->cur_alloc, &ctx->cur_items, in get_and_print_stats()
824 &ctx->cur_stats, &ctx->cur_time, &ctx->flags, ports) != 0) in get_and_print_stats()
827 switch(ctx->mode) { in get_and_print_stats()
857 count = -1; in main()
867 0) == -1) { in main()
875 while ((c = getopt(argc, argv, ctlstat_opts)) != -1) { in main()
950 errx(1, "Options -p and -l are exclusive."); in main()
953 if ((count != -1) || in main()
956 /* NB: -P could be compatible with -t in the future */ in main()
959 errx(1, "Option -P is exclusive with -p, -c, -w, and -t"); in main()
971 if ((fd = open(CTL_DEFAULT_DEV, O_RDWR)) == -1) in main()
977 * Content-Length, but they still work. And the data still in main()
982 "Content-Type: text/plain; version=0.0.4\r\n" in main()
1003 count--; in main()