Skip to content

Commit a096b34

Browse files
nashifkartben
authored andcommitted
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 <[email protected]>
1 parent 7312715 commit a096b34

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

subsys/tracing/ctf/ctf_top.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ void sys_trace_k_thread_priority_set(struct k_thread *thread)
7777
thread->base.prio, name);
7878
}
7979

80+
void sys_trace_k_thread_sleep_enter(k_timeout_t timeout)
81+
{
82+
ctf_top_thread_sleep_enter(
83+
k_ticks_to_us_floor32((uint32_t)timeout.ticks)
84+
);
85+
}
86+
87+
void sys_trace_k_thread_sleep_exit(k_timeout_t timeout, int ret)
88+
{
89+
ctf_top_thread_sleep_exit(
90+
k_ticks_to_us_floor32((uint32_t)timeout.ticks),
91+
(uint32_t)ret
92+
);
93+
}
94+
8095
void sys_trace_k_thread_create(struct k_thread *thread, size_t stack_size, int prio)
8196
{
8297
ctf_bounded_string_t name = { "unknown" };

subsys/tracing/ctf/ctf_top.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ typedef enum {
186186
CTF_EVENT_GPIO_GET_PENDING_INT_EXIT = 0x7C,
187187
CTF_EVENT_GPIO_FIRE_CALLBACKS_ENTER = 0x7D,
188188
CTF_EVENT_GPIO_FIRE_CALLBACK = 0x7E,
189+
CTF_EVENT_THREAD_SLEEP_ENTER = 0x7F,
190+
CTF_EVENT_THREAD_SLEEP_EXIT = 0x80,
189191
} ctf_event_t;
190192

191193
typedef struct {
@@ -213,6 +215,16 @@ static inline void ctf_top_thread_priority_set(uint32_t thread_id, int8_t prio,
213215
thread_id, name, prio);
214216
}
215217

218+
static inline void ctf_top_thread_sleep_enter(uint32_t timeout)
219+
{
220+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_THREAD_SLEEP_ENTER), timeout);
221+
}
222+
223+
static inline void ctf_top_thread_sleep_exit(uint32_t timeout, int32_t ret)
224+
{
225+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_THREAD_SLEEP_EXIT), timeout, ret);
226+
}
227+
216228
static inline void ctf_top_thread_create(uint32_t thread_id, int8_t prio,
217229
ctf_bounded_string_t name)
218230
{

subsys/tracing/ctf/tracing_ctf.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ extern "C" {
3131
#define sys_port_trace_k_thread_join_enter(thread, timeout)
3232
#define sys_port_trace_k_thread_join_blocking(thread, timeout)
3333
#define sys_port_trace_k_thread_join_exit(thread, timeout, ret)
34-
#define sys_port_trace_k_thread_sleep_enter(timeout)
35-
#define sys_port_trace_k_thread_sleep_exit(timeout, ret)
34+
35+
#define sys_port_trace_k_thread_sleep_enter(timeout) \
36+
sys_trace_k_thread_sleep_enter(timeout)
37+
#define sys_port_trace_k_thread_sleep_exit(timeout, ret) \
38+
sys_trace_k_thread_sleep_exit(timeout, ret)
39+
3640
#define sys_port_trace_k_thread_msleep_enter(ms)
3741
#define sys_port_trace_k_thread_msleep_exit(ms, ret)
3842
#define sys_port_trace_k_thread_usleep_enter(us)

0 commit comments

Comments
 (0)