1# -*- tab-width: 4 -*- ;; Emacs 2# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3############################################################ IDENT(1) 4# 5# $Title: dwatch(8) module for network stack counter probes $ 6# $Copyright: 2026 Devin Teske. All rights reserved. $ 7# 8############################################################ DESCRIPTION 9# 10# Print network stack statistics counters as they increment, via the 11# mib SDT probes (one probe per counter of the IP, ICMP, UDP, and TCP 12# MIBs). The tcp-retransmit profile watches the counters that signal 13# congestion or loss on the send path -- data packet retransmissions, 14# retransmit timer expirations, and connections dropped by retransmit 15# exhaustion -- answering "is this network slow because TCP is 16# resending?" as events with process context, not just netstat(1) 17# deltas. Use mib-NAME to watch a single counter by name (e.g., 18# mib-tcps_sndrexmitpack). NB: the probes exist only in kernels built 19# with options KDTRACE_MIB_SDT (enabled by default in -CURRENT via 20# std.debug); elsewhere dtrace(1) will refuse the script. Counters 21# bumped outside syscall context (e.g., timers) are tagged with the 22# interrupted thread, commonly [clock] or [intr]. 23# 24############################################################ PROBE 25 26case "$PROFILE" in 27mib) 28 : ${PROBE:=mib:::} ;; 29tcp-retransmit) 30 : ${PROBE:=$( echo \ 31 mib:tcp:count:tcps_sndrexmitpack, \ 32 mib:tcp:count:tcps_sndrexmitbad, \ 33 mib:tcp:count:tcps_rexmttimeo, \ 34 mib:tcp:count:tcps_timeoutdrop )} ;; 35*) 36 : ${PROBE:=mib:::${PROFILE#mib-}} 37esac 38 39############################################################ ACTIONS 40 41exec 9<<EOF 42this string mib_desc; 43 44/* 45 * Counters that signal send-path congestion or loss, described 46 */ 47inline string mib_tcp_desc[string name] = 48 name == "tcps_sndrexmitpack" ? "data packet retransmitted" : 49 name == "tcps_sndrexmitbad" ? "unnecessary retransmission" : 50 name == "tcps_rexmttimeo" ? "retransmit timeout" : 51 name == "tcps_timeoutdrop" ? 52 "connection dropped by retransmit timeout" : 53 name; 54 55$PROBE /* probe ID $ID */ 56{${TRACE:+ 57 printf("<$ID>");} 58 this->mib_desc = mib_tcp_desc[probename]; 59} 60EOF 61ACTIONS=$( cat <&9 ) 62ID=$(( $ID + 1 )) 63 64############################################################ EVENT DETAILS 65 66if [ ! "$CUSTOM_DETAILS" ]; then 67exec 9<<EOF 68 /* 69 * Print counter increment details 70 */ 71 printf("%s (+%d)", this->mib_desc, (int)arg0); 72EOF 73EVENT_DETAILS=$( cat <&9 ) 74fi 75 76################################################################################ 77# END 78################################################################################ 79