MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tcp_stats

Function tcp_stats

tools/netstat/inet.c:604–882  ·  view source on GitHub ↗

* Dump TCP statistics structure. */

Source from the content-addressed store, hash-verified

602 * Dump TCP statistics structure.
603 */
604void
605tcp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
606{
607 struct tcpstat tcpstat;
608 uint64_t tcps_states[TCP_NSTATES];
609
610#ifdef INET6
611 if (tcp_done != 0)
612 return;
613 else
614 tcp_done = 1;
615#endif
616
617 if (fetch_stats("net.inet.tcp.stats", off, &tcpstat,
618 sizeof(tcpstat), kread_counters) != 0)
619 return;
620
621 if (fetch_stats_ro("net.inet.tcp.states", nl[N_TCPS_STATES].n_value,
622 &tcps_states, sizeof(tcps_states), kread_counters) != 0)
623 return;
624
625 xo_open_container("tcp");
626 xo_emit("{T:/%s}:\n", name);
627
628#define p(f, m) if (tcpstat.f || sflag <= 1) \
629 xo_emit(m, (uintmax_t )tcpstat.f, plural(tcpstat.f))
630#define p1a(f, m) if (tcpstat.f || sflag <= 1) \
631 xo_emit(m, (uintmax_t )tcpstat.f)
632#define p2(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
633 xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \
634 (uintmax_t )tcpstat.f2, plural(tcpstat.f2))
635#define p2a(f1, f2, m) if (tcpstat.f1 || tcpstat.f2 || sflag <= 1) \
636 xo_emit(m, (uintmax_t )tcpstat.f1, plural(tcpstat.f1), \
637 (uintmax_t )tcpstat.f2)
638#define p3(f, m) if (tcpstat.f || sflag <= 1) \
639 xo_emit(m, (uintmax_t )tcpstat.f, pluralies(tcpstat.f))
640
641 p(tcps_sndtotal, "\t{:sent-packets/%ju} {N:/packet%s sent}\n");
642 p2(tcps_sndpack,tcps_sndbyte, "\t\t{:sent-data-packets/%ju} "
643 "{N:/data packet%s} ({:sent-data-bytes/%ju} {N:/byte%s})\n");
644 p2(tcps_sndrexmitpack, tcps_sndrexmitbyte, "\t\t"
645 "{:sent-retransmitted-packets/%ju} {N:/data packet%s} "
646 "({:sent-retransmitted-bytes/%ju} {N:/byte%s}) "
647 "{N:retransmitted}\n");
648 p(tcps_sndrexmitbad, "\t\t"
649 "{:sent-unnecessary-retransmitted-packets/%ju} "
650 "{N:/data packet%s unnecessarily retransmitted}\n");
651 p(tcps_mturesent, "\t\t{:sent-resends-by-mtu-discovery/%ju} "
652 "{N:/resend%s initiated by MTU discovery}\n");
653 p2a(tcps_sndacks, tcps_delack, "\t\t{:sent-ack-only-packets/%ju} "
654 "{N:/ack-only packet%s/} ({:sent-packets-delayed/%ju} "
655 "{N:delayed})\n");
656 p(tcps_sndurg, "\t\t{:sent-urg-only-packets/%ju} "
657 "{N:/URG only packet%s}\n");
658 p(tcps_sndprobe, "\t\t{:sent-window-probe-packets/%ju} "
659 "{N:/window probe packet%s}\n");
660 p(tcps_sndwinup, "\t\t{:sent-window-update-packets/%ju} "
661 "{N:/window update packet%s}\n");

Callers

nothing calls this directly

Calls 6

fetch_statsFunction · 0.85
fetch_stats_roFunction · 0.85
xo_open_containerFunction · 0.85
xo_emitFunction · 0.85
xo_close_containerFunction · 0.85
snprintfFunction · 0.85

Tested by

no test coverage detected