Skip to content

Commit 58536de

Browse files
committed
sys/event: add event loop debug threshold
1 parent 90d7b0b commit 58536de

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

sys/include/event.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ event_t *event_wait_timeout_ztimer(event_queue_t *queue,
405405
ztimer_clock_t *clock, uint32_t timeout);
406406
#endif
407407

408+
/**
409+
* @brief Threshold (USEC) below which event_handler are not printed,
410+
* while debugging eventloop setting a value (!0) will also remove
411+
* event_handler start message
412+
*
413+
* Use this to prevent *a lot* of output when debugging.
414+
*/
415+
#ifndef CONFIG_EVENT_LOOP_DEBUG_THRESHOLD
416+
#define CONFIG_EVENT_LOOP_DEBUG_THRESHOLD (0)
417+
#endif
418+
408419
/**
409420
* @brief Simple event loop with multiple queues
410421
*
@@ -442,17 +453,23 @@ static inline void event_loop_multi(event_queue_t *queues, size_t n_queues)
442453
ztimer_acquire(ZTIMER_USEC);
443454

444455
void _event_callback_handler(event_t *event);
445-
if (!IS_USED(MODULE_EVENT_CALLBACK) ||
446-
event->handler != _event_callback_handler) {
456+
if ((CONFIG_EVENT_LOOP_DEBUG_THRESHOLD == 0) &&
457+
(!IS_USED(MODULE_EVENT_CALLBACK) ||
458+
event->handler != _event_callback_handler)) {
447459
printf("event: executing %p->%p\n",
448460
(void *)event, (void *)(uintptr_t)event->handler);
449461
}
450462
now = ztimer_now(ZTIMER_USEC);
451-
463+
void * h = event->handler;
452464
event->handler(event);
453465

454-
printf("event: %p took %" PRIu32 " µs\n",
455-
(void *)event, ztimer_now(ZTIMER_USEC) - now);
466+
uint32_t now2 = ztimer_now(ZTIMER_USEC);
467+
uint32_t dt = now2 - now;
468+
469+
if ((CONFIG_EVENT_LOOP_DEBUG_THRESHOLD == 0) || dt > CONFIG_EVENT_LOOP_DEBUG_THRESHOLD) {
470+
printf("eventh: %p took %" PRIu32 " µs\n",
471+
(void *)h, dt);
472+
}
456473
ztimer_release(ZTIMER_USEC);
457474
}
458475
else {

0 commit comments

Comments
 (0)