[Pkg-voip-commits] [dahdi-tools] 50/285: dahdi_test: Enforce range from 0.0% - 100.0% for accuracy.

tzafrir at debian.org tzafrir at debian.org
Thu Jul 7 19:18:28 UTC 2016


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch master
in repository dahdi-tools.

commit 78584da122f21761398147bf946c9ede29af342a
Author: Shaun Ruffell <sruffell at digium.com>
Date:   Thu Sep 29 17:00:59 2011 +0000

    dahdi_test: Enforce range from 0.0% - 100.0% for accuracy.
    
    Also makes sure that the percentage output from the verbose and
    non-verbose modes of timer_test are the same and print a cumulative
    accuracy which smooths out the jitter for each pass.
    
    If the time it takes to read in 1 second worth of data is longer than 1
    second  accuracy will be 0%.
    
    (closes issue #18573)
    Reported by: smurfix
    
    Signed-off-by: Shaun Ruffell <sruffell at digium.com>
    
    git-svn-id: http://svn.astersk.org/svn/dahdi/tools/trunk@10216 17933a7a-c749-41c5-a318-cba88f637d49
---
 dahdi_test.c | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/dahdi_test.c b/dahdi_test.c
index ed71443..d07a1f6 100644
--- a/dahdi_test.c
+++ b/dahdi_test.c
@@ -40,17 +40,32 @@
 
 #define SIZE 8000
 
+static int verbose;
 static int pass = 0;
 static float best = 0.0;
 static float worst = 100.0;
 static double total = 0.0;
-static double delay_total = 0.0;
+static double total_time = 0.0;
+static double total_count = 0.0;
+
+static inline float _fmin(float a, float b)
+{
+	return (a < b) ? a : b;
+}
+
+static double calculate_accuracy(double count, double ms)
+{
+	return ((count - _fmin(count, fabs(count - ms))) / count) * 100.0;
+}
 
 void hup_handler(int sig)
 {
+	double accuracy = calculate_accuracy(total_count, total_time);
 	printf("\n--- Results after %d passes ---\n", pass);
-	printf("Best: %.3f -- Worst: %.3f -- Average: %f, Difference: %f\n", 
-			best, worst, pass ? total/pass : 100.00, pass ? delay_total/pass : 100);
+	printf("Best: %.3f%% -- Worst: %.3f%% -- Average: %f%%\n",
+			best, worst, pass ? total/pass : 100.00);
+	printf("Cummulative Accuracy (not per pass): %0.3f\n",
+	       pass ? accuracy : 0.0);
 	exit(0);
 }
 
@@ -79,9 +94,7 @@ int main(int argc, char *argv[])
 	int count = 0;
 	int seconds = 0;
 	int curarg = 1;
-	int verbose = 0;
 	char buf[8192];
-	float score;
 	float ms;
 	struct timeval start, now;
 	fd = open("/dev/dahdi/pseudo", O_RDWR);
@@ -140,23 +153,23 @@ int main(int argc, char *argv[])
 		ms += (now.tv_sec - start.tv_sec) * 8000;
 		ms += (now.tv_usec - start.tv_usec) / 125.0;
 		if (count >= SIZE) {
-			double percent = 100.0 * (count - ms) / count;
+			const double percent = calculate_accuracy(count, ms);
 			if (verbose) {
 				printf("\n%d samples in %0.3f system clock sample intervals (%.3f%%)", 
-						count, ms, 100 - percent);
+						count, ms, percent);
 			} else if (pass > 0 && (pass % 8) == 0) {
 				printf("\n");
 			}
-			score = 100.0 - fabs(percent);
-			if (score > best)
-				best = score;
-			if (score < worst)
-				worst = score;
+			if (percent > best)
+				best = percent;
+			if (percent < worst)
+				worst = percent;
 			if (!verbose)
-				printf("%.3f%% ", score);
-			total += score;
-			delay_total += 100 - percent;
+				printf("%.3f%% ", percent);
+			total += percent;
 			fflush(stdout);
+			total_count += count;
+			total_time += ms;
 			count = 0;
 			pass++;
 		}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/dahdi-tools.git



More information about the Pkg-voip-commits mailing list