From owner-freebsd-net@FreeBSD.ORG Sun Jul 1 16:20:17 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 30A31106566B; Sun, 1 Jul 2012 16:20:17 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx1.freebsd.org (Postfix) with ESMTP id 455768FC17; Sun, 1 Jul 2012 16:20:16 +0000 (UTC) Received: by mail-lb0-f182.google.com with SMTP id n10so8199953lbo.13 for ; Sun, 01 Jul 2012 09:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:sender:date:message-id:user-agent:mime-version :content-type; bh=dRA7KhUI9rbZL6OFuVcAZOyJddTcNs8PdG1MA/pkUG8=; b=gUcOaiNhewUQI8htPPBQKjyTZnl05K96ls77/bcmWVc1uAiXIOb4b1836IONSXg2SI sfjGroml1tSIKz7WDuO7YKF+jxlmPKOPQf/RRfAt+wwabv4X4Qrbgwh/1R7B+wY1hEJx DLAqzQgLHJckPeJfQHIR2fZqttSgtW21B3fV5JLHhJJz7cp7IHFyC/ob62LzwBtc5z/7 QwjiVi9pPgmvUjCb6RFvMmoHZ7zwWzTdBJ+Jy0auc6741TDkY7GQkLIt5a5dqXZ3TkTL fCAUcNQYg4deyYQIshHQawCLj0ECWr8hs4hsnuaD1MUhg19Qh23tapd76LKy+zc3cQr5 a7Lw== Received: by 10.152.103.11 with SMTP id fs11mr4651786lab.23.1341159615908; Sun, 01 Jul 2012 09:20:15 -0700 (PDT) Received: from localhost ([95.69.173.122]) by mx.google.com with ESMTPS id hi14sm18201102lab.4.2012.07.01.09.20.13 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 01 Jul 2012 09:20:14 -0700 (PDT) From: Mikolaj Golub To: Mykola Zubach , freebsd-net@FreeBSD.org Sender: Mikolaj Golub Date: Sun, 01 Jul 2012 19:20:11 +0300 Message-ID: <861ukvpi6c.fsf@kopusha.home.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jul 2012 16:20:17 -0000 --=-=-= 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); --=-=-=--