diff options
author | Garrett Wollman <wollman@FreeBSD.org> | 1997-07-18 17:52:05 +0000 |
---|---|---|
committer | Garrett Wollman <wollman@FreeBSD.org> | 1997-07-18 17:52:05 +0000 |
commit | 3109a910023110cdcd687c195f0c76220df21a47 (patch) | |
tree | 77d9e71a907fdad644b93493f1f8378f570c61cd /sbin/ping/ping.c | |
parent | f71a4cccdcd20fa55ace4ecd23d5f40a8d1689a9 (diff) | |
download | src-3109a910023110cdcd687c195f0c76220df21a47.tar.gz src-3109a910023110cdcd687c195f0c76220df21a47.zip |
Calculate and print out the standard deviation of the round trip times.
This isn't necessarily the best statistic, but it is by far the easiest to
calculate. Update the man page to be more explicit about precisely which
statistics are printed out. Revert some of jmg's bogus man page changes from
rev 1.11.
Notes
Notes:
svn path=/head/; revision=27508
Diffstat (limited to 'sbin/ping/ping.c')
-rw-r--r-- | sbin/ping/ping.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 5479d64d51c3..b83cdbb9cc4e 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -45,7 +45,7 @@ static const char copyright[] = static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; */ static const char rcsid[] = - "$Id: ping.c,v 1.23 1997/07/09 20:33:58 julian Exp $"; + "$Id: ping.c,v 1.24 1997/07/13 06:16:44 sef Exp $"; #endif /* not lint */ /* @@ -71,6 +71,7 @@ static const char rcsid[] = #include <ctype.h> #include <err.h> #include <errno.h> +#include <math.h> #include <netdb.h> #include <signal.h> #include <stdio.h> @@ -155,6 +156,7 @@ int timing; /* flag to do timing */ double tmin = 999999999.0; /* minimum round trip time */ double tmax = 0.0; /* maximum round trip time */ double tsum = 0.0; /* sum of all times, for doing average */ +double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ int reset_kerninfo; sig_atomic_t siginfo_p; @@ -649,6 +651,7 @@ pr_pack(buf, cc, from) triptime = ((double)tv.tv_sec) * 1000.0 + ((double)tv.tv_usec) / 1000.0; tsum += triptime; + tsumsq += triptime * triptime; if (triptime < tmin) tmin = triptime; if (triptime > tmax) @@ -922,9 +925,14 @@ finish(int sig) (int) (((ntransmitted - nreceived) * 100) / ntransmitted)); (void)putchar('\n'); - if (nreceived && timing) - (void)printf("round-trip min/avg/max = %.3f/%.3f/%.3f ms\n", - tmin, tsum / (nreceived + nrepeats), tmax); + if (nreceived && timing) { + double n = nreceived + nrepeats; + double avg = tsum / n; + double vari = tsumsq / n - avg * avg; + printf("round-trip min/avg/max/stddev = " + "%.3f/%.3f/%.3f/%.3f ms\n", + tmin, avg, tmax, sqrt(vari)); + } if (reset_kerninfo && tcgetattr(STDOUT_FILENO, &ts) != -1) { ts.c_lflag &= ~NOKERNINFO; tcsetattr(STDOUT_FILENO, TCSANOW, &ts); |