Date: Thu, 4 Nov 2010 13:56:40 GMT From: Mykola Zubach <zuborg@FreeBSD.org> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/151937: [patch] netstat(1) utility lack support of displaying rtt related counters of tcp sockets Message-ID: <201011041356.oA4DueAH025158@www.freebsd.org> Resent-Message-ID: <201011041400.oA4E0H5l085082@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 151937 >Category: bin >Synopsis: [patch] netstat(1) utility lack support of displaying rtt related counters of tcp sockets >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Thu Nov 04 14:00:17 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Mykola Zubach >Release: FreeBSD 8.1 >Organization: AdvancedHosters.com >Environment: >Description: RTT (round-trip time) timings are useful to investigate networking issues. There are a lot of various tools to measure rtt (like ping/mtr etc), but it would be also helpful to have possibility to see current values of rtt for some tcp socket. Here is a patch for netstat(1) utility which adds four optional columns for tcp sockets: RTT - smoothed rtt value (tp->t_srtt / hz / TCP_RTT_SCALE) RTT-DEV - smoothed rtt variance (tp->t_rttvar / hz / TCP_RTTVAR_SCALE) RTT-LOW - smallest observed rtt (tp->t_rttlow / hz) RTT-CNT - number of times rtt sampled (tp->t_rttupdated) First three columns provide timings, measured in seconds, with precision 0.001 s. '-T' option is free at the moment, so I chose it for this patch since it is related to 'T'imings >How-To-Repeat: >Fix: Patch attached with submission follows: --- /usr/src/usr.bin/netstat/main.c 2010-06-14 05:09:06.000000000 +0300 +++ main.c 2010-11-03 17:55:49.000000000 +0200 @@ -338,6 +338,7 @@ static int pflag; /* show given protocol */ int rflag; /* show routing tables (or routing stats) */ int sflag; /* show protocol statistics */ +int Tflag; /* show rtt counters of tcp sockets */ int tflag; /* show i/f watchdog timers */ int Wflag; /* wide display */ int xflag; /* extra information, includes all socket buffer info */ @@ -359,7 +360,7 @@ af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:q:rSstuWw:xz")) != -1) + while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:q:rSsTtuWw:xz")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -459,6 +460,9 @@ case 'S': numeric_addr = 1; break; + case 'T': + Tflag = 1; + break; case 't': tflag = 1; break; --- /usr/src/usr.bin/netstat/netstat.h 2010-06-14 05:09:06.000000000 +0300 +++ netstat.h 2010-11-03 17:56:08.000000000 +0200 @@ -50,6 +50,7 @@ extern int numeric_port; /* show ports numerically */ extern int rflag; /* show routing tables (or routing stats) */ extern int sflag; /* show protocol statistics */ +extern int Tflag; /* show rtt counters of tcp sockets */ extern int tflag; /* show i/f watchdog timers */ extern int Wflag; /* wide display */ extern int xflag; /* extended display, includes all socket buffer info */ --- /usr/src/usr.bin/netstat/inet.c 2010-06-14 05:09:06.000000000 +0300 +++ inet.c 2010-11-04 15:31:45.000000000 +0200 @@ -47,6 +47,7 @@ #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/sysctl.h> +#include <sys/time.h> #include <net/route.h> #include <net/if_arp.h> @@ -313,6 +314,21 @@ struct inpcb *inp; struct xinpgen *xig, *oxig; struct xsocket *so; + struct clockinfo clockinfo; + int mib[2]; + size_t ci_size; + int hz = 1; + float rtt, rtt_var, rtt_low; + + ci_size = sizeof(clockinfo); + mib[0] = CTL_KERN; + mib[1] = KERN_CLOCKRATE; + if (sysctl(mib, 2, &clockinfo, &ci_size, NULL, 0) < 0) + warn("sysctl: kern.clockrate"); + else if (clockinfo.hz == 0) + warn("sysctl: kern.clockrate: hz = 0"); + else + hz = clockinfo.hz; istcp = 0; switch (proto) { @@ -414,15 +430,17 @@ "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s", "Proto", "Recv-Q", "Send-Q", "Local Address", "Foreign Address"); + if (Tflag) + printf("%-6.6s %-7.7s %-7.7s %-7.7s ", + " RTT", "RTT-VAR", + "RTT-LOW", "RTT-CNT"); if (xflag) - printf("%-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %s\n", + printf("%-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s %-6.6s ", "R-MBUF", "S-MBUF", "R-CLUS", "S-CLUS", "R-HIWA", "S-HIWA", "R-LOWA", "S-LOWA", "R-BCNT", - "S-BCNT", "R-BMAX", "S-BMAX", - "(state)"); - else - printf("(state)\n"); + "S-BCNT", "R-BMAX", "S-BMAX"); + printf("(state)\n"); } first = 0; } @@ -506,6 +524,14 @@ } /* else nothing printed now */ #endif /* INET6 */ } + if (istcp && Tflag && !Lflag) { + rtt = (float)tp->t_srtt / hz / TCP_RTT_SCALE; + rtt_var = (float)tp->t_rttvar / hz / TCP_RTTVAR_SCALE; + rtt_low = (float)tp->t_rttlow / hz; + printf("%6.3f %7.3f %7.3f %7lu ", + rtt, rtt_var, rtt_low, + tp->t_rttupdated); + } if (xflag) { if (Lflag) printf("%21s %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u %6u ", >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011041356.oA4DueAH025158>