Skip to content

Commit bc6d16e

Browse files
rugeGerritsennashif
authored andcommitted
systemview: Use common function to get sysview thread name
Use a common function to get the thread name. There was no necessity in keeping sys_trace_thread_info() inline, Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
1 parent 7a9da57 commit bc6d16e

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

subsys/tracing/sysview/sysview.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ void sys_trace_mutex_unlock(struct k_mutex *mutex)
105105
SYS_TRACE_ID_MUTEX_UNLOCK, (uint32_t)(uintptr_t)mutex);
106106
}
107107

108+
static void set_thread_name(char *name, struct k_thread *thread)
109+
{
110+
const char *tname = k_thread_name_get(thread);
111+
112+
if (tname != NULL && tname[0] != '\0') {
113+
memcpy(name, tname, THREAD_NAME_LEN);
114+
name[THREAD_NAME_LEN - 1] = '\0';
115+
} else {
116+
snprintk(name, THREAD_NAME_LEN, "T%pE%p",
117+
thread, &thread->entry);
118+
}
119+
}
120+
121+
void sys_trace_thread_info(struct k_thread *thread)
122+
{
123+
char name[THREAD_NAME_LEN];
124+
125+
set_thread_name(name, thread);
126+
127+
SEGGER_SYSVIEW_TASKINFO Info;
128+
129+
Info.TaskID = (uint32_t)(uintptr_t)thread;
130+
Info.sName = name;
131+
Info.Prio = thread->base.prio;
132+
Info.StackBase = thread->stack_info.size;
133+
Info.StackSize = thread->stack_info.start;
134+
SEGGER_SYSVIEW_SendTaskInfo(&Info);
135+
}
136+
108137

109138

110139
static void send_task_list_cb(void)
@@ -113,19 +142,13 @@ static void send_task_list_cb(void)
113142

114143
for (thread = _kernel.threads; thread; thread = thread->next_thread) {
115144
char name[THREAD_NAME_LEN];
116-
const char *tname = k_thread_name_get(thread);
117145

118146
if (z_is_idle_thread_object(thread)) {
119147
continue;
120148
}
121149

122-
if (tname != NULL && tname[0] != '\0') {
123-
memcpy(name, tname, THREAD_NAME_LEN);
124-
name[THREAD_NAME_LEN - 1] = '\0';
125-
} else {
126-
snprintk(name, sizeof(name), "T%pE%p",
127-
thread, &thread->entry);
128-
}
150+
set_thread_name(name, thread);
151+
129152
SEGGER_SYSVIEW_SendTaskInfo(&(SEGGER_SYSVIEW_TASKINFO) {
130153
.TaskID = (uint32_t)(uintptr_t)thread,
131154
.sName = name,

subsys/tracing/sysview/tracing_sysview.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,10 @@ void sys_trace_semaphore_give(struct k_sem *sem);
2525
void sys_trace_mutex_init(struct k_mutex *mutex);
2626
void sys_trace_mutex_lock(struct k_mutex *mutex);
2727
void sys_trace_mutex_unlock(struct k_mutex *mutex);
28+
void sys_trace_thread_info(struct k_thread *thread);
2829

2930
#define sys_trace_thread_priority_set(thread)
3031

31-
static inline void sys_trace_thread_info(struct k_thread *thread)
32-
{
33-
#if IS_ENABLED(CONFIG_THREAD_NAME)
34-
char name[CONFIG_THREAD_MAX_NAME_LEN];
35-
#else
36-
char name[20];
37-
#endif
38-
39-
const char *tname = k_thread_name_get(thread);
40-
41-
if (tname != NULL && tname[0] != '\0') {
42-
memcpy(name, tname, sizeof(name));
43-
name[sizeof(name) - 1] = '\0';
44-
} else {
45-
snprintk(name, sizeof(name), "T%pE%p",
46-
thread, &thread->entry);
47-
}
48-
49-
SEGGER_SYSVIEW_TASKINFO Info;
50-
51-
Info.TaskID = (uint32_t)(uintptr_t)thread;
52-
Info.sName = name;
53-
Info.Prio = thread->base.prio;
54-
Info.StackBase = thread->stack_info.size;
55-
Info.StackSize = thread->stack_info.start;
56-
SEGGER_SYSVIEW_SendTaskInfo(&Info);
57-
}
58-
5932
#define sys_trace_thread_create(thread) \
6033
do { \
6134
SEGGER_SYSVIEW_OnTaskCreate((uint32_t)(uintptr_t)thread); \

0 commit comments

Comments
 (0)