Subject: bin/6197: add stddev to ping output
To: None <gnats-bugs@gnats.netbsd.org>
From: Daniel Hagerty <hag@ai.mit.edu>
List: netbsd-bugs
Date: 09/24/1998 16:07:17
>Number: 6197
>Category: bin
>Synopsis: add stddev to ping output
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Thu Sep 24 13:50:01 1998
>Last-Modified:
>Originator: Daniel Hagerty
>Organization:
MIT
>Release: NetBSD 1.3.2
>Environment:
System: NetBSD repo-man.ai.mit.edu 1.3.2 NetBSD 1.3.2 (REPO_MAN) #45: Fri Jun 12 15:09:02 EDT 1998 hag@repo-man.ai.mit.edu:/fs/repo/hag/work/hacking/os/netbsd/src-stable/sys/arch/i386/compile/REPO_MAN i386
>Description:
Patch to add standard deviation (easily derived from the
information already kept about the dataset) to ping's final output.
Idea from freebsd current ping.
Sample output:
----EXTERNAL-RTR-IHTFP-FDDI.MIT.EDU PING Statistics----
13 packets transmitted, 13 packets received, 0% packet loss
round-trip min/avg/max/stddev = 5.798/21.916/102.123/33.278 ms
>How-To-Repeat:
>Fix:
diff -uw ping.c.orig ping.c
--- ping.c.orig Tue May 5 04:40:35 1998
+++ ping.c Thu Sep 24 15:53:52 1998
@@ -78,6 +78,7 @@
#include <limits.h>
#include <string.h>
#include <err.h>
+#include <math.h>
#ifdef sgi
#include <bstring.h>
#include <getopt.h>
@@ -177,6 +178,7 @@
double tmin = 999999999;
double tmax = 0;
double tsum = 0; /* sum of all times */
+double tsumsq = 0;
double maxwait = 0;
#ifdef SIGINFO
@@ -833,6 +835,7 @@
(void) memcpy(&tv, icp->icmp_data, sizeof(tv));
triptime = diffsec(&last_rx, &tv);
tsum += triptime;
+ tsumsq += triptime * triptime;
if (triptime < tmin)
tmin = triptime;
if (triptime > tmax)
@@ -1089,10 +1092,14 @@
}
(void)printf("\n");
if (nreceived && (pingflags & F_TIMING)) {
- (void)printf("round-trip min/avg/max = %.3f/%.3f/%.3f ms\n",
- tmin*1000.0,
- (tsum/(nreceived+nrepeats))*1000.0,
- tmax*1000.0);
+ double n = nreceived + nrepeats;
+ double avg = (tsum / n);
+ double variance = (tsumsq / (n - (avg * avg)));
+
+ 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);
if (pingflags & F_FLOOD) {
double r = diffsec(&last_rx, &first_rx);
double t = diffsec(&last_tx, &first_tx);
diff -uw Makefile.orig Makefile.c
--- Makefile.orig Tue May 5 02:41:13 1998
+++ Makefile Thu Sep 24 15:27:06 1998
@@ -5,5 +5,6 @@
MAN= ping.8
BINOWN= root
BINMODE=4555
+LDADD+= -lm
.include <bsd.prog.mk>
>Audit-Trail:
>Unformatted: