tracing: ctf: trace k_sleep()

Trace sleep events in CTF:

[19:00:00.181375400] (+0.000044700) k_sleep_enter: ...
..
[19:00:00.290203800] (+0.000031500) k_sleep_exit: ...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2025-07-05 08:28:20 -04:00 committed by Benjamin Cabé
parent 7312715975
commit a096b34835
3 changed files with 33 additions and 2 deletions

View File

@ -77,6 +77,21 @@ void sys_trace_k_thread_priority_set(struct k_thread *thread)
thread->base.prio, name);
}
void sys_trace_k_thread_sleep_enter(k_timeout_t timeout)
{
ctf_top_thread_sleep_enter(
k_ticks_to_us_floor32((uint32_t)timeout.ticks)
);
}
void sys_trace_k_thread_sleep_exit(k_timeout_t timeout, int ret)
{
ctf_top_thread_sleep_exit(
k_ticks_to_us_floor32((uint32_t)timeout.ticks),
(uint32_t)ret
);
}
void sys_trace_k_thread_create(struct k_thread *thread, size_t stack_size, int prio)
{
ctf_bounded_string_t name = { "unknown" };

View File

@ -186,6 +186,8 @@ typedef enum {
CTF_EVENT_GPIO_GET_PENDING_INT_EXIT = 0x7C,
CTF_EVENT_GPIO_FIRE_CALLBACKS_ENTER = 0x7D,
CTF_EVENT_GPIO_FIRE_CALLBACK = 0x7E,
CTF_EVENT_THREAD_SLEEP_ENTER = 0x7F,
CTF_EVENT_THREAD_SLEEP_EXIT = 0x80,
} ctf_event_t;
typedef struct {
@ -213,6 +215,16 @@ static inline void ctf_top_thread_priority_set(uint32_t thread_id, int8_t prio,
thread_id, name, prio);
}
static inline void ctf_top_thread_sleep_enter(uint32_t timeout)
{
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_THREAD_SLEEP_ENTER), timeout);
}
static inline void ctf_top_thread_sleep_exit(uint32_t timeout, int32_t ret)
{
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_THREAD_SLEEP_EXIT), timeout, ret);
}
static inline void ctf_top_thread_create(uint32_t thread_id, int8_t prio,
ctf_bounded_string_t name)
{

View File

@ -31,8 +31,12 @@ extern "C" {
#define sys_port_trace_k_thread_join_enter(thread, timeout)
#define sys_port_trace_k_thread_join_blocking(thread, timeout)
#define sys_port_trace_k_thread_join_exit(thread, timeout, ret)
#define sys_port_trace_k_thread_sleep_enter(timeout)
#define sys_port_trace_k_thread_sleep_exit(timeout, ret)
#define sys_port_trace_k_thread_sleep_enter(timeout) \
sys_trace_k_thread_sleep_enter(timeout)
#define sys_port_trace_k_thread_sleep_exit(timeout, ret) \
sys_trace_k_thread_sleep_exit(timeout, ret)
#define sys_port_trace_k_thread_msleep_enter(ms)
#define sys_port_trace_k_thread_msleep_exit(ms, ret)
#define sys_port_trace_k_thread_usleep_enter(us)