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.
This commit is contained in:
Garrett Wollman 1997-07-18 17:52:05 +00:00
parent f71a4cccdc
commit 3109a91002
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27508
3 changed files with 33 additions and 19 deletions

View File

@ -5,5 +5,6 @@ MAN8= ping.8
BINOWN= root BINOWN= root
BINMODE=4555 BINMODE=4555
COPTS+= -Wall -Wmissing-prototypes COPTS+= -Wall -Wmissing-prototypes
LDADD= -lm
.include <bsd.prog.mk> .include <bsd.prog.mk>

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 .\" @(#)ping.8 8.2 (Berkeley) 12/11/93
.\" $Id: ping.8,v 1.10 1997/03/02 20:01:07 imp Exp $ .\" $Id: ping.8,v 1.11 1997/03/02 23:38:05 jmg Exp $
.\" .\"
.Dd March 1, 1997 .Dd March 1, 1997
.Dt PING 8 .Dt PING 8
@ -214,12 +214,14 @@ Then, hosts and gateways further and further away should be
Round-trip times and packet loss statistics are computed. Round-trip times and packet loss statistics are computed.
If duplicate packets are received, they are not included in the packet If duplicate packets are received, they are not included in the packet
loss calculation, although the round trip time of these packets is used loss calculation, although the round trip time of these packets is used
in calculating the minimum/average/maximum round-trip time numbers. in calculating the round-trip time statistics.
When the specified number of packets have been sent When the specified number of packets have been sent
.Pq and received .Pq and received
or if the program is terminated with a or if the program is terminated with a
.Dv SIGINT , .Dv SIGINT ,
a brief summary is displayed. a brief summary is displayed, showing the number of packets sent and
received, and the minimum, maximum, mean, and standard deviation of
the round-trip times.
.Pp .Pp
This program is intended for use in network testing, measurement and This program is intended for use in network testing, measurement and
management. management.
@ -267,25 +269,21 @@ to the same request.
Damaged packets are obviously serious cause for alarm and often Damaged packets are obviously serious cause for alarm and often
indicate broken hardware somewhere in the indicate broken hardware somewhere in the
.Nm ping .Nm ping
.No packet Ap s path packet's path (in the network or in the hosts).
.Pq in the network or in the hosts .
.Sh TRYING DIFFERENT DATA PATTERNS .Sh TRYING DIFFERENT DATA PATTERNS
The The
.Po (inter)network
inter
.Pc Ns network
layer should never treat packets differently depending on the data layer should never treat packets differently depending on the data
contained in the data portion. contained in the data portion.
Unfortunately, data-dependent problems have been known to sneak into Unfortunately, data-dependent problems have been known to sneak into
networks and remain undetected for long periods of time. networks and remain undetected for long periods of time.
In many cases the particular pattern that will have problems is something In many cases the particular pattern that will have problems is something
.No that doesn Ap t have sufficient that does not have sufficient
.Dq transitions , .Dq transitions ,
such as all ones or all zeros, or a pattern right at the edge, such as such as all ones or all zeros, or a pattern right at the edge, such as
almost all zeros. almost all zeros.
.No It isn Ap t It is not
necessarily enough to specify a data pattern of all zeros necessarily enough to specify a data pattern of all zeros (for example)
.Pq for example
on the command line because the pattern that is of interest is on the command line because the pattern that is of interest is
at the data link level, and the relationship between what you type and at the data link level, and the relationship between what you type and
what the controllers transmit can be complicated. what the controllers transmit can be complicated.
@ -293,7 +291,7 @@ what the controllers transmit can be complicated.
This means that if you have a data-dependent problem you will probably This means that if you have a data-dependent problem you will probably
have to do a lot of testing to find it. have to do a lot of testing to find it.
If you are lucky, you may manage to find a file that either If you are lucky, you may manage to find a file that either
.No can Ap t cannot
be sent across your network or that takes much longer to transfer than be sent across your network or that takes much longer to transfer than
other similar length files. other similar length files.
You can then examine this file for repeated patterns that you can test You can then examine this file for repeated patterns that you can test
@ -318,7 +316,12 @@ specification states that the
field for field for
.Tn TCP .Tn TCP
packets should be set to 60, but many systems use smaller values packets should be set to 60, but many systems use smaller values
.Pq Bx 4.3 \ uses 30, Bx 4.2 \ used 15 . .Po
.Bx 4.3
uses 30,
.Bx 4.2
used 15
.Pc .
.Pp .Pp
The maximum possible value of this field is 255, and most Unix systems set The maximum possible value of this field is 255, and most Unix systems set
the the
@ -348,7 +351,9 @@ In this case the
value in the received packet will be 255 minus the value in the received packet will be 255 minus the
number of routers in the round-trip path. number of routers in the round-trip path.
.It .It
Set it to 255; this is what current Berkeley Unix systems do. Set it to 255; this is what current
.Tn BSD
systems do.
In this case the In this case the
.Tn TTL .Tn TTL
value in the received packet will be 255 minus the value in the received packet will be 255 minus the

View File

@ -45,7 +45,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
*/ */
static const char rcsid[] = 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 */ #endif /* not lint */
/* /*
@ -71,6 +71,7 @@ static const char rcsid[] =
#include <ctype.h> #include <ctype.h>
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <math.h>
#include <netdb.h> #include <netdb.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
@ -155,6 +156,7 @@ int timing; /* flag to do timing */
double tmin = 999999999.0; /* minimum round trip time */ double tmin = 999999999.0; /* minimum round trip time */
double tmax = 0.0; /* maximum round trip time */ double tmax = 0.0; /* maximum round trip time */
double tsum = 0.0; /* sum of all times, for doing average */ 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; int reset_kerninfo;
sig_atomic_t siginfo_p; sig_atomic_t siginfo_p;
@ -649,6 +651,7 @@ pr_pack(buf, cc, from)
triptime = ((double)tv.tv_sec) * 1000.0 + triptime = ((double)tv.tv_sec) * 1000.0 +
((double)tv.tv_usec) / 1000.0; ((double)tv.tv_usec) / 1000.0;
tsum += triptime; tsum += triptime;
tsumsq += triptime * triptime;
if (triptime < tmin) if (triptime < tmin)
tmin = triptime; tmin = triptime;
if (triptime > tmax) if (triptime > tmax)
@ -922,9 +925,14 @@ finish(int sig)
(int) (((ntransmitted - nreceived) * 100) / (int) (((ntransmitted - nreceived) * 100) /
ntransmitted)); ntransmitted));
(void)putchar('\n'); (void)putchar('\n');
if (nreceived && timing) if (nreceived && timing) {
(void)printf("round-trip min/avg/max = %.3f/%.3f/%.3f ms\n", double n = nreceived + nrepeats;
tmin, tsum / (nreceived + nrepeats), tmax); 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) { if (reset_kerninfo && tcgetattr(STDOUT_FILENO, &ts) != -1) {
ts.c_lflag &= ~NOKERNINFO; ts.c_lflag &= ~NOKERNINFO;
tcsetattr(STDOUT_FILENO, TCSANOW, &ts); tcsetattr(STDOUT_FILENO, TCSANOW, &ts);