[asterisk-commits] russell: branch russell/heap r175771 - /team/russell/heap/tests/test_sched.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Feb 14 11:45:07 CST 2009


Author: russell
Date: Sat Feb 14 11:45:07 2009
New Revision: 175771

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=175771
Log:
Add the beginning of test_sched

So far, there is one test, which times how long it takes to insert a million
entries into a scheduler context using ast_sched_add().

Average running time:
  trunk:             686.7 seconds
  team/russell/heap: 2.7   seconds

Added:
    team/russell/heap/tests/test_sched.c   (with props)

Added: team/russell/heap/tests/test_sched.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/tests/test_sched.c?view=auto&rev=175771
==============================================================================
--- team/russell/heap/tests/test_sched.c (added)
+++ team/russell/heap/tests/test_sched.c Sat Feb 14 11:45:07 2009
@@ -1,0 +1,98 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2009, Digium, Inc.
+ *
+ * Russell Bryant <russell at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief ast_sched performance test module
+ *
+ * \author Russell Bryant <russell at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/cli.h"
+#include "asterisk/utils.h"
+#include "asterisk/sched.h"
+
+static int sched_cb(const void *data)
+{
+	return 0;
+}
+
+static char *handle_cli_sched_test_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct sched_context *con;
+	struct timeval start;
+	static const unsigned int one_million = 1000000;
+	unsigned int i = one_million;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "sched test add";
+		e->usage = "";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	ast_cli(a->fd, "Testing ast_sched_add() performance - timing how long it takes "
+			"to add a million entries at random time intervals from 0 to 60 seconds\n");
+
+	if (!(con = sched_context_create())) {
+		ast_cli(a->fd, "Test failed - could not create scheduler context\n");
+		return CLI_FAILURE;
+	}
+
+	start = ast_tvnow();
+
+	while (i--) {
+		int when = abs(ast_random()) % 60000;
+		if (ast_sched_add(con, when, sched_cb, NULL) == -1) {
+			ast_cli(a->fd, "Test failed - sched_add returned -1\n");
+			goto return_cleanup;
+		}
+	}
+
+	ast_cli(a->fd, "Test complete - %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
+
+return_cleanup:
+	sched_context_destroy(con);
+
+	return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_sched[] = {
+	AST_CLI_DEFINE(handle_cli_sched_test_add, "Test ast_sched_add performance"),
+};
+
+static int unload_module(void)
+{
+	ast_cli_unregister_multiple(cli_sched, ARRAY_LEN(cli_sched));
+	return 0;
+}
+
+static int load_module(void)
+{
+	ast_cli_register_multiple(cli_sched, ARRAY_LEN(cli_sched));
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_sched performance test module");

Propchange: team/russell/heap/tests/test_sched.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/russell/heap/tests/test_sched.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/russell/heap/tests/test_sched.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list