Skip to content

Commit ce0dbba

Browse files
author
Richard Aas
committed
add tmr_status()
1 parent 097b9eb commit ce0dbba

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

include/re_tmr.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void tmr_poll(struct list *tmrl);
2525
uint64_t tmr_jiffies(void);
2626
uint64_t tmr_next_timeout(struct list *tmrl);
2727
void tmr_debug(void);
28+
int tmr_status(struct re_printf *pf, void *unused);
2829

2930
void tmr_init(struct tmr *tmr);
3031
void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg);

src/tmr/tmr.c

+22-10
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,43 @@ uint64_t tmr_next_timeout(struct list *tmrl)
172172
}
173173

174174

175-
/**
176-
* Print timer debug info to stderr
177-
*/
178-
void tmr_debug(void)
175+
int tmr_status(struct re_printf *pf, void *unused)
179176
{
180177
struct list *tmrl = tmrl_get();
181178
struct le *le;
182179
uint32_t n;
180+
int err;
181+
182+
(void)unused;
183183

184184
n = list_count(tmrl);
185185
if (!n)
186-
return;
186+
return 0;
187187

188-
(void)re_fprintf(stderr, "Timers (%u):\n", n);
188+
err = re_hprintf(pf, "Timers (%u):\n", n);
189189

190190
for (le = tmrl->head; le; le = le->next) {
191191
const struct tmr *tmr = le->data;
192192

193-
(void)re_fprintf(stderr, " %p: th=%p expire=%llums\n",
194-
tmr, tmr->th,
195-
(unsigned long long)tmr_get_expire(tmr));
193+
err |= re_hprintf(pf, " %p: th=%p expire=%llums\n",
194+
tmr, tmr->th,
195+
(unsigned long long)tmr_get_expire(tmr));
196196
}
197197

198198
if (n > 100)
199-
(void)re_fprintf(stderr, " (Dumped Timers: %u)\n", n);
199+
err |= re_hprintf(pf, " (Dumped Timers: %u)\n", n);
200+
201+
return err;
202+
}
203+
204+
205+
/**
206+
* Print timer debug info to stderr
207+
*/
208+
void tmr_debug(void)
209+
{
210+
if (!list_isempty(tmrl_get()))
211+
(void)re_fprintf(stderr, "%H", tmr_status, NULL);
200212
}
201213

202214

0 commit comments

Comments
 (0)