Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/ping more precision for F_TIMING64



details:   https://anonhg.NetBSD.org/src/rev/315b181e5ed8
branches:  trunk
changeset: 785259:315b181e5ed8
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Mar 06 11:33:08 2013 +0000

description:
more precision for F_TIMING64

diffstat:

 sbin/ping/ping.c |  20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)

diffs (52 lines):

diff -r 01b0abb6a63a -r 315b181e5ed8 sbin/ping/ping.c
--- a/sbin/ping/ping.c  Wed Mar 06 11:31:34 2013 +0000
+++ b/sbin/ping/ping.c  Wed Mar 06 11:33:08 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ping.c,v 1.105 2012/12/30 03:19:24 christos Exp $      */
+/*     $NetBSD: ping.c,v 1.106 2013/03/06 11:33:08 yamt Exp $  */
 
 /*
  * Copyright (c) 1989, 1993
@@ -58,7 +58,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ping.c,v 1.105 2012/12/30 03:19:24 christos Exp $");
+__RCSID("$NetBSD: ping.c,v 1.106 2013/03/06 11:33:08 yamt Exp $");
 #endif
 
 #include <stdio.h>
@@ -953,8 +953,11 @@
        if (dupflag)
                (void)printf(" DUP!");
        (void)printf(" ttl=%d", ttl);
-       if (pingflags & (F_TIMING|F_TIMING64))
-               (void)printf(" time=%.3f ms", triptime*1000.0);
+       if (pingflags & (F_TIMING|F_TIMING64)) {
+               const unsigned int prec = (pingflags & F_TIMING64) != 0 ? 6 : 3;
+
+               (void)printf(" time=%.*f ms", prec, triptime*1000.0);
+       }
 
        /*
         * Send beep to stderr, since that's more likely than stdout
@@ -1340,13 +1343,16 @@
                double n = nreceived + nrepeats;
                double avg = (tsum / n);
                double variance = 0.0;
+               const unsigned int prec = (pingflags & F_TIMING64) != 0 ? 6 : 3;
                if (n>1)
                        variance = (tsumsq - n*avg*avg) /(n-1);
 
                printf("round-trip min/avg/max/stddev = "
-                       "%.3f/%.3f/%.3f/%.3f ms\n",
-                       tmin * 1000.0, avg * 1000.0,
-                       tmax * 1000.0, sqrt(variance) * 1000.0);
+                       "%.*f/%.*f/%.*f/%.*f ms\n",
+                       prec, tmin * 1000.0,
+                       prec, avg * 1000.0,
+                       prec, tmax * 1000.0,
+                       prec, sqrt(variance) * 1000.0);
                if (pingflags & F_FLOOD) {
                        double r = diffsec(&last_rx, &first_rx);
                        double t = diffsec(&last_tx, &first_tx);



Home | Main Index | Thread Index | Old Index