The following reply was made to PR bin/151937; it has been noted by GNATS.

From: Mikolaj Golub <[email protected]>
To: Mykola Zubach <[email protected]>, [email protected]
Cc: Robert Watson <[email protected]>, [email protected]
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);
 
 --=-=-=--
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to