[asterisk-commits] russell: branch group/timing r122801 - in /team/group/timing: main/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jun 15 08:52:25 CDT 2008


Author: russell
Date: Sun Jun 15 08:52:24 2008
New Revision: 122801

URL: http://svn.digium.com/view/asterisk?view=rev&rev=122801
Log:
Add timing test CLI command

Modified:
    team/group/timing/main/timing.c
    team/group/timing/res/res_timing_pthread.c

Modified: team/group/timing/main/timing.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/main/timing.c?view=diff&rev=122801&r1=122800&r2=122801
==============================================================================
--- team/group/timing/main/timing.c (original)
+++ team/group/timing/main/timing.c Sun Jun 15 08:52:24 2008
@@ -27,9 +27,13 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include "asterisk/_private.h"
+
 #include "asterisk/timing.h"
 #include "asterisk/lock.h"
-#include "asterisk/_private.h"
+#include "asterisk/cli.h"
+#include "asterisk/utils.h"
+#include "asterisk/time.h"
 
 AST_RWLOCK_DEFINE_STATIC(lock);
 
@@ -194,7 +198,63 @@
 	return result;
 }
 
+static char *timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	int fd, count = 0;
+	struct timeval start, end;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "timing test";
+		e->usage = "Usage: timing test\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "Attempting to test a timer with 50 ticks per second ...\n");
+
+	if ((fd = ast_timer_open()) == -1) {
+		ast_cli(a->fd, "Failed to open timing fd\n");
+		return CLI_FAILURE;
+	}
+
+	start = ast_tvnow();
+
+	ast_timer_set_rate(fd, 50);
+
+	while (ast_tvdiff_ms((end = ast_tvnow()), start) < 1000) {
+		int res;
+		struct pollfd pfd = {
+			.fd = fd,
+			.events = POLLIN | POLLPRI,
+		};
+
+		res = poll(&pfd, 1, 100);
+
+		if (res == 1) {
+			count++;
+			ast_timer_ack(fd, 1);
+		} else if (!res) {
+			ast_cli(a->fd, "poll() timed out!  This is bad.\n");
+		} else if (errno != EAGAIN && errno != EINTR) {
+			ast_cli(a->fd, "poll() returned error: %s\n", strerror(errno));
+		}
+	}
+
+	ast_timer_close(fd);
+
+	ast_cli(a->fd, "It has been %d milliseconds, and we got %d timer ticks\n", 
+		ast_tvdiff_ms(end, start), count);
+
+	return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_timing[] = {
+	AST_CLI_DEFINE(timing_test, "Run a timing test"),
+};
+
 int ast_timing_init(void)
 {
-	return 0;
-}
+	return ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
+}

Modified: team/group/timing/res/res_timing_pthread.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/res/res_timing_pthread.c?view=diff&rev=122801&r1=122800&r2=122801
==============================================================================
--- team/group/timing/res/res_timing_pthread.c (original)
+++ team/group/timing/res/res_timing_pthread.c Sun Jun 15 08:52:24 2008
@@ -413,9 +413,9 @@
 			}
 			last_adjust = new_adjust;
 
-			base = ast_tvadd(base, ast_tv(0, ((TIMING_INTERVAL - new_adjust) + TIMING_INTERVAL) * 1000));
+			base = ast_tvadd(base, ast_tv(0, (TIMING_INTERVAL - new_adjust) * 1000));
 		} else {
-			base = ast_tvadd(base, ast_tv(0, (TIMING_INTERVAL * 2) * 1000));
+			base = ast_tvadd(base, ast_tv(0, TIMING_INTERVAL * 1000));
 		}
 
 		now = ast_tvnow();




More information about the asterisk-commits mailing list