From owner-freebsd-bugs@FreeBSD.ORG Sun Jul 1 16:30:09 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EAF5A106566C for ; Sun, 1 Jul 2012 16:30:08 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id C47D78FC08 for ; Sun, 1 Jul 2012 16:30:08 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q61GU8aZ044478 for ; Sun, 1 Jul 2012 16:30:08 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q61GU87S044475; Sun, 1 Jul 2012 16:30:08 GMT (envelope-from gnats) Date: Sun, 1 Jul 2012 16:30:08 GMT Message-Id: <201207011630.q61GU87S044475@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Mikolaj Golub Cc: Subject: Re: bin/151937: [patch] netstat(1) utility lack support of displaying rtt related counters of tcp sockets X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Mikolaj Golub List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jul 2012 16:30:09 -0000 The following reply was made to PR bin/151937; it has been noted by GNATS. From: Mikolaj Golub To: Mykola Zubach , freebsd-net@FreeBSD.org Cc: Robert Watson , bug-followup@FreeBSD.org Subject: Re: bin/151937: [patch] netstat(1) utility lack support of displaying rtt related counters of tcp sockets Date: Sun, 01 Jul 2012 19:20:11 +0300 --=-=-= Hi, Mykola, thank you for the report and the provided patch. Displaying rtt related counters per connection looks useful for me too. I am attaching the modified version of the patch to discuss (and commit if there are no objections or other suggestions). The differences from your version: 1) '-T' option is already used. Also, I don't like very much adding yet another option, so I added the statistics to '-x' option. Or it can be added to '-T' statistics. 2) As counter names I used names that are close to field names in the tcpcb structure. 3) To get hz, instead of kern.clockrate, I use kern.hz sysctl (as it simplifies the code a little) and for !live case read it from the dump. 4) The trick with printing to buf is used to pad the counters on the right, as it is with other counters. Also, it might be enough to display only srtt and rttvar statistics? -- Mikolaj Golub --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=netstat.rtt.2.patch Index: usr.bin/netstat/inet.c =================================================================== --- usr.bin/netstat/inet.c (revision 237835) +++ usr.bin/netstat/inet.c (working copy) @@ -293,6 +293,28 @@ fail: #undef KREAD } +static const char * +humanize_rtt(int val, int scale) +{ + size_t len; + static int hz; + static char buf[16]; + + if (hz == 0) { + hz = 1; + if (live) { + len = sizeof(hz); + if (sysctlbyname("kern.hz", &hz, &len, NULL, 0) == -1) + warn("sysctl: kern.hz"); + } else { + kread(hz_addr, &hz, sizeof(hz)); + } + } + snprintf(buf, sizeof(buf), "%.3f", (float)val / (scale * hz)); + + return (buf); +} + /* * Print a summary of connections related to an Internet * protocol. For TCP, also give state of connection. @@ -441,6 +463,8 @@ protopr(u_long off, const char *name, int af1, int printf(" %7.7s %7.7s %7.7s %7.7s %7.7s %7.7s", "rexmt", "persist", "keep", "2msl", "delack", "rcvtime"); + printf(" %7.7s %7.7s %7.7s %9.9s", + "srtt", "rttvar", "rttlow", "rttupdate"); } putchar('\n'); first = 0; @@ -548,6 +572,14 @@ protopr(u_long off, const char *name, int af1, int timer->tt_2msl / 1000, (timer->tt_2msl % 1000) / 10, timer->tt_delack / 1000, (timer->tt_delack % 1000) / 10, timer->t_rcvtime / 1000, (timer->t_rcvtime % 1000) / 10); + if (tp != NULL) { + printf(" %7s", humanize_rtt(tp->t_srtt, + TCP_RTT_SCALE)); + printf(" %7s", humanize_rtt(tp->t_rttvar, + TCP_RTTVAR_SCALE)); + printf(" %7s", humanize_rtt(tp->t_rttlow, 1)); + printf(" %9lu ", tp->t_rttupdated); + } } if (istcp && !Lflag && !xflag && !Tflag) { if (tp->t_state < 0 || tp->t_state >= TCP_NSTATES) Index: usr.bin/netstat/main.c =================================================================== --- usr.bin/netstat/main.c (revision 237835) +++ usr.bin/netstat/main.c (working copy) @@ -184,6 +184,8 @@ static struct nlist nl[] = { { .n_name = "_arpstat" }, #define N_UNP_SPHEAD 56 { .n_name = "unp_sphead" }, +#define N_HZ 57 + { .n_name = "_hz" }, { .n_name = NULL }, }; @@ -358,6 +360,8 @@ int unit; /* unit number for above */ int af; /* address family */ int live; /* true if we are examining a live system */ +u_long hz_addr; /* address of hz variable in kernel memory */ + int main(int argc, char *argv[]) { @@ -563,6 +567,7 @@ main(int argc, char *argv[]) */ #endif kread(0, NULL, 0); + hz_addr = nl[N_HZ].n_value; if (iflag && !sflag) { intpr(interval, nl[N_IFNET].n_value, NULL); exit(0); Index: usr.bin/netstat/netstat.h =================================================================== --- usr.bin/netstat/netstat.h (revision 237835) +++ usr.bin/netstat/netstat.h (working copy) @@ -59,6 +59,8 @@ extern int unit; /* unit number for above */ extern int af; /* address family */ extern int live; /* true if we are examining a live system */ +extern u_long hz_addr; /* address of hz variable in kernel memory */ + int kread(u_long addr, void *buf, size_t size); const char *plural(uintmax_t); const char *plurales(uintmax_t); --=-=-=--