mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
Add a "timing test" CLI command. It opens a timer and configures it for
50 ticks per second, and then counts to see how many ticks it actually gets in a second. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@122926 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -37,6 +37,7 @@ void ast_autoservice_init(void); /*!< Provided by autoservice.c */
|
|||||||
int ast_http_init(void); /*!< Provided by http.c */
|
int ast_http_init(void); /*!< Provided by http.c */
|
||||||
int ast_http_reload(void); /*!< Provided by http.c */
|
int ast_http_reload(void); /*!< Provided by http.c */
|
||||||
int ast_tps_init(void); /*!< Provided by taskprocessor.c */
|
int ast_tps_init(void); /*!< Provided by taskprocessor.c */
|
||||||
|
int ast_timing_init(void); /*!< Provided by timing.c */
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Reload asterisk modules.
|
* \brief Reload asterisk modules.
|
||||||
|
@@ -3306,6 +3306,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
ast_autoservice_init();
|
ast_autoservice_init();
|
||||||
|
|
||||||
|
if (ast_timing_init()) {
|
||||||
|
printf("%s", term_quit());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (load_modules(1)) { /* Load modules, pre-load only */
|
if (load_modules(1)) { /* Load modules, pre-load only */
|
||||||
printf("%s", term_quit());
|
printf("%s", term_quit());
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@@ -27,8 +27,13 @@
|
|||||||
|
|
||||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||||
|
|
||||||
|
#include "asterisk/_private.h"
|
||||||
|
|
||||||
#include "asterisk/timing.h"
|
#include "asterisk/timing.h"
|
||||||
#include "asterisk/lock.h"
|
#include "asterisk/lock.h"
|
||||||
|
#include "asterisk/cli.h"
|
||||||
|
#include "asterisk/utils.h"
|
||||||
|
#include "asterisk/time.h"
|
||||||
|
|
||||||
AST_RWLOCK_DEFINE_STATIC(lock);
|
AST_RWLOCK_DEFINE_STATIC(lock);
|
||||||
|
|
||||||
@@ -192,3 +197,64 @@ enum ast_timing_event ast_timer_get_event(int handle)
|
|||||||
|
|
||||||
return result;
|
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 ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user