static void procstat_close_signame(int sig) { char name[12]; int i; if (!nflag && sig < sys_nsig) { strlcpy(name, sys_signame[sig], sizeof(name)); for (i = 0; name[i] != 0; i++) name[i] = toupper(name[i]); xo_close_container(name); } else snprintf(name, 12, "%d", sig); xo_close_container(name); }
/* * Display an individual arp entry */ static int get(char *host) { struct sockaddr_in *addr; int found; addr = getaddr(host); if (addr == NULL) return (1); xo_set_version(ARP_XO_VERSION); xo_open_container("arp"); xo_open_list("arp-cache"); found = search(addr->sin_addr.s_addr, print_entry); if (found == 0) { xo_emit("{d:hostname/%s} ({d:ip-address/%s}) -- no entry", host, inet_ntoa(addr->sin_addr)); if (rifname) xo_emit(" on {d:interface/%s}", rifname); xo_emit("\n"); } xo_close_list("arp-cache"); xo_close_container("arp"); xo_finish(); return (found == 0); }
void inet6print(const char *container, struct in6_addr *in6, int port, const char *proto, int numeric) { struct servent *sp = 0; char line[80], *cp; int width; if (container) xo_open_container(container); sprintf(line, "%.*s.", Wflag ? 39 : (Aflag && !numeric) ? 12 : 16, inet6name(in6)); cp = strchr(line, '\0'); if (!numeric && port) GETSERVBYPORT6(port, proto, sp); if (sp || port == 0) sprintf(cp, "%.15s", sp ? sp->s_name : "*"); else sprintf(cp, "%d", ntohs((u_short)port)); width = Wflag ? 45 : Aflag ? 18 : 22; xo_emit("{d:target/%-*.*s} ", width, width, line); int alen = cp - line - 1, plen = strlen(cp) - 1; xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, plen, cp); if (container) xo_close_container(container); }
/* * Dump ARP statistics structure. */ void arp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct arpstat arpstat; if (fetch_stats("net.link.ether.arp.stats", off, &arpstat, sizeof(arpstat), kread_counters) != 0) return; xo_open_container(name); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (arpstat.f || sflag <= 1) \ xo_emit("\t" m, (uintmax_t)arpstat.f, plural(arpstat.f)) #define p2(f, m) if (arpstat.f || sflag <= 1) \ xo_emit("\t" m, (uintmax_t)arpstat.f, pluralies(arpstat.f)) p(txrequests, "{:sent-requests/%ju} {N:/ARP request%s sent}\n"); p2(txreplies, "{:sent-replies/%ju} {N:/ARP repl%s sent}\n"); p(rxrequests, "{:received-requests/%ju} " "{N:/ARP request%s received}\n"); p2(rxreplies, "{:received-replies/%ju} " "{N:/ARP repl%s received}\n"); p(received, "{:received-packers/%ju} " "{N:/ARP packet%s received}\n"); p(dropped, "{:dropped-no-entry/%ju} " "{N:/total packet%s dropped due to no ARP entry}\n"); p(timeouts, "{:entries-timeout/%ju} " "{N:/ARP entry%s timed out}\n"); p(dupips, "{:dropped-duplicate-address/%ju} " "{N:/Duplicate IP%s seen}\n"); #undef p #undef p2 xo_close_container(name); }
/* * Print routing tables. */ void routepr(int fibnum, int af) { size_t intsize; int numfibs; if (live == 0) return; intsize = sizeof(int); if (fibnum == -1 && sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1) fibnum = 0; if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) numfibs = 1; if (fibnum < 0 || fibnum > numfibs - 1) errx(EX_USAGE, "%d: invalid fib", fibnum); /* * Since kernel & userland use different timebase * (time_uptime vs time_second) and we are reading kernel memory * directly we should do rt_expire --> expire_time conversion. */ if (clock_gettime(CLOCK_UPTIME, &uptime) < 0) err(EX_OSERR, "clock_gettime() failed"); xo_open_container("route-information"); xo_emit("{T:Routing tables}"); if (fibnum) xo_emit(" ({L:fib}: {:fib/%d})", fibnum); xo_emit("\n"); p_rtable_sysctl(fibnum, af); xo_close_container("route-information"); }
void procstat_rusage(struct procstat *procstat, struct kinfo_proc *kipp) { struct kinfo_proc *kip; unsigned int count, i; if (!hflag) { xo_emit("{d:ta/%5s} ", "PID"); if (Hflag) xo_emit("{d:tb/%6s} ", "TID"); xo_emit("{d:tc/%-16s %-32s %14s}\n", "COMM", "RESOURCE", "VALUE "); } if (!Hflag) { print_rusage(kipp); return; } xo_emit("{e:process_id/%d}", kipp->ki_pid); xo_emit("{e:command/%s}", kipp->ki_comm); xo_open_container("threads"); kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD, kipp->ki_pid, &count); if (kip == NULL) return; kinfo_proc_sort(kip, count); for (i = 0; i < count; i++) { print_rusage(&kip[i]); } xo_close_container("threads"); procstat_freeprocs(procstat, kip); }
/* * Dump raw ip6 statistics structure. */ void rip6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct rip6stat rip6stat, zerostat; u_quad_t delivered; size_t len; len = sizeof(rip6stat); if (live) { if (zflag) memset(&zerostat, 0, len); if (sysctlbyname("net.inet6.ip6.rip6stats", &rip6stat, &len, zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { if (errno != ENOENT) xo_warn("sysctl: net.inet6.ip6.rip6stats"); return; } } else kread_counters(off, &rip6stat, len); xo_emit("{T:/%s}:\n", name); xo_open_container(name); #define p(f, m) if (rip6stat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)rip6stat.f, plural(rip6stat.f)) p(rip6s_ipackets, "\t{:received-packets/%ju} " "{N:/message%s received}\n"); p(rip6s_isum, "\t{:input-checksum-computation/%ju} " "{N:/checksum calculation%s on inbound}\n"); p(rip6s_badsum, "\t{:received-bad-checksum/%ju} " "{N:/message%s with bad checksum}\n"); p(rip6s_nosock, "\t{:dropped-no-socket/%ju} " "{N:/message%s dropped due to no socket}\n"); p(rip6s_nosockmcast, "\t{:dropped-multicast-no-socket/%ju} " "{N:/multicast message%s dropped due to no socket}\n"); p(rip6s_fullsock, "\t{:dropped-full-socket-buffer/%ju} " "{N:/message%s dropped due to full socket buffers}\n"); delivered = rip6stat.rip6s_ipackets - rip6stat.rip6s_badsum - rip6stat.rip6s_nosock - rip6stat.rip6s_nosockmcast - rip6stat.rip6s_fullsock; if (delivered || sflag <= 1) xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n", (uintmax_t)delivered); p(rip6s_opackets, "\t{:sent-packets/%ju} " "{N:/datagram%s output}\n"); #undef p xo_close_container(name); }
void mrt6_stats() { struct mrt6stat mrtstat; size_t len = sizeof mrtstat; if (sysctlbyname("net.inet6.ip6.mrt6stat", &mrtstat, &len, NULL, 0) < 0) { xo_warn("sysctl: net.inet6.ip6.mrt6stat"); return; } xo_open_container("multicast-statistics"); xo_emit("{T:IPv6 multicast forwarding}:\n"); #define p(f, m) if (mrtstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)mrtstat.f, plural(mrtstat.f)) #define p2(f, m) if (mrtstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)mrtstat.f, plurales(mrtstat.f)) p(mrt6s_mfc_lookups, "\t{:cache-lookups/%ju} " "{N:/multicast forwarding cache lookup%s}\n"); p2(mrt6s_mfc_misses, "\t{:cache-misses/%ju} " "{N:/multicast forwarding cache miss%s}\n"); p(mrt6s_upcalls, "\t{:upcalls/%ju} " "{N:/upcall%s to multicast routing daemon}\n"); p(mrt6s_upq_ovflw, "\t{:upcall-overflows/%ju} " "{N:/upcall queue overflow%s}\n"); p(mrt6s_upq_sockfull, "\t{:upcalls-dropped-full-buffer/%ju} " "{N:/upcall%s dropped due to full socket buffer}\n"); p(mrt6s_cache_cleanups, "\t{:cache-cleanups/%ju} " "{N:/cache cleanup%s}\n"); p(mrt6s_no_route, "\t{:dropped-no-origin/%ju} " "{N:/datagram%s with no route for origin}\n"); p(mrt6s_bad_tunnel, "\t{:dropped-bad-tunnel/%ju} " "{N:/datagram%s arrived with bad tunneling}\n"); p(mrt6s_cant_tunnel, "\t{:dropped-could-not-tunnel/%ju} " "{N:/datagram%s could not be tunneled}\n"); p(mrt6s_wrong_if, "\t{:dropped-wrong-incoming-interface/%ju} " "{N:/datagram%s arrived on wrong interface}\n"); p(mrt6s_drop_sel, "\t{:dropped-selectively/%ju} " "{N:/datagram%s selectively dropped}\n"); p(mrt6s_q_overflow, "\t{:dropped-queue-overflow/%ju} " "{N:/datagram%s dropped due to queue overflow}\n"); p(mrt6s_pkt2large, "\t{:dropped-too-large/%ju} " "{N:/datagram%s dropped for being too large}\n"); #undef p2 #undef p xo_close_container("multicast-statistics"); }
/* * Dump CARP statistics structure. */ void carp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct carpstats carpstat; if (fetch_stats("net.inet.carp.stats", off, &carpstat, sizeof(carpstat), kread_counters) != 0) return; xo_open_container(name); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (carpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)carpstat.f, plural(carpstat.f)) #define p2(f, m) if (carpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)carpstat.f) p(carps_ipackets, "\t{:received-inet-packets/%ju} " "{N:/packet%s received (IPv4)}\n"); p(carps_ipackets6, "\t{:received-inet6-packets/%ju} " "{N:/packet%s received (IPv6)}\n"); p(carps_badttl, "\t\t{:dropped-wrong-ttl/%ju} " "{N:/packet%s discarded for wrong TTL}\n"); p(carps_hdrops, "\t\t{:dropped-short-header/%ju} " "{N:/packet%s shorter than header}\n"); p(carps_badsum, "\t\t{:dropped-bad-checksum/%ju} " "{N:/discarded for bad checksum%s}\n"); p(carps_badver, "\t\t{:dropped-bad-version/%ju} " "{N:/discarded packet%s with a bad version}\n"); p2(carps_badlen, "\t\t{:dropped-short-packet/%ju} " "{N:/discarded because packet too short}\n"); p2(carps_badauth, "\t\t{:dropped-bad-authentication/%ju} " "{N:/discarded for bad authentication}\n"); p2(carps_badvhid, "\t\t{:dropped-bad-vhid/%ju} " "{N:/discarded for bad vhid}\n"); p2(carps_badaddrs, "\t\t{:dropped-bad-address-list/%ju} " "{N:/discarded because of a bad address list}\n"); p(carps_opackets, "\t{:sent-inet-packets/%ju} " "{N:/packet%s sent (IPv4)}\n"); p(carps_opackets6, "\t{:sent-inet6-packets/%ju} " "{N:/packet%s sent (IPv6)}\n"); p2(carps_onomem, "\t\t{:send-failed-memory-error/%ju} " "{N:/send failed due to mbuf memory error}\n"); #if notyet p(carps_ostates, "\t\t{:send-state-updates/%s} " "{N:/state update%s sent}\n"); #endif #undef p #undef p2 xo_close_container(name); }
static void print_rusage(struct kinfo_proc *kipp) { long *lp; unsigned int i; char *field, *threadid; print_prefix(kipp); xo_emit("{d:resource/%-14s} {d:usage/%29s}{P: }\n", "user time", format_time(&kipp->ki_rusage.ru_utime)); print_prefix(kipp); xo_emit("{d:resource/%-14s} {d:usage/%29s}{P: }\n", "system time", format_time(&kipp->ki_rusage.ru_stime)); if (Hflag) { asprintf(&threadid, "%d", kipp->ki_tid); if (threadid == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in print_rusage()"); xo_open_container(threadid); xo_emit("{e:thread_id/%d}", kipp->ki_tid); } else { xo_emit("{e:process_id/%d}", kipp->ki_pid); xo_emit("{e:command/%s}", kipp->ki_comm); } xo_emit("{e:user time/%s}", format_time(&kipp->ki_rusage.ru_utime)); xo_emit("{e:system time/%s}", format_time(&kipp->ki_rusage.ru_stime)); lp = &kipp->ki_rusage.ru_maxrss; for (i = 0; i < nitems(rusage_info); i++) { print_prefix(kipp); asprintf(&field, "{e:%s/%%D}", rusage_info[i].ri_name); if (field == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in print_rusage()"); xo_emit(field, *lp); free(field); xo_emit("{d:resource/%-32s} {d:usage/%14s}\n", rusage_info[i].ri_name, format_value(*lp, rusage_info[i].ri_humanize, rusage_info[i].ri_scale)); lp++; } if (Hflag) { xo_close_container(threadid); free(threadid); } }
/* * Dump PIM statistics structure. */ void pim_stats(u_long off __unused, const char *name, int af1 __unused, int proto __unused) { struct pimstat pimstat; if (fetch_stats("net.inet.pim.stats", off, &pimstat, sizeof(pimstat), kread_counters) != 0) return; xo_open_container(name); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (pimstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)pimstat.f, plural(pimstat.f)) #define py(f, m) if (pimstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)pimstat.f, pimstat.f != 1 ? "ies" : "y") p(pims_rcv_total_msgs, "\t{:received-messages/%ju} " "{N:/message%s received}\n"); p(pims_rcv_total_bytes, "\t{:received-bytes/%ju} " "{N:/byte%s received}\n"); p(pims_rcv_tooshort, "\t{:dropped-too-short/%ju} " "{N:/message%s received with too few bytes}\n"); p(pims_rcv_badsum, "\t{:dropped-bad-checksum/%ju} " "{N:/message%s received with bad checksum}\n"); p(pims_rcv_badversion, "\t{:dropped-bad-version/%ju} " "{N:/message%s received with bad version}\n"); p(pims_rcv_registers_msgs, "\t{:received-data-register-messages/%ju} " "{N:/data register message%s received}\n"); p(pims_rcv_registers_bytes, "\t{:received-data-register-bytes/%ju} " "{N:/data register byte%s received}\n"); p(pims_rcv_registers_wrongiif, "\t" "{:received-data-register-wrong-interface/%ju} " "{N:/data register message%s received on wrong iif}\n"); p(pims_rcv_badregisters, "\t{:received-bad-registers/%ju} " "{N:/bad register%s received}\n"); p(pims_snd_registers_msgs, "\t{:sent-data-register-messages/%ju} " "{N:/data register message%s sent}\n"); p(pims_snd_registers_bytes, "\t{:sent-data-register-bytes/%ju} " "{N:/data register byte%s sent}\n"); #undef p #undef py xo_close_container(name); }
static void print_espstats(const struct espstat *espstat) { xo_open_container("esp-statictics"); #define p(f, n, m) if (espstat->f || sflag <= 1) \ xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \ (uintmax_t)espstat->f, plural(espstat->f)) #define hist(f, n, t, c) \ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c)); p(esps_hdrops, "dropped-short-header", "packet%s shorter than header shows"); p(esps_nopf, "dropped-bad-protocol", "packet%s dropped; protocol family not supported"); p(esps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB"); p(esps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR"); p(esps_qfull, "dropped-queue-full", "packet%s dropped; queue full"); p(esps_noxform, "dropped-no-transform", "packet%s dropped; no transform"); p(esps_badilen, "dropped-bad-length", "packet%s dropped; bad ilen"); p(esps_wrap, "replay-counter-wraps", "replay counter wrap%s"); p(esps_badenc, "dropped-bad-crypto", "packet%s dropped; bad encryption detected"); p(esps_badauth, "dropped-bad-auth", "packet%s dropped; bad authentication detected"); p(esps_replay, "possible-replay-detected", "possible replay packet%s detected"); p(esps_input, "received-packets", "packet%s in"); p(esps_output, "sent-packets", "packet%s out"); p(esps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB"); p(esps_ibytes, "receieve-bytes", "byte%s in"); p(esps_obytes, "sent-bytes", "byte%s out"); p(esps_toobig, "dropped-too-large", "packet%s dropped; larger than IP_MAXPACKET"); p(esps_pdrops, "dropped-policy-violation", "packet%s blocked due to policy"); p(esps_crypto, "crypto-failures", "crypto processing failure%s"); p(esps_tunnel, "tunnel-failures", "tunnel sanity check failure%s"); hist(espstat->esps_hist, ipsec_espnames, "ESP output", "esp-output-histogram"); #undef p #undef hist xo_close_container("esp-statictics"); }
static void procstat(struct procstat *prstat, struct kinfo_proc *kipp) { char *pidstr = NULL; asprintf(&pidstr, "%d", kipp->ki_pid); if (pidstr == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in procstat()"); xo_open_container(pidstr); if (bflag) procstat_bin(prstat, kipp); else if (cflag) procstat_args(prstat, kipp); else if (eflag) procstat_env(prstat, kipp); else if (fflag) procstat_files(prstat, kipp); else if (iflag) procstat_sigs(prstat, kipp); else if (jflag) procstat_threads_sigs(prstat, kipp); else if (kflag) procstat_kstack(prstat, kipp, kflag); else if (lflag) procstat_rlimit(prstat, kipp); else if (rflag) procstat_rusage(prstat, kipp); else if (sflag) procstat_cred(prstat, kipp); else if (tflag) procstat_threads(prstat, kipp); else if (vflag) procstat_vm(prstat, kipp); else if (xflag) procstat_auxv(prstat, kipp); else if (Sflag) procstat_cs(prstat, kipp); else procstat_basic(kipp); xo_close_container(pidstr); free(pidstr); }
/* * Dump PIM statistics structure. */ void pim6_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct pim6stat pim6stat, zerostat; size_t len = sizeof pim6stat; if (live) { if (zflag) memset(&zerostat, 0, len); if (sysctlbyname("net.inet6.pim.stats", &pim6stat, &len, zflag ? &zerostat : NULL, zflag ? len : 0) < 0) { if (errno != ENOENT) xo_warn("sysctl: net.inet6.pim.stats"); return; } } else { if (off == 0) return; kread(off, &pim6stat, len); } xo_emit("{T:/%s}:\n", name); xo_open_container(name); #define p(f, m) if (pim6stat.f || sflag <= 1) \ xo_emit(m, (uintmax_t)pim6stat.f, plural(pim6stat.f)) p(pim6s_rcv_total, "\t{:received-packets/%ju} " "{N:/message%s received}\n"); p(pim6s_rcv_tooshort, "\t{:dropped-too-short/%ju} " "{N:/message%s received with too few bytes}\n"); p(pim6s_rcv_badsum, "\t{:dropped-bad-checksum/%ju} " "{N:/message%s received with bad checksum}\n"); p(pim6s_rcv_badversion, "\t{:dropped-bad-version/%ju} " "{N:/message%s received with bad version}\n"); p(pim6s_rcv_registers, "\t{:received-registers/%ju} " "{N:/register%s received}\n"); p(pim6s_rcv_badregisters, "\t{:received-bad-registers/%ju} " "{N:/bad register%s received}\n"); p(pim6s_snd_registers, "\t{:sent-registers/%ju} " "{N:/register%s sent}\n"); #undef p xo_close_container(name); }
static void sctp_print_address(const char *container, union sctp_sockstore *address, int port, int num_port) { struct servent *sp = 0; char line[80], *cp; int width; if (container) xo_open_container(container); switch (address->sa.sa_family) { #ifdef INET case AF_INET: sprintf(line, "%.*s.", Wflag ? 39 : 16, inetname(&address->sin.sin_addr)); break; #endif #ifdef INET6 case AF_INET6: sprintf(line, "%.*s.", Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr)); break; #endif default: sprintf(line, "%.*s.", Wflag ? 39 : 16, ""); break; } cp = strchr(line, '\0'); if (!num_port && port) sp = getservbyport((int)port, "sctp"); if (sp || port == 0) sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); else sprintf(cp, "%d ", ntohs((u_short)port)); width = Wflag ? 45 : 22; xo_emit("{d:target/%-*.*s} ", width, width, line); int alen = cp - line - 1, plen = strlen(cp) - 1; xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, plen, cp); if (container) xo_close_container(container); }
/* * Pretty print an Internet address (net address + port). */ void inetprint(const char *container, struct in_addr *in, int port, const char *proto, int num_port, const int af1) { struct servent *sp = 0; char line[80], *cp; int width; size_t alen, plen; if (container) xo_open_container(container); if (Wflag) snprintf(line, sizeof(line), "%s.", inetname(in)); else snprintf(line, sizeof(line), "%.*s.", (Aflag && !num_port) ? 12 : 16, inetname(in)); alen = strlen(line); cp = line + alen; if (!num_port && port) sp = getservbyport((int)port, proto); if (sp || port == 0) snprintf(cp, sizeof(line) - alen, "%.15s ", sp ? sp->s_name : "*"); else snprintf(cp, sizeof(line) - alen, "%d ", ntohs((u_short)port)); width = (Aflag && !Wflag) ? 18 : ((!Wflag || af1 == AF_INET) ? 22 : 45); if (Wflag) xo_emit("{d:target/%-*s} ", width, line); else xo_emit("{d:target/%-*.*s} ", width, width, line); plen = strlen(cp) - 1; alen--; xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, plen, cp); if (container) xo_close_container(container); }
static void print_ipcompstats(const struct ipcompstat *ipcompstat) { xo_open_container("ipcomp-statictics"); #define p(f, n, m) if (ipcompstat->f || sflag <= 1) \ xo_emit("\t{:" n "/%ju} {N:/" m "}\n", \ (uintmax_t)ipcompstat->f, plural(ipcompstat->f)) #define hist(f, n, t, c) \ ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t), (c)); p(ipcomps_hdrops, "dropped-short-header", "packet%s shorter than header shows"); p(ipcomps_nopf, "dropped-bad-protocol", "packet%s dropped; protocol family not supported"); p(ipcomps_notdb, "dropped-no-tdb", "packet%s dropped; no TDB"); p(ipcomps_badkcr, "dropped-bad-kcr", "packet%s dropped; bad KCR"); p(ipcomps_qfull, "dropped-queue-full", "packet%s dropped; queue full"); p(ipcomps_noxform, "dropped-no-transform", "packet%s dropped; no transform"); p(ipcomps_wrap, "replay-counter-wraps", "replay counter wrap%s"); p(ipcomps_input, "receieve-packets", "packet%s in"); p(ipcomps_output, "sent-packets", "packet%s out"); p(ipcomps_invalid, "dropped-bad-tdb", "packet%s dropped; invalid TDB"); p(ipcomps_ibytes, "receieved-bytes", "byte%s in"); p(ipcomps_obytes, "sent-bytes", "byte%s out"); p(ipcomps_toobig, "dropped-too-large", "packet%s dropped; larger than IP_MAXPACKET"); p(ipcomps_pdrops, "dropped-policy-violation", "packet%s blocked due to policy"); p(ipcomps_crypto, "crypto-failure", "crypto processing failure%s"); hist(ipcompstat->ipcomps_hist, ipsec_compnames, "COMP output", "comp-output-histogram"); p(ipcomps_threshold, "sent-uncompressed-small-packets", "packet%s sent uncompressed; size < compr. algo. threshold"); p(ipcomps_uncompr, "sent-uncompressed-useless-packets", "packet%s sent uncompressed; compression was useless"); #undef p #undef hist xo_close_container("ipcomp-statictics"); }
static void print_ipsecstats(const struct ipsecstat *ipsecstat) { xo_open_container("ipsec-statistics"); #define p(f, m) if (ipsecstat->f || sflag <= 1) \ xo_emit(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f)) p(ips_in_polvio, "\t{:dropped-policy-violation/%ju} " "{N:/inbound packet%s violated process security policy}\n"); p(ips_in_nomem, "\t{:dropped-no-memory/%ju} " "{N:/inbound packet%s failed due to insufficient memory}\n"); p(ips_in_inval, "\t{:dropped-invalid/%ju} " "{N:/invalid inbound packet%s}\n"); p(ips_out_polvio, "\t{:discarded-policy-violation/%ju} " "{N:/outbound packet%s violated process security policy}\n"); p(ips_out_nosa, "\t{:discarded-no-sa/%ju} " "{N:/outbound packet%s with no SA available}\n"); p(ips_out_nomem, "\t{:discarded-no-memory/%ju} " "{N:/outbound packet%s failed due to insufficient memory}\n"); p(ips_out_noroute, "\t{:discarded-no-route/%ju} " "{N:/outbound packet%s with no route available}\n"); p(ips_out_inval, "\t{:discarded-invalid/%ju} " "{N:/invalid outbound packet%s}\n"); p(ips_out_bundlesa, "\t{:send-bundled-sa/%ju} " "{N:/outbound packet%s with bundled SAs}\n"); p(ips_mbcoalesced, "\t{:mbufs-coalesced-during-clone/%ju} " "{N:/mbuf%s coalesced during clone}\n"); p(ips_clcoalesced, "\t{:clusters-coalesced-during-clone/%ju} " "{N:/cluster%s coalesced during clone}\n"); p(ips_clcopied, "\t{:clusters-copied-during-clone/%ju} " "{N:/cluster%s copied during clone}\n"); p(ips_mbinserted, "\t{:mbufs-inserted/%ju} " "{N:/mbuf%s inserted during makespace}\n"); #undef p xo_close_container("ipsec-statistics"); }
void procstat_rlimit(struct procstat *prstat, struct kinfo_proc *kipp) { struct rlimit rlimit; int i; if ((procstat_opts & PS_OPT_NOHEADER) == 0) { xo_emit("{T:/%5s %-16s %-16s %16s %16s}\n", "PID", "COMM", "RLIMIT", "SOFT ", "HARD "); } xo_emit("{ek:process_id/%5d}{e:command/%-16s/%s}", kipp->ki_pid, kipp->ki_comm); for (i = 0; i < RLIM_NLIMITS; i++) { if (procstat_getrlimit(prstat, kipp, i, &rlimit) == -1) return; xo_emit("{dk:process_id/%5d} {d:command/%-16s} " "{d:rlimit_param/%-16s} ", kipp->ki_pid, kipp->ki_comm, rlimit_param[i].name); xo_open_container(rlimit_param[i].name); if (rlimit.rlim_cur == RLIM_INFINITY) xo_emit("{e:soft_limit/infinity}"); else xo_emit("{e:soft_limit/%U}", rlimit.rlim_cur); if (rlimit.rlim_max == RLIM_INFINITY) xo_emit("{e:hard_limit/infinity}"); else xo_emit("{e:hard_limit/%U}", rlimit.rlim_max); xo_close_container(rlimit_param[i].name); xo_emit("{d:rlim_cur/%16s} ", humanize_rlimit(i, rlimit.rlim_cur)); xo_emit("{d:rlim_max/%16s}\n", humanize_rlimit(i, rlimit.rlim_max)); } }
/* * Dump IP statistics structure. */ void ip_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct ipstat ipstat; if (fetch_stats("net.inet.ip.stats", off, &ipstat, sizeof(ipstat), kread_counters) != 0) return; xo_open_container(name); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (ipstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t )ipstat.f, plural(ipstat.f)) #define p1a(f, m) if (ipstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t )ipstat.f) p(ips_total, "\t{:received-packets/%ju} " "{N:/total packet%s received}\n"); p(ips_badsum, "\t{:dropped-bad-checksum/%ju} " "{N:/bad header checksum%s}\n"); p1a(ips_toosmall, "\t{:dropped-below-minimum-size/%ju} " "{N:/with size smaller than minimum}\n"); p1a(ips_tooshort, "\t{:dropped-short-packets/%ju} " "{N:/with data size < data length}\n"); p1a(ips_toolong, "\t{:dropped-too-long/%ju} " "{N:/with ip length > max ip packet size}\n"); p1a(ips_badhlen, "\t{:dropped-short-header-length/%ju} " "{N:/with header length < data size}\n"); p1a(ips_badlen, "\t{:dropped-short-data/%ju} " "{N:/with data length < header length}\n"); p1a(ips_badoptions, "\t{:dropped-bad-options/%ju} " "{N:/with bad options}\n"); p1a(ips_badvers, "\t{:dropped-bad-version/%ju} " "{N:/with incorrect version number}\n"); p(ips_fragments, "\t{:received-fragments/%ju} " "{N:/fragment%s received}\n"); p(ips_fragdropped, "\t{:dropped-fragments/%ju} " "{N:/fragment%s dropped (dup or out of space)}\n"); p(ips_fragtimeout, "\t{:dropped-fragments-after-timeout/%ju} " "{N:/fragment%s dropped after timeout}\n"); p(ips_reassembled, "\t{:reassembled-packets/%ju} " "{N:/packet%s reassembled ok}\n"); p(ips_delivered, "\t{:received-local-packets/%ju} " "{N:/packet%s for this host}\n"); p(ips_noproto, "\t{:dropped-unknown-protocol/%ju} " "{N:/packet%s for unknown\\/unsupported protocol}\n"); p(ips_forward, "\t{:forwarded-packets/%ju} " "{N:/packet%s forwarded}"); p(ips_fastforward, " ({:fast-forwarded-packets/%ju} " "{N:/packet%s fast forwarded})"); if (ipstat.ips_forward || sflag <= 1) xo_emit("\n"); p(ips_cantforward, "\t{:packets-cannot-forward/%ju} " "{N:/packet%s not forwardable}\n"); p(ips_notmember, "\t{:received-unknown-multicast-group/%ju} " "{N:/packet%s received for unknown multicast group}\n"); p(ips_redirectsent, "\t{:redirects-sent/%ju} " "{N:/redirect%s sent}\n"); p(ips_localout, "\t{:sent-packets/%ju} " "{N:/packet%s sent from this host}\n"); p(ips_rawout, "\t{:send-packets-fabricated-header/%ju} " "{N:/packet%s sent with fabricated ip header}\n"); p(ips_odropped, "\t{:discard-no-mbufs/%ju} " "{N:/output packet%s dropped due to no bufs, etc.}\n"); p(ips_noroute, "\t{:discard-no-route/%ju} " "{N:/output packet%s discarded due to no route}\n"); p(ips_fragmented, "\t{:sent-fragments/%ju} " "{N:/output datagram%s fragmented}\n"); p(ips_ofragments, "\t{:fragments-created/%ju} " "{N:/fragment%s created}\n"); p(ips_cantfrag, "\t{:discard-cannot-fragment/%ju} " "{N:/datagram%s that can't be fragmented}\n"); p(ips_nogif, "\t{:discard-tunnel-no-gif/%ju} " "{N:/tunneling packet%s that can't find gif}\n"); p(ips_badaddr, "\t{:discard-bad-address/%ju} " "{N:/datagram%s with bad address in header}\n"); #undef p #undef p1a xo_close_container(name); }
/* * Dump UDP statistics structure. */ void udp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct udpstat udpstat; uint64_t delivered; #ifdef INET6 if (udp_done != 0) return; else udp_done = 1; #endif if (fetch_stats("net.inet.udp.stats", off, &udpstat, sizeof(udpstat), kread_counters) != 0) return; xo_open_container("udp"); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (udpstat.f || sflag <= 1) \ xo_emit("\t" m, (uintmax_t)udpstat.f, plural(udpstat.f)) #define p1a(f, m) if (udpstat.f || sflag <= 1) \ xo_emit("\t" m, (uintmax_t)udpstat.f) p(udps_ipackets, "{:received-datagrams/%ju} " "{N:/datagram%s received}\n"); p1a(udps_hdrops, "{:dropped-incomplete-headers/%ju} " "{N:/with incomplete header}\n"); p1a(udps_badlen, "{:dropped-bad-data-length/%ju} " "{N:/with bad data length field}\n"); p1a(udps_badsum, "{:dropped-bad-checksum/%ju} " "{N:/with bad checksum}\n"); p1a(udps_nosum, "{:dropped-no-checksum/%ju} " "{N:/with no checksum}\n"); p1a(udps_noport, "{:dropped-no-socket/%ju} " "{N:/dropped due to no socket}\n"); p(udps_noportbcast, "{:dropped-broadcast-multicast/%ju} " "{N:/broadcast\\/multicast datagram%s undelivered}\n"); p1a(udps_fullsock, "{:dropped-full-socket-buffer/%ju} " "{N:/dropped due to full socket buffers}\n"); p1a(udpps_pcbhashmiss, "{:not-for-hashed-pcb/%ju} " "{N:/not for hashed pcb}\n"); delivered = udpstat.udps_ipackets - udpstat.udps_hdrops - udpstat.udps_badlen - udpstat.udps_badsum - udpstat.udps_noport - udpstat.udps_noportbcast - udpstat.udps_fullsock; if (delivered || sflag <= 1) xo_emit("\t{:delivered-packets/%ju} {N:/delivered}\n", (uint64_t)delivered); p(udps_opackets, "{:output-packets/%ju} {N:/datagram%s output}\n"); /* the next statistic is cumulative in udps_noportbcast */ p(udps_filtermcast, "{:multicast-source-filter-matches/%ju} " "{N:/time%s multicast source filter matched}\n"); #undef p #undef p1a xo_close_container("udp"); }
/* * Dump TCP statistics structure. */ void tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct tcpstat tcpstat; uint64_t tcps_states[TCP_NSTATES]; #ifdef INET6 if (tcp_done != 0) return; else tcp_done = 1; #endif if (fetch_stats("net.inet.tcp.stats", off, &tcpstat, sizeof(tcpstat), kread_counters) != 0) return; if (fetch_stats_ro("net.inet.tcp.states", nl[N_TCPS_STATES].n_value, &tcps_states, sizeof(tcps_states), kread_counters) != 0) return; xo_open_container("tcp"); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (tcpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t )tcpstat.f, plural(tcpstat.f)) #define p1a(f, m) if (tcpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t )tcpstat.f) #define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \ (uintmax_t )tcpstat.f2, plural(tcpstat.f2)) #define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \ xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \ (uintmax_t )tcpstat.f2) #define p3(f, m) if (tcpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f)) p(tcps_sndtotal, "\t{:sent-packets/%ju} {N:/packet%s sent}\n"); p2(tcps_sndpack,tcps_sndbyte, "\t\t{:sent-data-packets/%ju} " "{N:/data packet%s} ({:sent-data-bytes/%ju} {N:/byte%s})\n"); p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t" "{:sent-retransmitted-packets/%ju} {N:/data packet%s} " "({:sent-retransmitted-bytes/%ju} {N:/byte%s}) " "{N:retransmitted}\n"); p(tcps_sndrexmitbad, "\t\t" "{:sent-unnecessary-retransmitted-packets/%ju} " "{N:/data packet%s unnecessarily retransmitted}\n"); p(tcps_mturesent, "\t\t{:sent-resends-by-mtu-discovery/%ju} " "{N:/resend%s initiated by MTU discovery}\n"); p2a(tcps_sndacks, tcps_delack, "\t\t{:sent-ack-only-packets/%ju} " "{N:/ack-only packet%s/} ({:sent-packets-delayed/%ju} " "{N:delayed})\n"); p(tcps_sndurg, "\t\t{:sent-urg-only-packets/%ju} " "{N:/URG only packet%s}\n"); p(tcps_sndprobe, "\t\t{:sent-window-probe-packets/%ju} " "{N:/window probe packet%s}\n"); p(tcps_sndwinup, "\t\t{:sent-window-update-packets/%ju} " "{N:/window update packet%s}\n"); p(tcps_sndctrl, "\t\t{:sent-control-packets/%ju} " "{N:/control packet%s}\n"); p(tcps_rcvtotal, "\t{:received-packets/%ju} " "{N:/packet%s received}\n"); p2(tcps_rcvackpack, tcps_rcvackbyte, "\t\t" "{:received-ack-packets/%ju} {N:/ack%s} " "{N:(for} {:received-ack-bytes/%ju} {N:/byte%s})\n"); p(tcps_rcvdupack, "\t\t{:received-duplicate-acks/%ju} " "{N:/duplicate ack%s}\n"); p(tcps_rcvacktoomuch, "\t\t{:received-acks-for-unsent-data/%ju} " "{N:/ack%s for unsent data}\n"); p2(tcps_rcvpack, tcps_rcvbyte, "\t\t" "{:received-in-sequence-packets/%ju} {N:/packet%s} " "({:received-in-sequence-bytes/%ju} {N:/byte%s}) " "{N:received in-sequence}\n"); p2(tcps_rcvduppack, tcps_rcvdupbyte, "\t\t" "{:received-completely-duplicate-packets/%ju} " "{N:/completely duplicate packet%s} " "({:received-completely-duplicate-bytes/%ju} {N:/byte%s})\n"); p(tcps_pawsdrop, "\t\t{:received-old-duplicate-packets/%ju} " "{N:/old duplicate packet%s}\n"); p2(tcps_rcvpartduppack, tcps_rcvpartdupbyte, "\t\t" "{:received-some-duplicate-packets/%ju} " "{N:/packet%s with some dup. data} " "({:received-some-duplicate-bytes/%ju} {N:/byte%s duped/})\n"); p2(tcps_rcvoopack, tcps_rcvoobyte, "\t\t{:received-out-of-order/%ju} " "{N:/out-of-order packet%s} " "({:received-out-of-order-bytes/%ju} {N:/byte%s})\n"); p2(tcps_rcvpackafterwin, tcps_rcvbyteafterwin, "\t\t" "{:received-after-window-packets/%ju} {N:/packet%s} " "({:received-after-window-bytes/%ju} {N:/byte%s}) " "{N:of data after window}\n"); p(tcps_rcvwinprobe, "\t\t{:received-window-probes/%ju} " "{N:/window probe%s}\n"); p(tcps_rcvwinupd, "\t\t{:receive-window-update-packets/%ju} " "{N:/window update packet%s}\n"); p(tcps_rcvafterclose, "\t\t{:received-after-close-packets/%ju} " "{N:/packet%s received after close}\n"); p(tcps_rcvbadsum, "\t\t{:discard-bad-checksum/%ju} " "{N:/discarded for bad checksum%s}\n"); p(tcps_rcvbadoff, "\t\t{:discard-bad-header-offset/%ju} " "{N:/discarded for bad header offset field%s}\n"); p1a(tcps_rcvshort, "\t\t{:discard-too-short/%ju} " "{N:discarded because packet too short}\n"); p1a(tcps_rcvmemdrop, "\t\t{:discard-memory-problems/%ju} " "{N:discarded due to memory problems}\n"); p(tcps_connattempt, "\t{:connection-requests/%ju} " "{N:/connection request%s}\n"); p(tcps_accepts, "\t{:connections-accepts/%ju} " "{N:/connection accept%s}\n"); p(tcps_badsyn, "\t{:bad-connection-attempts/%ju} " "{N:/bad connection attempt%s}\n"); p(tcps_listendrop, "\t{:listen-queue-overflows/%ju} " "{N:/listen queue overflow%s}\n"); p(tcps_badrst, "\t{:ignored-in-window-resets/%ju} " "{N:/ignored RSTs in the window%s}\n"); p(tcps_connects, "\t{:connections-established/%ju} " "{N:/connection%s established (including accepts)}\n"); p(tcps_usedrtt, "\t\t{:connections-hostcache-rtt/%ju} " "{N:/time%s used RTT from hostcache}\n"); p(tcps_usedrttvar, "\t\t{:connections-hostcache-rttvar/%ju} " "{N:/time%s used RTT variance from hostcache}\n"); p(tcps_usedssthresh, "\t\t{:connections-hostcache-ssthresh/%ju} " "{N:/time%s used slow-start threshold from hostcache}\n"); p2(tcps_closed, tcps_drops, "\t{:connections-closed/%ju} " "{N:/connection%s closed (including} " "{:connection-drops/%ju} {N:/drop%s})\n"); p(tcps_cachedrtt, "\t\t{:connections-updated-rtt-on-close/%ju} " "{N:/connection%s updated cached RTT on close}\n"); p(tcps_cachedrttvar, "\t\t" "{:connections-updated-variance-on-close/%ju} " "{N:/connection%s updated cached RTT variance on close}\n"); p(tcps_cachedssthresh, "\t\t" "{:connections-updated-ssthresh-on-close/%ju} " "{N:/connection%s updated cached ssthresh on close}\n"); p(tcps_conndrops, "\t{:embryonic-connections-dropped/%ju} " "{N:/embryonic connection%s dropped}\n"); p2(tcps_rttupdated, tcps_segstimed, "\t{:segments-updated-rtt/%ju} " "{N:/segment%s updated rtt (of} " "{:segment-update-attempts/%ju} {N:/attempt%s})\n"); p(tcps_rexmttimeo, "\t{:retransmit-timeouts/%ju} " "{N:/retransmit timeout%s}\n"); p(tcps_timeoutdrop, "\t\t" "{:connections-dropped-by-retransmit-timeout/%ju} " "{N:/connection%s dropped by rexmit timeout}\n"); p(tcps_persisttimeo, "\t{:persist-timeout/%ju} " "{N:/persist timeout%s}\n"); p(tcps_persistdrop, "\t\t" "{:connections-dropped-by-persist-timeout/%ju} " "{N:/connection%s dropped by persist timeout}\n"); p(tcps_finwait2_drops, "\t" "{:connections-dropped-by-finwait2-timeout/%ju} " "{N:/Connection%s (fin_wait_2) dropped because of timeout}\n"); p(tcps_keeptimeo, "\t{:keepalive-timeout/%ju} " "{N:/keepalive timeout%s}\n"); p(tcps_keepprobe, "\t\t{:keepalive-probes/%ju} " "{N:/keepalive probe%s sent}\n"); p(tcps_keepdrops, "\t\t{:connections-dropped-by-keepalives/%ju} " "{N:/connection%s dropped by keepalive}\n"); p(tcps_predack, "\t{:ack-header-predictions/%ju} " "{N:/correct ACK header prediction%s}\n"); p(tcps_preddat, "\t{:data-packet-header-predictions/%ju} " "{N:/correct data packet header prediction%s}\n"); xo_open_container("syncache"); p3(tcps_sc_added, "\t{:entries-added/%ju} " "{N:/syncache entr%s added}\n"); p1a(tcps_sc_retransmitted, "\t\t{:retransmitted/%ju} " "{N:/retransmitted}\n"); p1a(tcps_sc_dupsyn, "\t\t{:duplicates/%ju} {N:/dupsyn}\n"); p1a(tcps_sc_dropped, "\t\t{:dropped/%ju} {N:/dropped}\n"); p1a(tcps_sc_completed, "\t\t{:completed/%ju} {N:/completed}\n"); p1a(tcps_sc_bucketoverflow, "\t\t{:bucket-overflow/%ju} " "{N:/bucket overflow}\n"); p1a(tcps_sc_cacheoverflow, "\t\t{:cache-overflow/%ju} " "{N:/cache overflow}\n"); p1a(tcps_sc_reset, "\t\t{:reset/%ju} {N:/reset}\n"); p1a(tcps_sc_stale, "\t\t{:stale/%ju} {N:/stale}\n"); p1a(tcps_sc_aborted, "\t\t{:aborted/%ju} {N:/aborted}\n"); p1a(tcps_sc_badack, "\t\t{:bad-ack/%ju} {N:/badack}\n"); p1a(tcps_sc_unreach, "\t\t{:unreachable/%ju} {N:/unreach}\n"); p(tcps_sc_zonefail, "\t\t{:zone-failures/%ju} {N:/zone failure%s}\n"); p(tcps_sc_sendcookie, "\t{:sent-cookies/%ju} {N:/cookie%s sent}\n"); p(tcps_sc_recvcookie, "\t{:receivd-cookies/%ju} " "{N:/cookie%s received}\n"); xo_close_container("syncache"); xo_open_container("hostcache"); p3(tcps_hc_added, "\t{:entries-added/%ju} " "{N:/hostcache entr%s added}\n"); p1a(tcps_hc_bucketoverflow, "\t\t{:buffer-overflows/%ju} " "{N:/bucket overflow}\n"); xo_close_container("hostcache"); xo_open_container("sack"); p(tcps_sack_recovery_episode, "\t{:recovery-episodes/%ju} " "{N:/SACK recovery episode%s}\n"); p(tcps_sack_rexmits, "\t{:segment-retransmits/%ju} " "{N:/segment rexmit%s in SACK recovery episodes}\n"); p(tcps_sack_rexmit_bytes, "\t{:byte-retransmits/%ju} " "{N:/byte rexmit%s in SACK recovery episodes}\n"); p(tcps_sack_rcv_blocks, "\t{:received-blocks/%ju} " "{N:/SACK option%s (SACK blocks) received}\n"); p(tcps_sack_send_blocks, "\t{:sent-option-blocks/%ju} " "{N:/SACK option%s (SACK blocks) sent}\n"); p1a(tcps_sack_sboverflow, "\t{:scoreboard-overflows/%ju} " "{N:/SACK scoreboard overflow}\n"); xo_close_container("sack"); xo_open_container("ecn"); p(tcps_ecn_ce, "\t{:ce-packets/%ju} " "{N:/packet%s with ECN CE bit set}\n"); p(tcps_ecn_ect0, "\t{:ect0-packets/%ju} " "{N:/packet%s with ECN ECT(0) bit set}\n"); p(tcps_ecn_ect1, "\t{:ect1-packets/%ju} " "{N:/packet%s with ECN ECT(1) bit set}\n"); p(tcps_ecn_shs, "\t{:handshakes/%ju} " "{N:/successful ECN handshake%s}\n"); p(tcps_ecn_rcwnd, "\t{:congestion-reductions/%ju} " "{N:/time%s ECN reduced the congestion window}\n"); xo_close_container("ecn"); xo_open_container("tcp-signature"); p(tcps_sig_rcvgoodsig, "\t{:received-good-signature/%ju} " "{N:/packet%s with matching signature received}\n"); p(tcps_sig_rcvbadsig, "\t{:received-bad-signature/%ju} " "{N:/packet%s with bad signature received}\n"); p(tcps_sig_err_buildsig, "\t{:failed-make-signature/%ju} " "{N:/time%s failed to make signature due to no SA}\n"); p(tcps_sig_err_sigopt, "\t{:no-signature-expected/%ju} " "{N:/time%s unexpected signature received}\n"); p(tcps_sig_err_nosigopt, "\t{:no-signature-provided/%ju} " "{N:/time%s no signature provided by segment}\n"); #undef p #undef p1a #undef p2 #undef p2a #undef p3 xo_close_container("tcp-signature"); xo_open_container("TCP connection count by state"); xo_emit("{T:/TCP connection count by state}:\n"); for (int i = 0; i < TCP_NSTATES; i++) { /* * XXXGL: is there a way in libxo to use %s * in the "content string" of a format * string? I failed to do that, that's why * a temporary buffer is used to construct * format string for xo_emit(). */ char fmtbuf[80]; if (sflag > 1 && tcps_states[i] == 0) continue; snprintf(fmtbuf, sizeof(fmtbuf), "\t{:%s/%%ju} " "{Np:/connection ,connections} in %s state\n", tcpstates[i], tcpstates[i]); xo_emit(fmtbuf, (uintmax_t )tcps_states[i]); } xo_close_container("TCP connection count by state"); xo_close_container("tcp"); }
/* * Dump IGMP statistics structure. */ void igmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct igmpstat igmpstat; if (fetch_stats("net.inet.igmp.stats", 0, &igmpstat, sizeof(igmpstat), kread) != 0) return; if (igmpstat.igps_version != IGPS_VERSION_3) { xo_warnx("%s: version mismatch (%d != %d)", __func__, igmpstat.igps_version, IGPS_VERSION_3); } if (igmpstat.igps_len != IGPS_VERSION3_LEN) { xo_warnx("%s: size mismatch (%d != %d)", __func__, igmpstat.igps_len, IGPS_VERSION3_LEN); } xo_open_container(name); xo_emit("{T:/%s}:\n", name); #define p64(f, m) if (igmpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t) igmpstat.f, plural(igmpstat.f)) #define py64(f, m) if (igmpstat.f || sflag <= 1) \ xo_emit(m, (uintmax_t) igmpstat.f, pluralies(igmpstat.f)) p64(igps_rcv_total, "\t{:received-messages/%ju} " "{N:/message%s received}\n"); p64(igps_rcv_tooshort, "\t{:dropped-too-short/%ju} " "{N:/message%s received with too few bytes}\n"); p64(igps_rcv_badttl, "\t{:dropped-wrong-ttl/%ju} " "{N:/message%s received with wrong TTL}\n"); p64(igps_rcv_badsum, "\t{:dropped-bad-checksum/%ju} " "{N:/message%s received with bad checksum}\n"); py64(igps_rcv_v1v2_queries, "\t{:received-membership-queries/%ju} " "{N:/V1\\/V2 membership quer%s received}\n"); py64(igps_rcv_v3_queries, "\t{:received-v3-membership-queries/%ju} " "{N:/V3 membership quer%s received}\n"); py64(igps_rcv_badqueries, "\t{:dropped-membership-queries/%ju} " "{N:/membership quer%s received with invalid field(s)}\n"); py64(igps_rcv_gen_queries, "\t{:received-general-queries/%ju} " "{N:/general quer%s received}\n"); py64(igps_rcv_group_queries, "\t{:received-group-queries/%ju} " "{N:/group quer%s received}\n"); py64(igps_rcv_gsr_queries, "\t{:received-group-source-queries/%ju} " "{N:/group-source quer%s received}\n"); py64(igps_drop_gsr_queries, "\t{:dropped-group-source-queries/%ju} " "{N:/group-source quer%s dropped}\n"); p64(igps_rcv_reports, "\t{:received-membership-requests/%ju} " "{N:/membership report%s received}\n"); p64(igps_rcv_badreports, "\t{:dropped-membership-reports/%ju} " "{N:/membership report%s received with invalid field(s)}\n"); p64(igps_rcv_ourreports, "\t" "{:received-membership-reports-matching/%ju} " "{N:/membership report%s received for groups to which we belong}" "\n"); p64(igps_rcv_nora, "\t{:received-v3-reports-no-router-alert/%ju} " "{N:/V3 report%s received without Router Alert}\n"); p64(igps_snd_reports, "\t{:sent-membership-reports/%ju} " "{N:/membership report%s sent}\n"); #undef p64 #undef py64 xo_close_container(name); }
/* * Dump ICMP statistics. */ void icmp_stats(u_long off, const char *name, int af1 __unused, int proto __unused) { struct icmpstat icmpstat; size_t len; int i, first; if (fetch_stats("net.inet.icmp.stats", off, &icmpstat, sizeof(icmpstat), kread_counters) != 0) return; xo_open_container(name); xo_emit("{T:/%s}:\n", name); #define p(f, m) if (icmpstat.f || sflag <= 1) \ xo_emit(m, icmpstat.f, plural(icmpstat.f)) #define p1a(f, m) if (icmpstat.f || sflag <= 1) \ xo_emit(m, icmpstat.f) #define p2(f, m) if (icmpstat.f || sflag <= 1) \ xo_emit(m, icmpstat.f, plurales(icmpstat.f)) p(icps_error, "\t{:icmp-calls/%lu} " "{N:/call%s to icmp_error}\n"); p(icps_oldicmp, "\t{:errors-not-from-message/%lu} " "{N:/error%s not generated in response to an icmp message}\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) { if (icmpstat.icps_outhist[i] != 0) { if (first) { xo_open_list("output-histogram"); xo_emit("\tOutput histogram:\n"); first = 0; } xo_open_instance("output-histogram"); if (icmpnames[i] != NULL) xo_emit("\t\t{k:name/%s}: {:count/%lu}\n", icmpnames[i], icmpstat.icps_outhist[i]); else xo_emit("\t\tunknown ICMP #{k:name/%d}: " "{:count/%lu}\n", i, icmpstat.icps_outhist[i]); xo_close_instance("output-histogram"); } } if (!first) xo_close_list("output-histogram"); p(icps_badcode, "\t{:dropped-bad-code/%lu} " "{N:/message%s with bad code fields}\n"); p(icps_tooshort, "\t{:dropped-too-short/%lu} " "{N:/message%s less than the minimum length}\n"); p(icps_checksum, "\t{:dropped-bad-checksum/%lu} " "{N:/message%s with bad checksum}\n"); p(icps_badlen, "\t{:dropped-bad-length/%lu} " "{N:/message%s with bad length}\n"); p1a(icps_bmcastecho, "\t{:dropped-multicast-echo/%lu} " "{N:/multicast echo requests ignored}\n"); p1a(icps_bmcasttstamp, "\t{:dropped-multicast-timestamp/%lu} " "{N:/multicast timestamp requests ignored}\n"); for (first = 1, i = 0; i < ICMP_MAXTYPE + 1; i++) { if (icmpstat.icps_inhist[i] != 0) { if (first) { xo_open_list("input-histogram"); xo_emit("\tInput histogram:\n"); first = 0; } xo_open_instance("input-histogram"); if (icmpnames[i] != NULL) xo_emit("\t\t{k:name/%s}: {:count/%lu}\n", icmpnames[i], icmpstat.icps_inhist[i]); else xo_emit( "\t\tunknown ICMP #{k:name/%d}: {:count/%lu}\n", i, icmpstat.icps_inhist[i]); xo_close_instance("input-histogram"); } } if (!first) xo_close_list("input-histogram"); p(icps_reflect, "\t{:sent-packets/%lu} " "{N:/message response%s generated}\n"); p2(icps_badaddr, "\t{:discard-invalid-return-address/%lu} " "{N:/invalid return address%s}\n"); p(icps_noroute, "\t{:discard-no-route/%lu} " "{N:/no return route%s}\n"); #undef p #undef p1a #undef p2 if (live) { len = sizeof i; if (sysctlbyname("net.inet.icmp.maskrepl", &i, &len, NULL, 0) < 0) return; xo_emit("\tICMP address mask responses are " "{q:icmp-address-responses/%sabled}\n", i ? "en" : "dis"); } xo_close_container(name); }
int main(int argc, char *argv[]) { int ch, errors, total; (void) setlocale(LC_CTYPE, ""); argc = xo_parse_args(argc, argv); if (argc < 0) return (argc); while ((ch = getopt(argc, argv, "clmwL")) != -1) switch((char)ch) { case 'l': doline = 1; break; case 'w': doword = 1; break; case 'c': dochar = 1; domulti = 0; break; case 'L': dolongline = 1; break; case 'm': domulti = 1; dochar = 0; break; case '?': default: usage(); } argv += optind; argc -= optind; (void)signal(SIGINFO, siginfo_handler); /* Wc's flags are on by default. */ if (doline + doword + dochar + domulti + dolongline == 0) doline = doword = dochar = 1; stderr_handle = xo_create_to_file(stderr, XO_STYLE_TEXT, 0); xo_open_container("wc"); xo_open_list("file"); errors = 0; total = 0; if (!*argv) { xo_open_instance("file"); if (cnt((char *)NULL) != 0) ++errors; xo_close_instance("file"); } else { do { xo_open_instance("file"); if (cnt(*argv) != 0) ++errors; xo_close_instance("file"); ++total; } while(*++argv); } xo_close_list("file"); if (total > 1) { xo_open_container("total"); show_cnt("total", tlinect, twordct, tcharct, tlongline); xo_close_container("total"); } xo_close_container("wc"); xo_finish(); exit(errors == 0 ? 0 : 1); }
/* * Print a description of the nfs stats. */ static void intpr(int clientOnly, int serverOnly) { int nfssvc_flag; nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT; if (zflag != 0) { if (clientOnly != 0) nfssvc_flag |= NFSSVC_ZEROCLTSTATS; if (serverOnly != 0) nfssvc_flag |= NFSSVC_ZEROSRVSTATS; } ext_nfsstats.vers = NFSSTATS_V1; if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0) xo_err(1, "Can't get stats"); if (clientOnly) { xo_open_container("clientstats"); if (printtitle) xo_emit("{T:Client Info:\n"); xo_open_container("operations"); xo_emit("{T:Rpc Counts:}\n"); xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" "{T:Read/%13.13s}{T:Write/%13.13s}" "{T:Create/%13.13s}{T:Remove/%13.13s}\n"); xo_emit("{:getattr/%13ju}{:setattr/%13ju}" "{:lookup/%13ju}{:readlink/%13ju}" "{:read/%13ju}{:write/%13ju}" "{:create/%13ju}{:remove/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE]); xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}" "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}" "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n"); xo_emit("{:rename/%13ju}{:link/%13ju}" "{:symlink/%13ju}{:mkdir/%13ju}" "{:rmdir/%13ju}{:readdir/%13ju}" "{:rdirplus/%13ju}{:access/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS]); xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}" "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}" "{T:Commit/%13.13s}\n"); xo_emit("{:mknod/%13ju}{:fsstat/%13ju}" "{:fsinfo/%13ju}{:pathconf/%13ju}" "{:commit/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT]); xo_close_container("operations"); xo_open_container("rpcs"); xo_emit("{T:Rpc Info:}\n"); xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}" "{T:X Replies/%13.13s}{T:Retries/%13.13s}" "{T:Requests/%13.13s}\n"); xo_emit("{:timedout/%13ju}{:invalid/%13ju}" "{:xreplies/%13ju}{:retries/%13ju}" "{:requests/%13ju}\n", (uintmax_t)ext_nfsstats.rpctimeouts, (uintmax_t)ext_nfsstats.rpcinvalid, (uintmax_t)ext_nfsstats.rpcunexpected, (uintmax_t)ext_nfsstats.rpcretries, (uintmax_t)ext_nfsstats.rpcrequests); xo_close_container("rpcs"); xo_open_container("cache"); xo_emit("{T:Cache Info:}\n"); xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}" "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}" "{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}" "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n"); xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}" "{:lkuphits/%13ju}{:lkupmisses/%13ju}" "{:biorhits/%13ju}{:biormisses/%13ju}" "{:biowhits/%13ju}{:biowmisses/%13ju}\n", (uintmax_t)ext_nfsstats.attrcache_hits, (uintmax_t)ext_nfsstats.attrcache_misses, (uintmax_t)ext_nfsstats.lookupcache_hits, (uintmax_t)ext_nfsstats.lookupcache_misses, (uintmax_t)(ext_nfsstats.biocache_reads - ext_nfsstats.read_bios), (uintmax_t)ext_nfsstats.read_bios, (uintmax_t)(ext_nfsstats.biocache_writes - ext_nfsstats.write_bios), (uintmax_t)ext_nfsstats.write_bios); xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}" "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}" "{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}" "{T:Accs Hits/%13.13s}{T:Accs Misses/%13.13s}\n"); xo_emit("{:biosrlhits/%13ju}{:biorlmisses/%13ju}" "{:biodhits/%13ju}{:biodmisses/%13ju}" "{:direhits/%13ju}{:diremisses/%13ju}" "{:accshits/%13ju}{:accsmisses/%13ju}\n", (uintmax_t)(ext_nfsstats.biocache_readlinks - ext_nfsstats.readlink_bios), (uintmax_t)ext_nfsstats.readlink_bios, (uintmax_t)(ext_nfsstats.biocache_readdirs - ext_nfsstats.readdir_bios), (uintmax_t)ext_nfsstats.readdir_bios, (uintmax_t)ext_nfsstats.direofcache_hits, (uintmax_t)ext_nfsstats.direofcache_misses, (uintmax_t)ext_nfsstats.accesscache_hits, (uintmax_t)ext_nfsstats.accesscache_misses); xo_close_container("cache"); xo_close_container("clientstats"); } if (serverOnly) { xo_open_container("serverstats"); xo_emit("{T:Server Info:}\n"); xo_open_container("operations"); xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" "{T:Read/%13.13s}{T:Write/%13.13s}" "{T:Create/%13.13s}{T:Remove/%13.13s}\n"); xo_emit("{:getattr/%13ju}{:setattr/%13ju}" "{:lookup/%13ju}{:readlink/%13ju}" "{:read/%13ju}{:write/%13ju}" "{:create/%13ju}{:remove/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE]); xo_emit("{T:Rename/%13.13s}{T:Link/%13.13s}" "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}" "{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" "{T:RdirPlus/%13.13s}{T:Access/%13.13s}\n"); xo_emit("{:rename/%13ju}{:link/%13ju}" "{:symlink/%13ju}{:mkdir/%13ju}" "{:rmdir/%13ju}{:readdir/%13ju}" "{:rdirplus/%13ju}{:access/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS]); xo_emit("{T:Mknod/%13.13s}{T:Fsstat/%13.13s}" "{T:Fsinfo/%13.13s}{T:PathConf/%13.13s}" "{T:Commit/%13.13s}\n"); xo_emit("{:mknod/%13ju}{:fsstat/%13ju}" "{:fsinfo/%13ju}{:pathconf/%13ju}" "{:commit/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT]); xo_close_container("operations"); xo_open_container("server"); xo_emit("{T:Server Re-Failed:}\n"); xo_emit("{T:retfailed/%17ju}\n", (uintmax_t)ext_nfsstats.srvrpc_errs); xo_emit("{T:Server Faults:}\n"); xo_emit("{T:faults/%13ju}\n", (uintmax_t)ext_nfsstats.srv_errs); xo_emit("{T:Server Write Gathering:/%13.13s}\n"); xo_emit("{T:WriteOps/%13.13s}{T:WriteRPC/%13.13s}" "{T:Opsaved/%13.13s}\n"); xo_emit("{:writeops/%13ju}{:writerpc/%13ju}" "{:opsaved/%13ju}\n", /* * The new client doesn't do write gathering. It was * only useful for NFSv2. */ (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE], 0); xo_close_container("server"); xo_open_container("cache"); xo_emit("{T:Server Cache Stats:/%13.13s}\n"); xo_emit("{T:Inprog/%13.13s}{T:Idem/%13.13s}" "{T:Non-Idem/%13.13s}{T:Misses/%13.13s}\n"); xo_emit("{:inprog/%13ju}{:idem/%13ju}" "{:nonidem/%13ju}{:misses/%13ju}\n", (uintmax_t)ext_nfsstats.srvcache_inproghits, (uintmax_t)ext_nfsstats.srvcache_idemdonehits, (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits, (uintmax_t)ext_nfsstats.srvcache_misses); xo_close_container("cache"); xo_close_container("serverstats"); } }
int main(int argc, char **argv) { u_int interval; int clientOnly = -1; int serverOnly = -1; int newStats = 0; int ch; char *memf, *nlistf; int mntlen, i; char buf[1024]; struct statfs *mntbuf; struct nfscl_dumpmntopts dumpmntopts; interval = 0; memf = nlistf = NULL; argc = xo_parse_args(argc, argv); if (argc < 0) exit(1); xo_set_version(NFSSTAT_XO_VERSION); while ((ch = getopt(argc, argv, "cdEesWM:mN:w:zq")) != -1) switch(ch) { case 'M': memf = optarg; break; case 'm': /* Display mount options for NFS mount points. */ mntlen = getmntinfo(&mntbuf, MNT_NOWAIT); for (i = 0; i < mntlen; i++) { if (strcmp(mntbuf->f_fstypename, "nfs") == 0) { dumpmntopts.ndmnt_fname = mntbuf->f_mntonname; dumpmntopts.ndmnt_buf = buf; dumpmntopts.ndmnt_blen = sizeof(buf); if (nfssvc(NFSSVC_DUMPMNTOPTS, &dumpmntopts) >= 0) printf("%s on %s\n%s\n", mntbuf->f_mntfromname, mntbuf->f_mntonname, buf); else if (errno == EPERM) errx(1, "Only priviledged users" " can use the -m option"); } mntbuf++; } exit(0); case 'N': nlistf = optarg; break; case 'W': widemode = 1; break; case 'w': interval = atoi(optarg); break; case 'c': clientOnly = 1; if (serverOnly < 0) serverOnly = 0; break; case 'd': newStats = 1; if (interval == 0) interval = 1; break; case 's': serverOnly = 1; if (clientOnly < 0) clientOnly = 0; break; case 'z': zflag = 1; break; case 'E': if (extra_output != 0) xo_err(1, "-e and -E are mutually exclusive"); extra_output = 2; break; case 'e': if (extra_output != 0) xo_err(1, "-e and -E are mutually exclusive"); extra_output = 1; break; case 'q': printtitle = 0; break; case '?': default: usage(); } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { interval = atoi(*argv); if (*++argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif if (modfind("nfscommon") < 0) xo_err(1, "NFS client/server not loaded"); if (interval) { exp_sidewaysintpr(interval, clientOnly, serverOnly, newStats); } else { xo_open_container("nfsstat"); if (extra_output != 0) exp_intpr(clientOnly, serverOnly, extra_output - 1); else intpr(clientOnly, serverOnly); xo_close_container("nfsstat"); } xo_finish(); exit(0); }
int main (int argc, char **argv) { argc = xo_parse_args(argc, argv); if (argc < 0) return 1; for (argc = 1; argv[argc]; argc++) { if (strcmp(argv[argc], "xml") == 0) xo_set_style(NULL, XO_STYLE_XML); else if (strcmp(argv[argc], "json") == 0) xo_set_style(NULL, XO_STYLE_JSON); else if (strcmp(argv[argc], "text") == 0) xo_set_style(NULL, XO_STYLE_TEXT); else if (strcmp(argv[argc], "html") == 0) xo_set_style(NULL, XO_STYLE_HTML); else if (strcmp(argv[argc], "pretty") == 0) xo_set_flags(NULL, XOF_PRETTY); else if (strcmp(argv[argc], "xpath") == 0) xo_set_flags(NULL, XOF_XPATH); else if (strcmp(argv[argc], "info") == 0) xo_set_flags(NULL, XOF_INFO); } xo_set_flags(NULL, XOF_UNITS); /* Always test w/ this */ xo_open_container_h(NULL, "top"); xo_open_container("data"); xo_emit("We are {{emit}}{{ting}} some {:what}\n", "braces"); xo_message("abcdef"); close(-1); xo_message_e("abcdef"); xo_message("improper use of profanity; %s; %s", "ten yard penalty", "first down"); xo_emit("length {:length/%6.6s}\n", "abcdefghijklmnopqrstuvwxyz"); close(-1); xo_emit("close {:fd/%d} returned {:error/%m} {:test}\n", -1, "good"); close(-1); xo_emit("close {:fd/%d} returned {:error/%6.6m} {:test}\n", -1, "good"); xo_message("improper use of profanity; %s; %s", "ten yard penalty", "first down"); xo_emit(" {:lines/%7ju} {:words/%7ju} " "{:characters/%7ju} {d:filename/%s}\n", 20, 30, 40, "file"); int i; for (i = 0; i < 5; i++) xo_emit("{lw:bytes/%d}{Np:byte,bytes}\n", i); xo_emit("{:mbuf-current/%u}/{:mbuf-cache/%u}/{:mbuf-total/%u} " "{N:mbufs <&> in use (current\\/cache\\/total)}\n", 10, 20, 30); xo_emit("{:distance/%u}{Uw:miles} from {:location}\n", 50, "Boston"); xo_emit("{:memory/%u}{U:k} left out of {:total/%u}{U:kb}\n", 64, 640); xo_emit("{:memory/%u}{U:/%s} left out of {:total/%u}{U:/%s}\n", 64, "k", 640, "kilobytes"); xo_emit("{,title:/before%safter:}\n", "working"); xo_emit("{,display,white,colon:some/%s}" "{,value:ten/%ju}{,value:eleven/%ju}\n", "string", (uintmax_t) 10, (uintmax_t) 11); xo_emit("{:unknown/%u} " "{N:/packet%s here\\/there\\/everywhere}\n", 1010, "s"); xo_emit("{:unknown/%u} " "{,note:/packet%s here\\/there\\/everywhere}\n", 1010, "s"); xo_emit("({[:/%d}{n:min/15}/{n:cur/20}/{:max/%d}{]:})\n", 30, 125); xo_emit("({[:30}{:min/%u}/{:cur/%u}/{:max/%u}{]:})\n", 15, 20, 125); xo_emit("({[:-30}{n:min/15}/{n:cur/20}/{n:max/125}{]:})\n"); xo_emit("({[:}{:min/%u}/{:cur/%u}/{:max/%u}{]:/%d})\n", 15, 20, 125, -30); xo_emit("Humanize: {h:val1/%u}, {h,hn-space:val2/%u}, " "{h,hn-decimal:val3/%u}, {h,hn-1000:val4/%u}, " "{h,hn-decimal:val5/%u}\n", 21, 57 * 1024, 96 * 1024 * 1024, (42 * 1024 + 420) * 1024, 1342172800); xo_open_list("flag"); xo_emit("{lq:flag/one} {lq:flag/two} {lq:flag/three}\n"); xo_close_list("flag"); xo_emit("{n:works/%s}\n", NULL); xo_emit("{e:empty-tag/}"); xo_emit("1:{qt:t1/%*d} 2:{qt:t2/test%-*u} " "3:{qt:t3/%10sx} 4:{qt:t4/x%-*.*s}\n", 6, 1000, 8, 5000, "ten-long", 10, 10, "test"); xo_emit("{E:this is an error}\n"); xo_emit("{E:/%s more error%s}\n", "two", "s" ); xo_emit("{W:this is an warning}\n"); xo_emit("{W:/%s more warning%s}\n", "two", "s" ); xo_emit("{L:/V1\\/V2 packet%s}: {:count/%u}\n", "s", 10); int test = 4; xo_emit("{:test/%04d} {L:/tr%s}\n", test, (test == 1) ? "y" : "ies"); xo_message("improper use of profanity; %s; %s", "ten yard penalty", "first down"); xo_error("Shut 'er down, Clancey! She's a-pumpin' mud! <>!,\"!<>\n"); xo_close_container("data"); xo_close_container_h(NULL, "top"); xo_finish(); return 0; }
/* * Print a description of the nfs stats for the client/server, * including NFSv4.1. */ static void exp_intpr(int clientOnly, int serverOnly, int nfs41) { int nfssvc_flag; xo_open_container("nfsv4"); nfssvc_flag = NFSSVC_GETSTATS | NFSSVC_NEWSTRUCT; if (zflag != 0) { if (clientOnly != 0) nfssvc_flag |= NFSSVC_ZEROCLTSTATS; if (serverOnly != 0) nfssvc_flag |= NFSSVC_ZEROSRVSTATS; } ext_nfsstats.vers = NFSSTATS_V1; if (nfssvc(nfssvc_flag, &ext_nfsstats) < 0) xo_err(1, "Can't get stats"); if (clientOnly != 0) { xo_open_container("clientstats"); xo_open_container("operations"); if (printtitle) { xo_emit("{T:Client Info:}\n"); xo_emit("{T:RPC Counts:}\n"); } xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" "{T:Read/%13.13s}{T:Write/%13.13s}\n"); xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}" "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETATTR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETATTR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOOKUP], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READLINK], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READ], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITE]); xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}" "{T:Rename/%13.13s}{T:Link/%13.13s}" "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n"); xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}" "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATE], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_REMOVE], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RENAME], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LINK], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SYMLINK], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKDIR]); xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" "{T:RdirPlus/%13.13s}{T:Access/%13.13s}" "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n"); xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}" "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RMDIR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIR], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDIRPLUS], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_ACCESS], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_MKNOD], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSSTAT]); xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}" "{T:Commit/%13.13s}{T:SetClId/%13.13s}" "{T:SetClIdCf/%13.13s}{T:Lock/%13.13s}\n"); xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}" "{:setclientid/%13ju}{:setclientidcf/%13ju}{:lock/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FSINFO], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PATHCONF], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMIT], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTID], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETCLIENTIDCFRM], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCK]); xo_emit("{T:LockT/%13.13s}{T:LockU/%13.13s}" "{T:Open/%13.13s}{T:OpenCfr/%13.13s}\n"); xo_emit("{:lockt/%13ju}{:locku/%13ju}" "{:open/%13ju}{:opencfr/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKT], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LOCKU], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPEN], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENCONFIRM]); if (nfs41) { xo_open_container("nfsv41"); xo_emit("{T:OpenDownGr/%13.13s}{T:Close/%13.13s}\n"); xo_emit("{:opendowngr/%13ju}{:close/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENDOWNGRADE], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CLOSE]); xo_emit("{T:RelLckOwn/%13.13s}{T:FreeStateID/%13.13s}" "{T:PutRootFH/%13.13s}{T:DelegRet/%13.13s}" "{T:GetAcl/%13.13s}{T:SetAcl/%13.13s}\n"); xo_emit("{:rellckown/%13ju}{:freestateid/%13ju}" "{:getacl/%13ju}{:delegret/%13ju}" "{:getacl/%13ju}{:setacl/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RELEASELCKOWN], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_FREESTATEID], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_PUTROOTFH], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DELEGRETURN], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETACL], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_SETACL]); xo_emit("{T:ExchangeId/%13.13s}{T:CreateSess/%13.13s}" "{T:DestroySess/%13.13s}{T:DestroyClId/%13.13s}" "{T:LayoutGet/%13.13s}{T:GetDevInfo/%13.13s}\n"); xo_emit("{:exchangeid/%13ju}{:createsess/%13ju}" "{:destroysess/%13ju}{:destroyclid/%13ju}" "{:layoutget/%13ju}{:getdevinfo/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_EXCHANGEID], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATESESSION], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYSESSION], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_DESTROYCLIENT], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTGET], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_GETDEVICEINFO]); xo_emit("{T:LayoutCommit/%13.13s}{T:LayoutReturn/%13.13s}" "{T:ReclaimCompl/%13.13s}{T:ReadDataS/%13.13s}" "{T:WriteDataS/%13.13s}{T:CommitDataS/%13.13s}\n"); xo_emit("{:layoutcomit/%13ju}{:layoutreturn/%13ju}" "{:reclaimcompl/%13ju}{:readdatas/%13ju}" "{:writedatas/%13ju}{:commitdatas/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTCOMMIT], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_LAYOUTRETURN], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_RECLAIMCOMPL], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_READDS], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_WRITEDS], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_COMMITDS]); xo_emit("{T:OpenLayout/%13.13s}{T:CreateLayout/%13.13s}\n"); xo_emit("{:openlayout/%13ju}{:createlayout/%13ju}\n", (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_OPENLAYGET], (uintmax_t)ext_nfsstats.rpccnt[NFSPROC_CREATELAYGET]); xo_close_container("nfsv41"); } xo_close_container("operations"); xo_open_container("client"); xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}" "{T:LockOwner/%13.13s}{T:Locks/%13.13s}" "{T:Delegs/%13.13s}{T:LocalOwn/%13.13s}\n"); xo_emit("{:openowner/%13ju}{:opens/%13ju}" "{:lockowner/%13ju}{:locks/%13ju}" "{:delegs/%13ju}{:localown/%13ju}\n", (uintmax_t)ext_nfsstats.clopenowners, (uintmax_t)ext_nfsstats.clopens, (uintmax_t)ext_nfsstats.cllockowners, (uintmax_t)ext_nfsstats.cllocks, (uintmax_t)ext_nfsstats.cldelegates, (uintmax_t)ext_nfsstats.cllocalopenowners); xo_emit("{T:LocalOpen/%13.13s}{T:LocalLown/%13.13s}" "{T:LocalLock/%13.13s}\n"); xo_emit("{:localopen/%13ju}{:locallown/%13ju}" "{:locallock/%13ju}\n", (uintmax_t)ext_nfsstats.cllocalopens, (uintmax_t)ext_nfsstats.cllocallockowners, (uintmax_t)ext_nfsstats.cllocallocks); xo_close_container("client"); xo_open_container("rpc"); if (printtitle) xo_emit("{T:Rpc Info:}\n"); xo_emit("{T:TimedOut/%13.13s}{T:Invalid/%13.13s}" "{T:X Replies/%13.13s}{T:Retries/%13.13s}" "{T:Requests/%13.13s}\n"); xo_emit("{:timedout/%13ju}{:invalid/%13ju}" "{:xreplies/%13ju}{:retries/%13ju}" "{:requests/%13ju}\n", (uintmax_t)ext_nfsstats.rpctimeouts, (uintmax_t)ext_nfsstats.rpcinvalid, (uintmax_t)ext_nfsstats.rpcunexpected, (uintmax_t)ext_nfsstats.rpcretries, (uintmax_t)ext_nfsstats.rpcrequests); xo_close_container("rpc"); xo_open_container("cache"); if (printtitle) xo_emit("{T:Cache Info:}\n"); xo_emit("{T:Attr Hits/%13.13s}{T:Attr Misses/%13.13s}" "{T:Lkup Hits/%13.13s}{T:Lkup Misses/%13.13s}\n"); xo_emit("{:attrhits/%13ju}{:attrmisses/%13ju}" "{:lkuphits/%13ju}{:lkupmisses/%13ju}\n", (uintmax_t)ext_nfsstats.attrcache_hits, (uintmax_t)ext_nfsstats.attrcache_misses, (uintmax_t)ext_nfsstats.lookupcache_hits, (uintmax_t)ext_nfsstats.lookupcache_misses); xo_emit("{T:BioR Hits/%13.13s}{T:BioR Misses/%13.13s}" "{T:BioW Hits/%13.13s}{T:BioW Misses/%13.13s}\n"); xo_emit("{:biorhits/%13ju}{:biormisses/%13ju}" "{:biowhits/%13ju}{:biowmisses/%13ju}\n", (uintmax_t)(ext_nfsstats.biocache_reads - ext_nfsstats.read_bios), (uintmax_t)ext_nfsstats.read_bios, (uintmax_t)(ext_nfsstats.biocache_writes - ext_nfsstats.write_bios), (uintmax_t)ext_nfsstats.write_bios); xo_emit("{T:BioRL Hits/%13.13s}{T:BioRL Misses/%13.13s}" "{T:BioD Hits/%13.13s}{T:BioD Misses/%13.13s}\n"); xo_emit("{:biorlhits/%13ju}{:biorlmisses/%13ju}" "{:biodhits/%13ju}{:biodmisses/%13ju}\n", (uintmax_t)(ext_nfsstats.biocache_readlinks - ext_nfsstats.readlink_bios), (uintmax_t)ext_nfsstats.readlink_bios, (uintmax_t)(ext_nfsstats.biocache_readdirs - ext_nfsstats.readdir_bios), (uintmax_t)ext_nfsstats.readdir_bios); xo_emit("{T:DirE Hits/%13.13s}{T:DirE Misses/%13.13s}\n"); xo_emit("{:direhits/%13ju}{:diremisses/%13ju}\n", (uintmax_t)ext_nfsstats.direofcache_hits, (uintmax_t)ext_nfsstats.direofcache_misses); xo_open_container("cache"); xo_close_container("clientstats"); } if (serverOnly != 0) { xo_open_container("serverstats"); xo_open_container("operations"); if (printtitle) xo_emit("{T:Server Info:}\n"); xo_emit("{T:Getattr/%13.13s}{T:Setattr/%13.13s}" "{T:Lookup/%13.13s}{T:Readlink/%13.13s}" "{T:Read/%13.13s}{T:Write/%13.13s}\n"); xo_emit("{:getattr/%13ju}{:setattr/%13ju}{:lookup/%13ju}" "{:readlink/%13ju}{:read/%13ju}{:write/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETATTR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETATTR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUP], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READLINK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READ], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WRITE]); xo_emit("{T:Create/%13.13s}{T:Remove/%13.13s}" "{T:Rename/%13.13s}{T:Link/%13.13s}" "{T:Symlink/%13.13s}{T:Mkdir/%13.13s}\n"); xo_emit("{:create/%13ju}{:remove/%13ju}{:rename/%13ju}" "{:link/%13ju}{:symlink/%13ju}{:mkdir/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_V3CREATE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_REMOVE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENAME], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LINK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SYMLINK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKDIR]); xo_emit("{T:Rmdir/%13.13s}{T:Readdir/%13.13s}" "{T:RdirPlus/%13.13s}{T:Access/%13.13s}" "{T:Mknod/%13.13s}{T:Fsstat/%13.13s}\n"); xo_emit("{:rmdir/%13ju}{:readdir/%13ju}{:rdirplus/%13ju}" "{:access/%13ju}{:mknod/%13ju}{:fsstat/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RMDIR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_READDIRPLUS], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_ACCESS], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_MKNOD], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSSTAT]); xo_emit("{T:FSinfo/%13.13s}{T:pathConf/%13.13s}" "{T:Commit/%13.13s}{T:LookupP/%13.13s}" "{T:SetClId/%13.13s}{T:SetClIdCf/%13.13s}\n"); xo_emit("{:fsinfo/%13ju}{:pathconf/%13ju}{:commit/%13ju}" "{:lookupp/%13ju}{:setclientid/%13ju}{:setclientidcfrm/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FSINFO], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PATHCONF], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_COMMIT], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOOKUPP], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTID], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETCLIENTIDCFRM]); xo_emit("{T:Open/%13.13s}{T:OpenAttr/%13.13s}" "{T:OpenDwnGr/%13.13s}{T:OpenCfrm/%13.13s}" "{T:DelePurge/%13.13s}{T:DelRet/%13.13s}\n"); xo_emit("{:open/%13ju}{:openattr/%13ju}{:opendwgr/%13ju}" "{:opencfrm/%13ju}{:delepurge/%13ju}{:delreg/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPEN], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENATTR], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENDOWNGRADE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_OPENCONFIRM], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGPURGE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DELEGRETURN]); xo_emit("{T:GetFH/%13.13s}{T:Lock/%13.13s}" "{T:LockT/%13.13s}{T:LockU/%13.13s}" "{T:Close/%13.13s}{T:Verify/%13.13s}\n"); xo_emit("{:getfh/%13ju}{:lock/%13ju}{:lockt/%13ju}" "{:locku/%13ju}{:close/%13ju}{:verify/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETFH], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCK], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKT], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LOCKU], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CLOSE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_VERIFY]); xo_emit("{T:NVerify/%13.13s}{T:PutFH/%13.13s}" "{T:PutPubFH/%13.13s}{T:PutRootFH/%13.13s}" "{T:Renew/%13.13s}{T:RestoreFH/%13.13s}\n"); xo_emit("{:nverify/%13ju}{:putfh/%13ju}{:putpubfh/%13ju}" "{:putrootfh/%13ju}{:renew/%13ju}{:restore/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_NVERIFY], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTFH], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTPUBFH], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_PUTROOTFH], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RENEW], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RESTOREFH]); xo_emit("{T:SaveFH/%13.13s}{T:Secinfo/%13.13s}" "{T:RelLockOwn/%13.13s}{T:V4Create/%13.13s}\n"); xo_emit("{:savefh/%13ju}{:secinfo/%13ju}{:rellockown/%13ju}" "{:v4create/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SAVEFH], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFO], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RELEASELCKOWN], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATE]); if (nfs41) { xo_open_container("nfsv41"); xo_emit("{T:BackChannelCtrl/%13.13s}{T:BindConnToSess/%13.13s}" "{T:ExchangeID/%13.13s}{T:CreateSess/%13.13s}" "{T:DestroySess/%13.13s}{T:FreeStateID/%13.13s}\n"); xo_emit("{:backchannelctrl/%13ju}{:bindconntosess/%13ju}" "{:exchangeid/%13ju}{:createsess/%13ju}" "{:destroysess/%13ju}{:freestateid/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BACKCHANNELCTL], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_BINDCONNTOSESS], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_EXCHANGEID], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_CREATESESSION], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYSESSION], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_FREESTATEID]), xo_emit("{T:GetDirDeleg/%13.13s}{T:GetDevInfo/%13.13s}" "{T:GetDevList/%13.13s}{T:layoutCommit/%13.13s}" "{T:LayoutGet/%13.13s}{T:LayoutReturn/%13.13s}\n"); xo_emit("{:getdirdeleg/%13ju}{:getdevinfo/%13ju}" "{:getdevlist/%13ju}{:layoutcommit/%13ju}" "{:layoutget/%13ju}{:layoutreturn/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDIRDELEG], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVINFO], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_GETDEVLIST], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTCOMMIT], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTGET], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_LAYOUTRETURN]); xo_emit("{T:SecInfNoName/%13.13s}{T:Sequence/%13.13s}" "{T:SetSSV/%13.13s}{T:TestStateID/%13.13s}" "{T:WantDeleg/%13.13s}{T:DestroyClId/%13.13s}\n"); xo_emit("{:secinfnoname/%13ju}{:sequence/%13ju}" "{:setssv/%13ju}{:teststateid/%13ju}{:wantdeleg/%13ju}" "{:destroyclid/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SECINFONONAME], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SEQUENCE], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_SETSSV], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_TESTSTATEID], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_WANTDELEG], (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_DESTROYCLIENTID]); xo_emit("{T:ReclaimCompl/%13.13s}\n"); xo_emit("{:reclaimcompl/%13ju}\n", (uintmax_t)ext_nfsstats.srvrpccnt[NFSV4OP_RECLAIMCOMPL]); xo_close_container("nfsv41"); } xo_close_container("operations"); if (printtitle) xo_emit("{T:Server:}\n"); xo_open_container("server"); xo_emit("{T:Retfailed/%13.13s}{T:Faults/%13.13s}" "{T:Clients/%13.13s}\n"); xo_emit("{:retfailed/%13ju}{:faults/%13ju}{:clients/%13ju}\n", (uintmax_t)ext_nfsstats.srv_errs, (uintmax_t)ext_nfsstats.srvrpc_errs, (uintmax_t)ext_nfsstats.srvclients); xo_emit("{T:OpenOwner/%13.13s}{T:Opens/%13.13s}" "{T:LockOwner/%13.13s}{T:Locks/%13.13s}" "{T:Delegs/%13.13s}\n"); xo_emit("{:openowner/%13ju}{:opens/%13ju}{:lockowner/%13ju}" "{:locks/%13ju}{:delegs/%13ju}\n", (uintmax_t)ext_nfsstats.srvopenowners, (uintmax_t)ext_nfsstats.srvopens, (uintmax_t)ext_nfsstats.srvlockowners, (uintmax_t)ext_nfsstats.srvlocks, (uintmax_t)ext_nfsstats.srvdelegates); xo_close_container("server"); if (printtitle) xo_emit("{T:Server Cache Stats:}\n"); xo_open_container("cache"); xo_emit("{T:Inprog/%13.13s}{T:Idem/%13.13s}" "{T:Non-idem/%13.13s}{T:Misses/%13.13s}" "{T:CacheSize/%13.13s}{T:TCPPeak/%13.13s}\n"); xo_emit("{:inprog/%13ju}{:idem/%13ju}{:nonidem/%13ju}" "{:misses/%13ju}{:cachesize/%13ju}{:tcppeak/%13ju}\n", (uintmax_t)ext_nfsstats.srvcache_inproghits, (uintmax_t)ext_nfsstats.srvcache_idemdonehits, (uintmax_t)ext_nfsstats.srvcache_nonidemdonehits, (uintmax_t)ext_nfsstats.srvcache_misses, (uintmax_t)ext_nfsstats.srvcache_size, (uintmax_t)ext_nfsstats.srvcache_tcppeak); xo_close_container("cache"); xo_close_container("serverstats"); } xo_close_container("nfsv4"); }
void procstat_threads(struct procstat *procstat, struct kinfo_proc *kipp) { struct kinfo_proc *kip; unsigned int count, i; const char *str; char *threadid; if (!hflag) xo_emit("{T:/%5s %6s %-19s %-19s %2s %4s %-7s %-9s}\n", "PID", "TID", "COMM", "TDNAME", "CPU", "PRI", "STATE", "WCHAN"); xo_emit("{ek:process_id/%d}", kipp->ki_pid); xo_emit("{e:command/%s}", strlen(kipp->ki_comm) ? kipp->ki_comm : "-"); xo_open_container("threads"); kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD, kipp->ki_pid, &count); if (kip == NULL) return; kinfo_proc_sort(kip, count); for (i = 0; i < count; i++) { kipp = &kip[i]; asprintf(&threadid, "%d", kipp->ki_tid); if (threadid == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in " "procstat_threads()"); xo_open_container(threadid); xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid); xo_emit("{:thread_id/%6d/%d} ", kipp->ki_tid); xo_emit("{d:command/%-19s/%s} ", strlen(kipp->ki_comm) ? kipp->ki_comm : "-"); xo_emit("{:thread_name/%-19s/%s} ", kinfo_proc_thread_name(kipp)); if (kipp->ki_oncpu != 255) xo_emit("{:cpu/%3d/%d} ", kipp->ki_oncpu); else if (kipp->ki_lastcpu != 255) xo_emit("{:cpu/%3d/%d} ", kipp->ki_lastcpu); else xo_emit("{:cpu/%3s/%s} ", "-"); xo_emit("{:priority/%4d/%d} ", kipp->ki_pri.pri_level); switch (kipp->ki_stat) { case SRUN: str = "run"; break; case SSTOP: str = "stop"; break; case SSLEEP: str = "sleep"; break; case SLOCK: str = "lock"; break; case SWAIT: str = "wait"; break; case SZOMB: str = "zomb"; break; case SIDL: str = "idle"; break; default: str = "??"; break; } xo_emit("{:run_state/%-7s/%s} ", str); if (kipp->ki_kiflag & KI_LOCKBLOCK) { xo_emit("{:lock_name/*%-8s/%s} ", strlen(kipp->ki_lockname) ? kipp->ki_lockname : "-"); } else { xo_emit("{:wait_channel/%-9s/%s} ", strlen(kipp->ki_wmesg) ? kipp->ki_wmesg : "-"); } xo_close_container(threadid); free(threadid); xo_emit("\n"); } xo_close_container("threads"); procstat_freeprocs(procstat, kip); }