Date: Fri, 30 May 2014 09:41:01 GMT From: zkorchev@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r268845 - soc2014/zkorchev/freebsd_head/usr.bin/vmstat Message-ID: <201405300941.s4U9f1L9091451@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: zkorchev Date: Fri May 30 09:41:00 2014 New Revision: 268845 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268845 Log: vmstat JSON output draft Modified: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c Modified: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c ============================================================================== --- soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c Fri May 30 08:22:58 2014 (r268844) +++ soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c Fri May 30 09:41:00 2014 (r268845) @@ -78,6 +78,13 @@ #include "sol.h" +/* + * Upward approximation of the maximum number of characters needed to + * represent a value of integral type t as a string, excluding the + * NUL terminator. + */ +#define STRBUF_SIZEOF(t) (CHAR_BIT * sizeof(t) / 3 + 1) + #if defined(SOL_ON) static struct sol_stream sol_stream; #endif @@ -228,7 +235,11 @@ maxshowdevs); break; case 'O': +#if defined(SOL_ON) Oflag = 1; +#else + errx(1, "vmstat compiled without -O support"); +#endif break; case 'p': if (devstat_buildmatch(optarg, &matches, &num_matches) != 0) @@ -641,12 +652,19 @@ { char buf[10]; int flags; + size_t len; if (size < 5 || size > 9) errx(1, "doofus"); flags = HN_B | HN_NOSPACE | HN_DECIMAL; - humanize_number(buf, size, val, "", HN_AUTOSCALE, flags); - printf("%*s", size, buf); + len = humanize_number(buf, size, val, "", HN_AUTOSCALE, flags); + +#if defined(SOL_ON) + if (Oflag) + sol_string(&sol_stream, buf, len); + else +#endif + printf("%*s", size, buf); } static int hz, hdrcnt; @@ -713,7 +731,7 @@ last_cp_times = calloc(1, size_cp_times); } for (hdrcnt = 1;;) { - if (!--hdrcnt) + if (!--hdrcnt && !Oflag) printhdr(ncpus, cpumask); if (kd != NULL) { if (kvm_getcptime(kd, cur.cp_time) < 0) @@ -765,7 +783,7 @@ errx(1, "%s", devstat_errbuf); break; case 1: - printhdr(ncpus, cpumask); + if (!Oflag) printhdr(ncpus, cpumask); break; default: break; @@ -777,45 +795,116 @@ fill_vmmeter(&sum); fill_vmtotal(&total); - (void)printf("%2d %1d %1d", - total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); + #define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10)) #define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */ - if (hflag) { - printf(" "); - prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7); - printf(" "); - prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6); - printf(" "); - } else { - printf(" %7d ", vmstat_pgtok(total.t_avm)); - printf(" %6d ", vmstat_pgtok(total.t_free)); + +#if defined(SOL_ON) + if (Oflag) + { + sol_map_start(&sol_stream); + + sol_map_key(&sol_stream, "pages_r", 7); + sol_integer(&sol_stream, total.t_rq - 1); + + sol_map_key(&sol_stream, "pages_b", 7); + sol_integer(&sol_stream, total.t_dw + total.t_pw); + + sol_map_key(&sol_stream, "pages_w", 7); + sol_integer(&sol_stream, total.t_sw); + + if (hflag) { + sol_map_key(&sol_stream, "hmem_avg", 8); + prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7); + sol_map_key(&sol_stream, "hmem_free", 9); + prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6); + } else { + sol_map_key(&sol_stream, "mem_avg", 7); + sol_integer(&sol_stream, vmstat_pgtok(total.t_avm)); + sol_map_key(&sol_stream, "mem_free", 8); + sol_integer(&sol_stream, vmstat_pgtok(total.t_free)); + } + + sol_map_key(&sol_stream, "page_flt", 8); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults)); + + sol_map_key(&sol_stream, "page_re", 7); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_reactivated - osum.v_reactivated)); + + sol_map_key(&sol_stream, "page_pi", 7); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_swapin + sum.v_vnodein - (osum.v_swapin + osum.v_vnodein))); + + sol_map_key(&sol_stream, "page_po", 7); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_swapout + sum.v_vnodeout - (osum.v_swapout + osum.v_vnodeout))); + + sol_map_key(&sol_stream, "page_fr", 7); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_tfree - osum.v_tfree)); + + sol_map_key(&sol_stream, "page_sr", 7); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_pdpages - osum.v_pdpages)); + + devstats(); + + sol_map_key(&sol_stream, "fault_in", 8); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_intr - osum.v_intr)); + + sol_map_key(&sol_stream, "fault_sy", 8); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_syscall - osum.v_syscall)); + + sol_map_key(&sol_stream, "fault_cs", 8); + sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_swtch - osum.v_swtch)); + + // 3 + + if (Pflag) + pcpustats(ncpus, cpumask, maxid); + else + cpustats(); + + sol_map_end(&sol_stream); } - (void)printf("%5lu ", - (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults)); - (void)printf("%3lu ", - (unsigned long)rate(sum.v_reactivated - osum.v_reactivated)); - (void)printf("%3lu ", - (unsigned long)rate(sum.v_swapin + sum.v_vnodein - - (osum.v_swapin + osum.v_vnodein))); - (void)printf("%3lu ", - (unsigned long)rate(sum.v_swapout + sum.v_vnodeout - - (osum.v_swapout + osum.v_vnodeout))); - (void)printf("%5lu ", - (unsigned long)rate(sum.v_tfree - osum.v_tfree)); - (void)printf("%3lu ", - (unsigned long)rate(sum.v_pdpages - osum.v_pdpages)); - devstats(); - (void)printf("%4lu %4lu %4lu", - (unsigned long)rate(sum.v_intr - osum.v_intr), - (unsigned long)rate(sum.v_syscall - osum.v_syscall), - (unsigned long)rate(sum.v_swtch - osum.v_swtch)); - if (Pflag) - pcpustats(ncpus, cpumask, maxid); else - cpustats(); - (void)printf("\n"); - (void)fflush(stdout); +#endif + { + (void)printf("%2d %1d %1d", + total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); + if (hflag) { + printf(" "); + prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7); + printf(" "); + prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6); + printf(" "); + } else { + printf(" %7d ", vmstat_pgtok(total.t_avm)); + printf(" %6d ", vmstat_pgtok(total.t_free)); + } + (void)printf("%5lu ", + (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults)); + (void)printf("%3lu ", + (unsigned long)rate(sum.v_reactivated - osum.v_reactivated)); + (void)printf("%3lu ", + (unsigned long)rate(sum.v_swapin + sum.v_vnodein - + (osum.v_swapin + osum.v_vnodein))); + (void)printf("%3lu ", + (unsigned long)rate(sum.v_swapout + sum.v_vnodeout - + (osum.v_swapout + osum.v_vnodeout))); + (void)printf("%5lu ", + (unsigned long)rate(sum.v_tfree - osum.v_tfree)); + (void)printf("%3lu ", + (unsigned long)rate(sum.v_pdpages - osum.v_pdpages)); + devstats(); + (void)printf("%4lu %4lu %4lu", + (unsigned long)rate(sum.v_intr - osum.v_intr), + (unsigned long)rate(sum.v_syscall - osum.v_syscall), + (unsigned long)rate(sum.v_swtch - osum.v_swtch)); + if (Pflag) + pcpustats(ncpus, cpumask, maxid); + else + cpustats(); + (void)printf("\n"); + (void)fflush(stdout); + } + if (reps >= 0 && --reps <= 0) break; osum = sum; @@ -963,47 +1052,76 @@ long nchtotal; fill_vmmeter(&sum); - (void)printf("%9u cpu context switches\n", sum.v_swtch); - (void)printf("%9u device interrupts\n", sum.v_intr); - (void)printf("%9u software interrupts\n", sum.v_soft); - (void)printf("%9u traps\n", sum.v_trap); - (void)printf("%9u system calls\n", sum.v_syscall); - (void)printf("%9u kernel threads created\n", sum.v_kthreads); - (void)printf("%9u fork() calls\n", sum.v_forks); - (void)printf("%9u vfork() calls\n", sum.v_vforks); - (void)printf("%9u rfork() calls\n", sum.v_rforks); - (void)printf("%9u swap pager pageins\n", sum.v_swapin); - (void)printf("%9u swap pager pages paged in\n", sum.v_swappgsin); - (void)printf("%9u swap pager pageouts\n", sum.v_swapout); - (void)printf("%9u swap pager pages paged out\n", sum.v_swappgsout); - (void)printf("%9u vnode pager pageins\n", sum.v_vnodein); - (void)printf("%9u vnode pager pages paged in\n", sum.v_vnodepgsin); - (void)printf("%9u vnode pager pageouts\n", sum.v_vnodeout); - (void)printf("%9u vnode pager pages paged out\n", sum.v_vnodepgsout); - (void)printf("%9u page daemon wakeups\n", sum.v_pdwakeups); - (void)printf("%9u pages examined by the page daemon\n", sum.v_pdpages); - (void)printf("%9u pages reactivated\n", sum.v_reactivated); - (void)printf("%9u copy-on-write faults\n", sum.v_cow_faults); - (void)printf("%9u copy-on-write optimized faults\n", sum.v_cow_optim); - (void)printf("%9u zero fill pages zeroed\n", sum.v_zfod); - (void)printf("%9u zero fill pages prezeroed\n", sum.v_ozfod); - (void)printf("%9u intransit blocking page faults\n", sum.v_intrans); - (void)printf("%9u total VM faults taken\n", sum.v_vm_faults); - (void)printf("%9u page faults requiring I/O\n", sum.v_io_faults); - (void)printf("%9u pages affected by kernel thread creation\n", sum.v_kthreadpages); - (void)printf("%9u pages affected by fork()\n", sum.v_forkpages); - (void)printf("%9u pages affected by vfork()\n", sum.v_vforkpages); - (void)printf("%9u pages affected by rfork()\n", sum.v_rforkpages); - (void)printf("%9u pages cached\n", sum.v_tcached); - (void)printf("%9u pages freed\n", sum.v_tfree); - (void)printf("%9u pages freed by daemon\n", sum.v_dfree); - (void)printf("%9u pages freed by exiting processes\n", sum.v_pfree); - (void)printf("%9u pages active\n", sum.v_active_count); - (void)printf("%9u pages inactive\n", sum.v_inactive_count); - (void)printf("%9u pages in VM cache\n", sum.v_cache_count); - (void)printf("%9u pages wired down\n", sum.v_wire_count); - (void)printf("%9u pages free\n", sum.v_free_count); - (void)printf("%9u bytes per page\n", sum.v_page_size); + + /* In order to avoid code duplication the output of dosum() is defined in + * the macro psum() below. Output format is changed by re-defining + * psum_out(). + */ + #define psum() do { \ + psum_out("cpu context switches", sum.v_swtch); \ + psum_out("device interrupts", sum.v_intr); \ + psum_out("software interrupts", sum.v_soft); \ + psum_out("traps", sum.v_trap); \ + psum_out("system calls", sum.v_syscall); \ + psum_out("kernel threads created", sum.v_kthreads); \ + psum_out(" fork() calls", sum.v_forks); \ + psum_out("vfork() calls", sum.v_vforks); \ + psum_out("rfork() calls", sum.v_rforks); \ + psum_out("swap pager pageins", sum.v_swapin); \ + psum_out("swap pager pages paged in", sum.v_swappgsin); \ + psum_out("swap pager pageouts", sum.v_swapout); \ + psum_out("swap pager pages paged out", sum.v_swappgsout); \ + psum_out("vnode pager pageins", sum.v_vnodein); \ + psum_out("vnode pager pages paged in", sum.v_vnodepgsin); \ + psum_out("vnode pager pageouts", sum.v_vnodeout); \ + psum_out("vnode pager pages paged out", sum.v_vnodepgsout); \ + psum_out("page daemon wakeups", sum.v_pdwakeups); \ + psum_out("pages examined by the page daemon", sum.v_pdpages); \ + psum_out("pages reactivated", sum.v_reactivated); \ + psum_out("copy-on-write faults", sum.v_cow_faults); \ + psum_out("copy-on-write optimized faults", sum.v_cow_optim); \ + psum_out("zero fill pages zeroed", sum.v_zfod); \ + psum_out("zero fill pages prezeroed", sum.v_ozfod); \ + psum_out("intransit blocking page faults", sum.v_intrans); \ + psum_out("total VM faults taken", sum.v_vm_faults); \ + psum_out("page faults requiring I/O", sum.v_io_faults); \ + psum_out("pages affected by kernel thread creation", sum.v_kthreadpages); \ + psum_out("pages affected by fork()", sum.v_forkpages); \ + psum_out("pages affected by vfork()", sum.v_vforkpages); \ + psum_out("pages affected by rfork()", sum.v_rforkpages); \ + psum_out("pages cached", sum.v_tcached); \ + psum_out("pages freed", sum.v_tfree); \ + psum_out("pages freed by daemon", sum.v_dfree); \ + psum_out("pages freed by exiting processes", sum.v_pfree); \ + psum_out("pages active", sum.v_active_count); \ + psum_out("pages inactive", sum.v_inactive_count); \ + psum_out("pages in VM cache", sum.v_cache_count); \ + psum_out("pages wired down", sum.v_wire_count); \ + psum_out("pages free", sum.v_free_count); \ + psum_out("bytes per page", sum.v_page_size); \ + } while (0) + +#if defined(SOL_ON) + if (Oflag) + { + sol_map_start(&sol_stream); + #define psum_out(str, val) do { \ + sol_map_key(&sol_stream, (str), sizeof(str) - 1); \ + sol_integer(&sol_stream, (val)); \ + } while (0) + psum(); + #undef psum_out + } + else +#endif + { + #define psum_out(str, val) (void)printf("%9u " str "\n", (val)); + psum(); + #undef psum_out + } + + #undef psum /* clean the macro namespace */ + if (kd != NULL) { kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats)); } else { @@ -1015,16 +1133,47 @@ nchtotal = lnchstats.ncs_goodhits + lnchstats.ncs_neghits + lnchstats.ncs_badhits + lnchstats.ncs_falsehits + lnchstats.ncs_miss + lnchstats.ncs_long; - (void)printf("%9ld total name lookups\n", nchtotal); - (void)printf( - "%9s cache hits (%ld%% pos + %ld%% neg) system %ld%% per-directory\n", - "", PCT(lnchstats.ncs_goodhits, nchtotal), - PCT(lnchstats.ncs_neghits, nchtotal), - PCT(lnchstats.ncs_pass2, nchtotal)); - (void)printf("%9s deletions %ld%%, falsehits %ld%%, toolong %ld%%\n", "", - PCT(lnchstats.ncs_badhits, nchtotal), - PCT(lnchstats.ncs_falsehits, nchtotal), - PCT(lnchstats.ncs_long, nchtotal)); + +#if defined(SOL_ON) + if (Oflag) + { + sol_map_key(&sol_stream, "total name lookups", sizeof("total name lookups") - 1); + sol_integer(&sol_stream, nchtotal); + + sol_map_key(&sol_stream, "cache hits + (%)", sizeof("cache hits + (%)") - 1); + sol_integer(&sol_stream, PCT(lnchstats.ncs_goodhits, nchtotal)); + + sol_map_key(&sol_stream, "cache hits - (%)", sizeof("cache hits - (%)") - 1); + sol_integer(&sol_stream, PCT(lnchstats.ncs_neghits, nchtotal)); + + sol_map_key(&sol_stream, "cache hits per dir (%)", sizeof("cache hits per dir (%)") - 1); + sol_integer(&sol_stream, PCT(lnchstats.ncs_pass2, nchtotal)); + + sol_map_key(&sol_stream, "deletions (%)", sizeof("deletions (%)") - 1); + sol_integer(&sol_stream, PCT(lnchstats.ncs_badhits, nchtotal)); + + sol_map_key(&sol_stream, "insertions (%)", sizeof("insertions (%)") - 1); + sol_integer(&sol_stream, PCT(lnchstats.ncs_falsehits, nchtotal)); + + sol_map_key(&sol_stream, "toolong (%)", sizeof("toolong (%)") - 1); + sol_integer(&sol_stream, PCT(lnchstats.ncs_long, nchtotal)); + + sol_map_end(&sol_stream); + } + else +#endif + { + (void)printf("%9ld total name lookups\n", nchtotal); + (void)printf( + "%9s cache hits (%ld%% pos + %ld%% neg) system %ld%% per-directory\n", + "", PCT(lnchstats.ncs_goodhits, nchtotal), + PCT(lnchstats.ncs_neghits, nchtotal), + PCT(lnchstats.ncs_pass2, nchtotal)); + (void)printf("%9s deletions %ld%%, falsehits %ld%%, toolong %ld%%\n", "", + PCT(lnchstats.ncs_badhits, nchtotal), + PCT(lnchstats.ncs_falsehits, nchtotal), + PCT(lnchstats.ncs_long, nchtotal)); + } } static void @@ -1123,7 +1272,19 @@ DSM_NONE) != 0) errx(1, "%s", devstat_errbuf); - (void)printf("%3.0Lf ", transfers_per_second); +#if defined(SOL_ON) + if (Oflag) { + char buf[2 + STRBUF_SIZEOF(dev_select[dn].unit_number) + 1]; + size_t len = snprintf(buf, sizeof(buf), "%c%c%d", dev_select[dn].device_name[0], + dev_select[dn].device_name[1], + dev_select[dn].unit_number); + + sol_map_key(&sol_stream, buf, len); + sol_map_float(&sol_stream, transfers_per_second); + } + else +#endif + (void)printf("%3.0Lf ", transfers_per_second); } } @@ -1157,12 +1318,27 @@ else lpct = 0.0; over = 0; - printf(" "); - percent((cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct, &over); - printf(" "); - percent((cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct, &over); - printf(" "); - percent(cur.cp_time[CP_IDLE] * lpct, &over); + +#if defined(SOL_ON) + if (Oflag) + { + sol_map_key(&sol_stream, "cpu_user", 8); + sol_map_float(&sol_stream, (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct); + sol_map_key(&sol_stream, "cpu_sys", 7); + sol_map_float(&sol_stream, (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct); + sol_map_key(&sol_stream, "cpu_idle", 8); + sol_map_float(&sol_stream, cur.cp_time[CP_IDLE] * lpct); + } + else +#endif + { + printf(" "); + percent((cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct, &over); + printf(" "); + percent((cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct, &over); + printf(" "); + percent(cur.cp_time[CP_IDLE] * lpct, &over); + } } static void @@ -1184,6 +1360,14 @@ } } +#if defined(SOL_ON) + if (Oflag) + { + sol_map_key(&sol_stream, "cpu", 3); + sol_array_start(&sol_stream); + } +#endif + over = 0; for (i = 0; i <= maxid; i++) { if ((cpumask & (1ul << i)) == 0) @@ -1195,15 +1379,40 @@ lpct = 100.0 / total; else lpct = 0.0; - printf(" "); - percent((cur_cp_times[i * CPUSTATES + CP_USER] + - cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over); - printf(" "); - percent((cur_cp_times[i * CPUSTATES + CP_SYS] + - cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over); - printf(" "); - percent(cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct, &over); + +#if defined(SOL_ON) + if (Oflag) + { + sol_map_start(&sol_stream); + + sol_map_key(&sol_stream, "user", 4); + sol_map_float(&sol_stream, (cur_cp_times[i * CPUSTATES + CP_USER] + + cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct); + + sol_map_key(&sol_stream, "sys", 3); + sol_map_float(&sol_stream, (cur_cp_times[i * CPUSTATES + CP_SYS] + + cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct); + + sol_map_key(&sol_stream, "idle", 4); + sol_map_float(&sol_stream, cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct); + } + else +#endif + { + printf(" "); + percent((cur_cp_times[i * CPUSTATES + CP_USER] + + cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over); + printf(" "); + percent((cur_cp_times[i * CPUSTATES + CP_SYS] + + cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over); + printf(" "); + percent(cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct, &over); + } } + +#if defined(SOL_ON) + if (Oflag) sol_array_end(&sol_stream); +#endif } static void @@ -1249,18 +1458,59 @@ istrnamlen = clen; tintrname += clen + 1; } - (void)printf("%-*s %20s %10s\n", (int)istrnamlen, "interrupt", "total", - "rate"); - inttotal = 0; - for (i = 0; i < nintr; i++) { - if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) - (void)printf("%-*s %20lu %10lu\n", (int)istrnamlen, - intrname, *intrcnt, *intrcnt / uptime); - intrname += strlen(intrname) + 1; - inttotal += *intrcnt++; + +#if defined(SOL_ON) + if (Oflag) + { + sol_map_start(&sol_stream); + + inttotal = 0; + for (i = 0; i < nintr; i++) { + if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) { + sol_map_key(&sol_stream, intrname, strlen(intrname)); + sol_map_start(&sol_stream); + + sol_map_key(&sol_stream, "total", 5); + sol_integer(&sol_stream, *intrcnt); + + sol_map_key(&sol_stream, "rate", 4); + sol_integer(&sol_stream, *intrcnt / uptime); + + sol_map_end(&sol_stream); + } + intrname += strlen(intrname) + 1; + inttotal += *intrcnt++; + } + + sol_map_key(&sol_stream, "Total", 5); + sol_map_start(&sol_stream); + + sol_map_key(&sol_stream, "total", 5); + sol_integer(&sol_stream, inttotal); + + sol_map_key(&sol_stream, "rate", 4); + sol_integer(&sol_stream, inttotal / uptime); + + sol_map_end(&sol_stream); + + sol_map_end(&sol_stream); + } + else +#endif + { + (void)printf("%-*s %20s %10s\n", (int)istrnamlen, "interrupt", "total", + "rate"); + inttotal = 0; + for (i = 0; i < nintr; i++) { + if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) + (void)printf("%-*s %20lu %10lu\n", (int)istrnamlen, + intrname, *intrcnt, *intrcnt / uptime); + intrname += strlen(intrname) + 1; + inttotal += *intrcnt++; + } + (void)printf("%-*s %20" PRIu64 " %10" PRIu64 "\n", (int)istrnamlen, + "Total", inttotal, inttotal / uptime); } - (void)printf("%-*s %20" PRIu64 " %10" PRIu64 "\n", (int)istrnamlen, - "Total", inttotal, inttotal / uptime); } static void @@ -1389,21 +1639,67 @@ memstat_strerror(error)); } } - printf("%-20s %6s %6s %8s %8s %8s %4s %4s\n\n", "ITEM", "SIZE", - "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP"); - for (mtp = memstat_mtl_first(mtlp); mtp != NULL; - mtp = memstat_mtl_next(mtp)) { - strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME); - strcat(name, ":"); - printf("%-20s %6" PRIu64 ", %6" PRIu64 ",%8" PRIu64 ",%8" PRIu64 - ",%8" PRIu64 ",%4" PRIu64 ",%4" PRIu64 "\n", name, - memstat_get_size(mtp), memstat_get_countlimit(mtp), - memstat_get_count(mtp), memstat_get_free(mtp), - memstat_get_numallocs(mtp), memstat_get_failures(mtp), - memstat_get_sleeps(mtp)); + +#if defined(SOL_ON) + if (Oflag) + { + sol_array_start(&sol_stream); + + for (mtp = memstat_mtl_first(mtlp); mtp != NULL; + mtp = memstat_mtl_next(mtp)) { + + sol_map_start(&sol_stream); + + const char *name = memstat_get_name(mtp); + sol_map_key(&sol_stream, "item", 4); + sol_map_string(&sol_stream, name, strlen(name)); + + sol_map_key(&sol_stream, "size", 4); + sol_map_integer(&sol_stream, memstat_get_size(mtp)); + + sol_map_key(&sol_stream, "limit", 4); + sol_map_integer(&sol_stream, memstat_get_countlimit(mtp)); + + sol_map_key(&sol_stream, "used", 4); + sol_map_integer(&sol_stream, memstat_get_count(mtp)); + + sol_map_key(&sol_stream, "free", 4); + sol_map_integer(&sol_stream, memstat_get_free(mtp)); + + sol_map_key(&sol_stream, "req", 3); + sol_map_integer(&sol_stream, memstat_get_numallocs(mtp)); + + sol_map_key(&sol_stream, "fail", 4); + sol_map_integer(&sol_stream, memstat_get_failures(mtp)); + + sol_map_key(&sol_stream, "sleep", 5); + sol_map_integer(&sol_stream, memstat_get_sleeps(mtp)); + + sol_map_end(&sol_stream); + } + memstat_mtl_free(mtlp); + + sol_array_end(&sol_stream); + } + else +#endif + { + printf("%-20s %6s %6s %8s %8s %8s %4s %4s\n\n", "ITEM", "SIZE", + "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP"); + for (mtp = memstat_mtl_first(mtlp); mtp != NULL; + mtp = memstat_mtl_next(mtp)) { + strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME); + strcat(name, ":"); + printf("%-20s %6" PRIu64 ", %6" PRIu64 ",%8" PRIu64 ",%8" PRIu64 + ",%8" PRIu64 ",%4" PRIu64 ",%4" PRIu64 "\n", name, + memstat_get_size(mtp), memstat_get_countlimit(mtp), + memstat_get_count(mtp), memstat_get_free(mtp), + memstat_get_numallocs(mtp), memstat_get_failures(mtp), + memstat_get_sleeps(mtp)); + } + memstat_mtl_free(mtlp); + printf("\n"); } - memstat_mtl_free(mtlp); - printf("\n"); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405300941.s4U9f1L9091451>