diff --git a/include/debug/tracing.h b/include/debug/tracing.h index 6c60110ad50..c1bdc46de9a 100644 --- a/include/debug/tracing.h +++ b/include/debug/tracing.h @@ -99,6 +99,12 @@ void z_sys_trace_thread_switched_out(void); */ #define sys_trace_thread_info(thread) +/** + * @brief Called when a thread name is set + * @param thread Thread structure + */ +#define sys_trace_thread_name_set(thread) + /** * @brief Called when entering an ISR */ diff --git a/kernel/thread.c b/kernel/thread.c index b8a63d0e39f..2659adad059 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -192,6 +192,7 @@ int z_impl_k_thread_name_set(struct k_thread *thread, const char *value) strncpy(thread->name, value, CONFIG_THREAD_MAX_NAME_LEN); thread->name[CONFIG_THREAD_MAX_NAME_LEN - 1] = '\0'; + sys_trace_thread_name_set(thread); return 0; #else ARG_UNUSED(thread); diff --git a/subsys/debug/tracing/ctf/ctf_middle.h b/subsys/debug/tracing/ctf/ctf_middle.h index 5fc850b1844..17559e83901 100644 --- a/subsys/debug/tracing/ctf/ctf_middle.h +++ b/subsys/debug/tracing/ctf/ctf_middle.h @@ -64,6 +64,7 @@ typedef enum { CTF_EVENT_THREAD_READY = 0x17, CTF_EVENT_THREAD_PENDING = 0x18, CTF_EVENT_THREAD_INFO = 0x19, + CTF_EVENT_THREAD_NAME_SET = 0x1A, CTF_EVENT_ISR_ENTER = 0x20, CTF_EVENT_ISR_EXIT = 0x21, CTF_EVENT_ISR_EXIT_TO_SCHEDULER = 0x22, @@ -170,6 +171,18 @@ static inline void ctf_middle_thread_info( ); } +static inline void ctf_middle_thread_name_set( + u32_t thread_id, + ctf_bounded_string_t name + ) +{ + CTF_EVENT( + CTF_LITERAL(u8_t, CTF_EVENT_THREAD_NAME_SET), + thread_id, + name + ); +} + static inline void ctf_middle_isr_enter(void) { CTF_EVENT( diff --git a/subsys/debug/tracing/ctf/ctf_top.c b/subsys/debug/tracing/ctf/ctf_top.c index 6dd40d4fae1..3ed4e30925f 100644 --- a/subsys/debug/tracing/ctf/ctf_top.c +++ b/subsys/debug/tracing/ctf/ctf_top.c @@ -42,7 +42,7 @@ void sys_trace_thread_switched_in(void) void sys_trace_thread_priority_set(struct k_thread *thread) { ctf_middle_thread_priority_set((u32_t)(uintptr_t)thread, - thread->base.prio); + thread->base.prio); } void sys_trace_thread_create(struct k_thread *thread) @@ -108,6 +108,23 @@ void sys_trace_thread_info(struct k_thread *thread) #endif } +void sys_trace_thread_name_set(struct k_thread *thread) +{ +#if defined(CONFIG_THREAD_NAME) + ctf_bounded_string_t name = { "Unnamed thread" }; + + if (thread->name != NULL) { + strncpy(name.buf, thread->name, sizeof(name.buf)); + /* strncpy may not always null-terminate */ + name.buf[sizeof(name.buf) - 1] = 0; + } + ctf_middle_thread_name_set( + (u32_t)(uintptr_t)thread, + name + ); +#endif +} + void sys_trace_isr_enter(void) { ctf_middle_isr_enter(); diff --git a/subsys/debug/tracing/ctf/tsdl/metadata b/subsys/debug/tracing/ctf/tsdl/metadata index 65badfeb348..ecd325be836 100644 --- a/subsys/debug/tracing/ctf/tsdl/metadata +++ b/subsys/debug/tracing/ctf/tsdl/metadata @@ -113,6 +113,15 @@ event { }; }; +event { + name = thread_name_set; + id = 0x1a; + fields := struct { + uint32_t thread_id; + ctf_bounded_string_t name[20]; + }; +}; + event { name = isr_enter; id = 0x20; diff --git a/subsys/debug/tracing/include/tracing_cpu_stats.h b/subsys/debug/tracing/include/tracing_cpu_stats.h index 2df27cdb79f..cacaad21e0d 100644 --- a/subsys/debug/tracing/include/tracing_cpu_stats.h +++ b/subsys/debug/tracing/include/tracing_cpu_stats.h @@ -36,6 +36,7 @@ void cpu_stats_reset_counters(void); #define sys_trace_thread_resume(thread) #define sys_trace_thread_ready(thread) #define sys_trace_thread_pend(thread) +#define sys_trace_thread_name_set(thread) #define sys_trace_void(id) #define sys_trace_end_call(id) diff --git a/subsys/debug/tracing/include/tracing_ctf.h b/subsys/debug/tracing/include/tracing_ctf.h index 3a300354a91..3f3eb337e2f 100644 --- a/subsys/debug/tracing/include/tracing_ctf.h +++ b/subsys/debug/tracing/include/tracing_ctf.h @@ -25,6 +25,7 @@ void sys_trace_thread_resume(struct k_thread *thread); void sys_trace_thread_ready(struct k_thread *thread); void sys_trace_thread_pend(struct k_thread *thread); void sys_trace_thread_info(struct k_thread *thread); +void sys_trace_thread_name_set(struct k_thread *thread); void sys_trace_isr_enter(void); void sys_trace_isr_exit(void); void sys_trace_isr_exit_to_scheduler(void); diff --git a/subsys/debug/tracing/include/tracing_sysview.h b/subsys/debug/tracing/include/tracing_sysview.h index 67b195717ec..3f9c461b724 100644 --- a/subsys/debug/tracing/include/tracing_sysview.h +++ b/subsys/debug/tracing/include/tracing_sysview.h @@ -74,6 +74,8 @@ static inline void sys_trace_thread_info(struct k_thread *thread) sys_trace_thread_info(thread); \ } while (0) +#define sys_trace_thread_name_set(thread) + #define sys_trace_thread_abort(thread) #define sys_trace_thread_suspend(thread)