205 struct timeval start,
end;
206 unsigned int test_rate = 50;
211 e->
usage =
"Usage: timing test <rate>\n"
212 " Test a timer with a specified rate, 50/sec by default.\n"
219 if (
a->argc != 2 &&
a->argc != 3) {
225 if (sscanf(
a->argv[2],
"%30u", &rate) == 1) {
228 ast_cli(
a->fd,
"Invalid rate '%s', using default of %u\n",
a->argv[2], test_rate);
232 ast_cli(
a->fd,
"Attempting to test a timer with %u ticks per second.\n", test_rate);
235 ast_cli(
a->fd,
"Failed to open timing fd\n");
247 struct pollfd pfd = {
249 .events = POLLIN | POLLPRI,
257 ast_cli(
a->fd,
"Timer failed to acknowledge.\n");
262 ast_cli(
a->fd,
"poll() timed out! This is bad.\n");
263 }
else if (
errno != EAGAIN &&
errno != EINTR) {
264 ast_cli(
a->fd,
"poll() returned error: %s\n", strerror(
errno));
271 ast_cli(
a->fd,
"It has been %" PRIi64
" milliseconds, and we got %d timer ticks\n",
Prototypes for public functions only of internal interest,.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_calloc(num, len)
A wrapper for calloc()
static struct ast_timer * timer
Standard Command Line Interface.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
void ast_cli(int fd, const char *fmt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
struct ast_heap * ast_heap_destroy(struct ast_heap *h)
Destroy a max heap.
#define ast_heap_create(init_height, cmp_fn, index_offset)
Create a max heap.
#define ast_heap_unlock(h)
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
#define ast_heap_rdlock(h)
#define ast_heap_push(h, elm)
Push an element on to a heap.
#define ast_heap_wrlock(h)
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
Asterisk locking-related definitions:
Asterisk module definitions.
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
#define ast_poll(a, b, c)
descriptor for a cli entry.
struct timing_holder * holder
int(* timer_set_rate)(void *data, unsigned int rate)
enum ast_timer_event(* timer_get_event)(void *data)
int(* timer_disable_continuous)(void *data)
int(* timer_enable_continuous)(void *data)
void *(* timer_open)(void)
void(* timer_close)(void *data)
int(* timer_fd)(void *data)
int(* timer_ack)(void *data, unsigned int quantity)
unsigned int(* timer_get_max_rate)(void *data)
struct ast_timing_interface * iface
Time-related functions and macros.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
static void timing_shutdown(void)
int ast_timing_init(void)
unsigned int ast_timer_get_max_rate(const struct ast_timer *handle)
Get maximum rate supported for a timer.
void ast_timer_close(struct ast_timer *handle)
Close an opened timing handle.
int ast_timer_ack(const struct ast_timer *handle, unsigned int quantity)
Acknowledge a timer event.
static struct ast_heap * timing_interfaces
int ast_timer_set_rate(const struct ast_timer *handle, unsigned int rate)
Set the timing tick rate.
int ast_unregister_timing_interface(void *handle)
Unregister a previously registered timing interface.
enum ast_timer_event ast_timer_get_event(const struct ast_timer *handle)
Retrieve timing event.
int ast_timer_enable_continuous(const struct ast_timer *handle)
Enable continuous mode.
const char * ast_timer_get_name(const struct ast_timer *handle)
Get name of timer in use.
static char * timing_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_timer_disable_continuous(const struct ast_timer *handle)
Disable continuous mode.
struct ast_timer * ast_timer_open(void)
Open a timer.
static struct ast_cli_entry cli_timing[]
int ast_timer_fd(const struct ast_timer *handle)
Get a poll()-able file descriptor for a timer.
void * _ast_register_timing_interface(struct ast_timing_interface *funcs, struct ast_module *mod)
static int timing_holder_cmp(void *_h1, void *_h2)
Timing source management.