Skip to content

Commit 317e7c4

Browse files
committed
tracing: ctf: add tracing for memory slabs
Add hooks for memory slabs. Signed-off-by: Anas Nashif <[email protected]>
1 parent 89add20 commit 317e7c4

File tree

4 files changed

+163
-6
lines changed

4 files changed

+163
-6
lines changed

subsys/tracing/ctf/ctf_top.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,55 @@ void sys_trace_idle_exit(void)
219219
}
220220
}
221221

222+
/* Memory Slabs */
223+
224+
void sys_trace_k_mem_slab_init(struct k_mem_slab *slab, int ret)
225+
{
226+
ctf_top_mem_slab_init(
227+
(uint32_t)(uintptr_t)slab,
228+
(int32_t)ret
229+
);
230+
}
231+
232+
void sys_trace_k_mem_slab_alloc_enter(struct k_mem_slab *slab, k_timeout_t timeout)
233+
{
234+
ctf_top_mem_slab_alloc_enter(
235+
(uint32_t)(uintptr_t)slab,
236+
k_ticks_to_us_floor32((uint32_t)timeout.ticks)
237+
);
238+
}
239+
240+
void sys_trace_k_mem_slab_alloc_blocking(struct k_mem_slab *slab, k_timeout_t timeout)
241+
{
242+
ctf_top_mem_slab_alloc_blocking(
243+
(uint32_t)(uintptr_t)slab,
244+
k_ticks_to_us_floor32((uint32_t)timeout.ticks)
245+
);
246+
}
247+
248+
void sys_trace_k_mem_slab_alloc_exit(struct k_mem_slab *slab, k_timeout_t timeout, int ret)
249+
{
250+
ctf_top_mem_slab_alloc_exit(
251+
(uint32_t)(uintptr_t)slab,
252+
k_ticks_to_us_floor32((uint32_t)timeout.ticks),
253+
(int32_t)ret
254+
);
255+
}
256+
257+
void sys_trace_k_mem_slab_free_enter(struct k_mem_slab *slab)
258+
{
259+
ctf_top_mem_slab_free_enter(
260+
(uint32_t)(uintptr_t)slab
261+
);
262+
}
263+
264+
void sys_trace_k_mem_slab_free_exit(struct k_mem_slab *slab)
265+
{
266+
ctf_top_mem_slab_free_exit(
267+
(uint32_t)(uintptr_t)slab
268+
);
269+
}
270+
222271
/* Semaphore */
223272
void sys_trace_k_sem_init(struct k_sem *sem, int ret)
224273
{

subsys/tracing/ctf/ctf_top.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ typedef enum {
188188
CTF_EVENT_GPIO_FIRE_CALLBACK = 0x7E,
189189
CTF_EVENT_THREAD_SLEEP_ENTER = 0x7F,
190190
CTF_EVENT_THREAD_SLEEP_EXIT = 0x80,
191+
/* memory slabs */
192+
CTF_EVENT_MEM_SLAB_INIT = 0x81,
193+
CTF_EVENT_MEM_SLAB_ALLOC_ENTER = 0x82,
194+
CTF_EVENT_MEM_SLAB_ALLOC_BLOCKING = 0x83,
195+
CTF_EVENT_MEM_SLAB_ALLOC_EXIT = 0x84,
196+
CTF_EVENT_MEM_SLAB_FREE_ENTER = 0x85,
197+
CTF_EVENT_MEM_SLAB_FREE_EXIT = 0x86,
191198
} ctf_event_t;
192199

193200
typedef struct {
@@ -324,6 +331,36 @@ static inline void ctf_top_end_call(uint32_t id)
324331
{
325332
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_ID_END_CALL), id);
326333
}
334+
/* Memory Slabs */
335+
static inline void ctf_top_mem_slab_init(uint32_t slab_id, int32_t ret)
336+
{
337+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_MEM_SLAB_INIT), slab_id, ret);
338+
}
339+
340+
static inline void ctf_top_mem_slab_alloc_enter(uint32_t slab_id, uint32_t timeout)
341+
{
342+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_MEM_SLAB_ALLOC_ENTER), slab_id, timeout);
343+
}
344+
345+
static inline void ctf_top_mem_slab_alloc_blocking(uint32_t slab_id, uint32_t timeout)
346+
{
347+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_MEM_SLAB_ALLOC_BLOCKING), slab_id, timeout);
348+
}
349+
350+
static inline void ctf_top_mem_slab_alloc_exit(uint32_t slab_id, uint32_t timeout, int32_t ret)
351+
{
352+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_MEM_SLAB_ALLOC_EXIT), slab_id, timeout, ret);
353+
}
354+
355+
static inline void ctf_top_mem_slab_free_enter(uint32_t slab_id)
356+
{
357+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_MEM_SLAB_FREE_ENTER), slab_id);
358+
}
359+
360+
static inline void ctf_top_mem_slab_free_exit(uint32_t slab_id)
361+
{
362+
CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_MEM_SLAB_FREE_EXIT), slab_id);
363+
}
327364

328365
/* Semaphore */
329366
static inline void ctf_top_semaphore_init(uint32_t sem_id,

subsys/tracing/ctf/tracing_ctf.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,18 @@ extern "C" {
338338
#define sys_port_trace_k_heap_sys_k_realloc_enter(heap, ptr)
339339
#define sys_port_trace_k_heap_sys_k_realloc_exit(heap, ptr, ret)
340340

341-
#define sys_port_trace_k_mem_slab_init(slab, rc)
342-
#define sys_port_trace_k_mem_slab_alloc_enter(slab, timeout)
343-
#define sys_port_trace_k_mem_slab_alloc_blocking(slab, timeout)
344-
#define sys_port_trace_k_mem_slab_alloc_exit(slab, timeout, ret)
345-
#define sys_port_trace_k_mem_slab_free_enter(slab)
346-
#define sys_port_trace_k_mem_slab_free_exit(slab)
341+
#define sys_port_trace_k_mem_slab_init(slab, rc) \
342+
sys_trace_k_mem_slab_init(slab, rc)
343+
#define sys_port_trace_k_mem_slab_alloc_enter(slab, timeout) \
344+
sys_trace_k_mem_slab_alloc_enter(slab, timeout)
345+
#define sys_port_trace_k_mem_slab_alloc_blocking(slab, timeout) \
346+
sys_trace_k_mem_slab_alloc_blocking(slab, timeout)
347+
#define sys_port_trace_k_mem_slab_alloc_exit(slab, timeout, ret) \
348+
sys_trace_k_mem_slab_alloc_exit(slab, timeout, ret)
349+
#define sys_port_trace_k_mem_slab_free_enter(slab) \
350+
sys_trace_k_mem_slab_free_enter(slab)
351+
#define sys_port_trace_k_mem_slab_free_exit(slab) \
352+
sys_trace_k_mem_slab_free_exit(slab)
347353

348354
#define sys_port_trace_k_event_init(event)
349355
#define sys_port_trace_k_event_post_enter(event, events, events_mask)
@@ -429,6 +435,15 @@ void sys_trace_k_thread_ready(struct k_thread *thread);
429435
void sys_trace_k_thread_pend(struct k_thread *thread);
430436
void sys_trace_k_thread_info(struct k_thread *thread);
431437

438+
/* Memory Slabs */
439+
440+
void sys_trace_k_mem_slab_init(struct k_mem_slab *slab, int ret);
441+
void sys_trace_k_mem_slab_alloc_enter(struct k_mem_slab *slab, k_timeout_t timeout);
442+
void sys_trace_k_mem_slab_alloc_blocking(struct k_mem_slab *slab, k_timeout_t timeout);
443+
void sys_trace_k_mem_slab_alloc_exit(struct k_mem_slab *slab, k_timeout_t timeout, int ret);
444+
void sys_trace_k_mem_slab_free_enter(struct k_mem_slab *slab);
445+
void sys_trace_k_mem_slab_free_exit(struct k_mem_slab *slab);
446+
432447
/* Semaphore */
433448

434449
void sys_trace_k_sem_init(struct k_sem *sem, int ret);

subsys/tracing/ctf/tsdl/metadata

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,3 +1066,59 @@ event {
10661066
uint32_t cb;
10671067
};
10681068
};
1069+
1070+
1071+
1072+
/* Memory Slabs */
1073+
event {
1074+
name = mem_slab_init;
1075+
id = 0x81;
1076+
fields := struct {
1077+
uint32_t id;
1078+
int32_t ret;
1079+
};
1080+
};
1081+
1082+
event {
1083+
name = mem_slab_alloc_enter;
1084+
id = 0x82;
1085+
fields := struct {
1086+
uint32_t id;
1087+
uint32_t timeout;
1088+
};
1089+
};
1090+
1091+
event {
1092+
name = mem_slab_alloc_blocking;
1093+
id = 0x83;
1094+
fields := struct {
1095+
uint32_t id;
1096+
uint32_t timeout;
1097+
};
1098+
};
1099+
1100+
event {
1101+
name = mem_slab_alloc_exit;
1102+
id = 0x84;
1103+
fields := struct {
1104+
uint32_t id;
1105+
uint32_t timeout;
1106+
int32_t ret;
1107+
};
1108+
};
1109+
1110+
event {
1111+
name = mem_slab_free_enter;
1112+
id = 0x85;
1113+
fields := struct {
1114+
uint32_t id;
1115+
};
1116+
};
1117+
1118+
event {
1119+
name = mem_slab_free_exit;
1120+
id = 0x86;
1121+
fields := struct {
1122+
uint32_t id;
1123+
};
1124+
};

0 commit comments

Comments
 (0)