36 #include "asterisk/_private.h"
210 unsigned int res = 0;
226 struct timeval start, end;
227 unsigned int test_rate = 50;
232 e->
usage =
"Usage: timing test <rate>\n"
233 " Test a timer with a specified rate, 50/sec by default.\n"
246 if (sscanf(a->
argv[2],
"%30u", &rate) == 1) {
249 ast_cli(a->
fd,
"Invalid rate '%s', using default of %u\n", a->
argv[2], test_rate);
253 ast_cli(a->
fd,
"Attempting to test a timer with %u ticks per second.\n", test_rate);
256 ast_cli(a->
fd,
"Failed to open timing fd\n");
268 struct pollfd pfd = {
270 .events = POLLIN | POLLPRI,
278 ast_cli(a->
fd,
"Timer failed to acknowledge.\n");
283 ast_cli(a->
fd,
"poll() timed out! This is bad.\n");
284 }
else if (
errno != EAGAIN &&
errno != EINTR) {
292 ast_cli(a->
fd,
"It has been %" PRIi64
" milliseconds, and we got %d timer ticks\n",
307 timing_interfaces = NULL;
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk locking-related definitions:
unsigned int ast_timer_get_max_rate(const struct ast_timer *handle)
Get maximum rate supported for a timer.
Asterisk main include file. File version handling, generic pbx functions.
void ast_module_unref(struct ast_module *)
static void timing_shutdown(void)
struct ast_timing_interface * iface
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
static int timing_holder_cmp(void *_h1, void *_h2)
Time-related functions and macros.
int ast_unregister_timing_interface(void *handle)
Unregister a previously registered timing interface.
#define ast_heap_unlock(h)
descriptor for a cli entry.
int ast_heap_push(struct ast_heap *h, void *elm)
Push an element on to a heap.
int(* timer_enable_continuous)(int handle)
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
struct ast_timer * ast_timer_open(void)
Open a timer.
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
enum ast_timer_event(* timer_get_event)(int handle)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
static char * timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
void(* timer_close)(int handle)
void ast_cli(int fd, const char *fmt,...)
int(* timer_disable_continuous)(int handle)
int(* timer_set_rate)(int handle, unsigned int rate)
int ast_timer_disable_continuous(const struct ast_timer *handle)
Disable continuous mode.
#define ast_poll(a, b, c)
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
struct timing_holder * holder
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
void * _ast_register_timing_interface(struct ast_timing_interface *funcs, struct ast_module *mod)
int(* timer_ack)(int handle, unsigned int quantity)
#define ast_heap_rdlock(h)
unsigned int(* timer_get_max_rate)(int handle)
static struct ast_heap * timing_interfaces
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
int ast_timer_enable_continuous(const struct ast_timer *handle)
Enable continuous mode.
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
Standard Command Line Interface.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
struct ast_heap * ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset)
Create a max heap.
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
static struct ast_cli_entry cli_timing[]
int ast_timing_init(void)
enum ast_timer_event ast_timer_get_event(const struct ast_timer *handle)
Retrieve timing event.
const char * ast_timer_get_name(const struct ast_timer *handle)
Get name of timer in use.
static struct ast_timer * timer
Asterisk module definitions.
Timing source management.
#define ast_heap_wrlock(h)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
struct ast_module * ast_module_ref(struct ast_module *)