1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 22:43:50 +01:00

sys/event: add event_loop_debug pseudo-module

This commit is contained in:
Benjamin Valentin 2024-09-02 18:27:30 +02:00
parent b469a52a21
commit bc8687695c
2 changed files with 27 additions and 4 deletions

View File

@ -384,6 +384,10 @@ ifneq (,$(filter event_periodic_callback,$(USEMODULE)))
USEMODULE += event_periodic
endif
ifneq (,$(filter event_loop_debug,$(USEMODULE)))
USEMODULE += ztimer_usec
endif
ifneq (,$(filter emcute,$(USEMODULE)))
USEMODULE += core_thread_flags
USEMODULE += sock_udp

View File

@ -96,6 +96,7 @@
#ifndef EVENT_H
#define EVENT_H
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
@ -106,10 +107,7 @@
#include "thread.h"
#include "thread_flags.h"
#include "ptrtag.h"
#if IS_USED(MODULE_ZTIMER)
#include "ztimer.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -429,6 +427,9 @@ event_t *event_wait_timeout_ztimer(event_queue_t *queue,
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @note Enable the `event_loop_debug` module to print the execution times of
* the event handler functions.
*
* @param[in] queues Event queues to process
* @param[in] n_queues Number of queues passed with @p queues
*/
@ -437,7 +438,22 @@ static inline void event_loop_multi(event_queue_t *queues, size_t n_queues)
event_t *event;
while ((event = event_wait_multi(queues, n_queues))) {
event->handler(event);
if (IS_USED(MODULE_EVENT_LOOP_DEBUG)) {
uint32_t now;
ztimer_acquire(ZTIMER_USEC);
printf("event: executing %p->%p\n",
(void *)event, (void *)(uintptr_t)event->handler);
now = ztimer_now(ZTIMER_USEC);
event->handler(event);
printf("event: %p took %" PRIu32 " µs\n",
(void *)event, ztimer_now(ZTIMER_USEC) - now);
ztimer_release(ZTIMER_USEC);
}
else {
event->handler(event);
}
}
}
@ -458,6 +474,9 @@ static inline void event_loop_multi(event_queue_t *queues, size_t n_queues)
* @pre The queue must have a waiter (i.e. it should have been claimed, or
* initialized using @ref event_queue_init, @ref event_queues_init)
*
* @note Enable the `event_loop_debug` module to print the execution times of
* the event handler functions.
*
* @param[in] queue event queue to process
*/
static inline void event_loop(event_queue_t *queue)