[zaptel-commits] tzafrir: branch 1.4 r2995 - /branches/1.4/zttest.c

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Fri Sep 7 19:45:41 CDT 2007


Author: tzafrir
Date: Fri Sep  7 19:45:41 2007
New Revision: 2995

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2995
Log:
* Improve accuracy of zttest by using floats (#10312).
* Account only for the time of actually waiting for the clock.
* Clarify message for zttest -v .
* Don't print some digits that are not meaningful enough.

Modified:
    branches/1.4/zttest.c

Modified: branches/1.4/zttest.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/zttest.c?view=diff&rev=2995&r1=2994&r2=2995
==============================================================================
--- branches/1.4/zttest.c (original)
+++ branches/1.4/zttest.c Fri Sep  7 19:45:41 2007
@@ -13,12 +13,14 @@
 static int pass = 0;
 static float best = 0.0;
 static float worst = 100.0;
-static float total = 0.0;
+static double total = 0.0;
+static double delay_total = 0.0;
 
 void hup_handler(int sig)
 {
 	printf("\n--- Results after %d passes ---\n", pass);
-	printf("Best: %f -- Worst: %f -- Average: %f\n", best, worst, pass ? total/pass : 100.00);
+	printf("Best: %.3f -- Worst: %.3f -- Average: %f, Difference: %f\n", 
+			best, worst, pass ? total/pass : 100.00, pass ? delay_total/pass : 100);
 	exit(0);
 }
 
@@ -28,11 +30,11 @@
 	int res;
 	int count=0;
 	int seconds;
-	int ms;
 	int curarg = 1;
 	int verbose=0;
 	char buf[8192];
 	float score;
+	float ms;
 	struct timeval start, now;
 	fd = open("/dev/zap/pseudo", O_RDWR);
 	if (fd < 0) {
@@ -54,31 +56,38 @@
 	for (count = 0;count < 4; count++)
 		res = read(fd, buf, sizeof(buf));
 	count = 0;
-	gettimeofday(&start, NULL);
 	if (seconds > 0)
 		alarm(seconds + 1);
 	for(;;) {
+		if (count == 0)
+			ms = 0;
+		gettimeofday(&start, NULL);
 		res = read(fd, buf, sizeof(buf));
 		if (res < 0) {
 			fprintf(stderr, "Failed to read from pseudo interface: %s\n", strerror(errno));
 			exit(1);
 		}
 		count += res;
+		gettimeofday(&now, NULL);
+		ms += (now.tv_sec - start.tv_sec) * 8000;
+		ms += (now.tv_usec - start.tv_usec) / 125.0;
 		if (count >= SIZE) {
-			gettimeofday(&now, NULL);
-			ms = (now.tv_sec - start.tv_sec) * 8000;
-			ms += (now.tv_usec - start.tv_usec) / 125;
-			start = now;
+			double percent;
+
+			percent = 100.0 * (count - ms) / count;
 			if (verbose)
-				printf("\n%d samples in %d sample intervals ", count, ms);
+				printf("\n%d zaptel samples in %0.3f system clock sample intervals (%.3f%%)", 
+						count, ms, 100 - percent);
 			else if ((pass % 8) == 7) printf("\n");
-			score = 100.0 - 100.0 * fabs((float)count - (float)ms) / (float)count;
+			score = 100.0 - fabs(percent);
 			if (score > best)
 				best = score;
 			if (score < worst)
 				worst = score;
-			printf("%f%% ", score);
+			if (!verbose)
+				printf("%f%% ", score);
 			total += score;
+			delay_total += 100 - percent;
 			fflush(stdout);
 			count = 0;
 			pass++;




More information about the zaptel-commits mailing list