From ce0dbba58e7c81bc850be1d41c07943000241afb Mon Sep 17 00:00:00 2001 From: Richard Aas Date: Wed, 30 May 2012 09:48:43 +0000 Subject: [PATCH] add tmr_status() --- include/re_tmr.h | 1 + src/tmr/tmr.c | 52 +++++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/include/re_tmr.h b/include/re_tmr.h index bfcb591..b399fb1 100644 --- a/include/re_tmr.h +++ b/include/re_tmr.h @@ -25,6 +25,7 @@ void tmr_poll(struct list *tmrl); uint64_t tmr_jiffies(void); uint64_t tmr_next_timeout(struct list *tmrl); void tmr_debug(void); +int tmr_status(struct re_printf *pf, void *unused); void tmr_init(struct tmr *tmr); void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg); diff --git a/src/tmr/tmr.c b/src/tmr/tmr.c index 3611001..035ceec 100644 --- a/src/tmr/tmr.c +++ b/src/tmr/tmr.c @@ -172,31 +172,43 @@ uint64_t tmr_next_timeout(struct list *tmrl) } +int tmr_status(struct re_printf *pf, void *unused) +{ + struct list *tmrl = tmrl_get(); + struct le *le; + uint32_t n; + int err; + + (void)unused; + + n = list_count(tmrl); + if (!n) + return 0; + + err = re_hprintf(pf, "Timers (%u):\n", n); + + for (le = tmrl->head; le; le = le->next) { + const struct tmr *tmr = le->data; + + err |= re_hprintf(pf, " %p: th=%p expire=%llums\n", + tmr, tmr->th, + (unsigned long long)tmr_get_expire(tmr)); + } + + if (n > 100) + err |= re_hprintf(pf, " (Dumped Timers: %u)\n", n); + + return err; +} + + /** * Print timer debug info to stderr */ void tmr_debug(void) { - struct list *tmrl = tmrl_get(); - struct le *le; - uint32_t n; - - n = list_count(tmrl); - if (!n) - return; - - (void)re_fprintf(stderr, "Timers (%u):\n", n); - - for (le = tmrl->head; le; le = le->next) { - const struct tmr *tmr = le->data; - - (void)re_fprintf(stderr, " %p: th=%p expire=%llums\n", - tmr, tmr->th, - (unsigned long long)tmr_get_expire(tmr)); - } - - if (n > 100) - (void)re_fprintf(stderr, " (Dumped Timers: %u)\n", n); + if (!list_isempty(tmrl_get())) + (void)re_fprintf(stderr, "%H", tmr_status, NULL); }