score: Add and use _Thread_Get_name()

Update #2858.
This commit is contained in:
Sebastian Huber
2017-01-12 09:25:56 +01:00
parent 2b72162b81
commit 7ced9d9bb2
7 changed files with 82 additions and 37 deletions

View File

@@ -40,7 +40,7 @@ typedef struct {
static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg ) static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg )
{ {
cpu_usage_context *ctx; cpu_usage_context *ctx;
char name[ 13 ]; char name[ 38 ];
uint32_t ival; uint32_t ival;
uint32_t fval; uint32_t fval;
Timestamp_Control uptime; Timestamp_Control uptime;
@@ -49,7 +49,7 @@ static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg )
uint32_t nanoseconds; uint32_t nanoseconds;
ctx = arg; ctx = arg;
rtems_object_get_name( the_thread->Object.id, sizeof( name ), name ); _Thread_Get_name( the_thread, name, sizeof( name ) );
_Thread_Get_CPU_time_used( the_thread, &used ); _Thread_Get_CPU_time_used( the_thread, &used );
_TOD_Get_uptime( &uptime ); _TOD_Get_uptime( &uptime );

View File

@@ -47,6 +47,12 @@ rtems_monitor_task_canonical(
api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ]; api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ];
_Thread_Get_name(
rtems_thread,
canonical_task->name_string,
sizeof( canonical_task->name_string )
);
rtems_monitor_task_wait_info( canonical_task, rtems_thread ); rtems_monitor_task_wait_info( canonical_task, rtems_thread );
canonical_task->entry = rtems_thread->Start.Entry; canonical_task->entry = rtems_thread->Start.Entry;
@@ -97,7 +103,7 @@ rtems_monitor_task_dump(
length += rtems_monitor_dump_id(monitor_task->id); length += rtems_monitor_dump_id(monitor_task->id);
length += rtems_monitor_pad(11, length); length += rtems_monitor_pad(11, length);
length += rtems_monitor_dump_name(monitor_task->id); length += fprintf(stdout, "%s", monitor_task->name_string);
length += rtems_monitor_pad(21, length); length += rtems_monitor_pad(21, length);
length += rtems_monitor_dump_decimal(monitor_task->cpu); length += rtems_monitor_dump_decimal(monitor_task->cpu);
length += rtems_monitor_pad(26, length); length += rtems_monitor_pad(26, length);

View File

@@ -95,6 +95,7 @@ typedef struct {
rtems_id id; rtems_id id;
rtems_name name; rtems_name name;
/* end of common portion */ /* end of common portion */
char name_string[10];
Thread_Entry_information entry; Thread_Entry_information entry;
void *stack; void *stack;
uint32_t stack_size; uint32_t stack_size;

View File

@@ -43,6 +43,7 @@
#include <rtems/printer.h> #include <rtems/printer.h>
#include <rtems/stackchk.h> #include <rtems/stackchk.h>
#include <rtems/score/percpu.h> #include <rtems/score/percpu.h>
#include <rtems/score/threadimpl.h>
/* /*
* This structure is used to fill in and compare the "end of stack" * This structure is used to fill in and compare the "end of stack"
@@ -238,10 +239,8 @@ static void Stack_check_report_blown_task(
"task name: 0x%08" PRIx32 "\n", "task name: 0x%08" PRIx32 "\n",
running->Object.name.name_u32 running->Object.name.name_u32
); );
printk( _Thread_Get_name(running, name, sizeof(name));
"task name string: %s\n", printk("task name string: %s\n", name);
rtems_object_get_name(running->Object.id, sizeof(name), name)
);
printk( printk(
"task stack area (%lu Bytes): 0x%08" PRIxPTR " .. 0x%08" PRIxPTR "\n", "task stack area (%lu Bytes): 0x%08" PRIxPTR " .. 0x%08" PRIxPTR "\n",
(unsigned long) stack->size, (unsigned long) stack->size,
@@ -362,8 +361,9 @@ static bool Stack_check_Dump_threads_usage(
void *high_water_mark; void *high_water_mark;
void *current; void *current;
Stack_Control *stack; Stack_Control *stack;
char name[5]; char name[ 22 ];
const rtems_printer *printer; const rtems_printer *printer;
uint32_t id;
printer = arg; printer = arg;
@@ -394,37 +394,32 @@ static bool Stack_check_Dump_threads_usage(
else else
used = 0; used = 0;
#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) if ( the_thread == NULL ) {
if ( the_thread ) id = 0xffffffff;
#endif strlcpy( name, "INTR", sizeof( name ) );
{ } else
rtems_printf( #endif
printer, {
"0x%08" PRIx32 " %4s", id = the_thread->Object.id;
the_thread->Object.id, _Thread_Get_name( the_thread, name, sizeof( name ) );
rtems_object_get_name( the_thread->Object.id, sizeof(name), name ) }
);
}
#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE)
else {
rtems_printf( printer, "0x%08x INTR", ~0 );
}
#endif
rtems_printf( rtems_printf(
printer, printer,
" %p - %p %p %8" PRId32 " ", "0x%08" PRIx32 " %-21s 0x%08" PRIuPTR " 0x%08" PRIuPTR " 0x%08" PRIuPTR " %6" PRId32 " ",
stack->area, id,
stack->area + stack->size - 1, name,
current, (uintptr_t) stack->area,
(uintptr_t) stack->area + (uintptr_t) stack->size - 1,
(uintptr_t) current,
size size
); );
if (Stack_check_Initialized == 0) { if (Stack_check_Initialized == 0) {
rtems_printf( printer, "Unavailable\n" ); rtems_printf( printer, "N/A\n" );
} else { } else {
rtems_printf( printer, "%8" PRId32 "\n", used ); rtems_printf( printer, "%6" PRId32 "\n", used );
} }
return false; return false;
@@ -453,9 +448,10 @@ void rtems_stack_checker_report_usage_with_plugin(
const rtems_printer* printer const rtems_printer* printer
) )
{ {
rtems_printf( printer, "Stack usage by thread\n"); rtems_printf(
rtems_printf( printer, printer,
" ID NAME LOW HIGH CURRENT AVAILABLE USED\n" " STACK USAGE BY THREAD\n"
"ID NAME LOW HIGH CURRENT AVAIL USED\n"
); );
/* iterate over all threads and dump the usage */ /* iterate over all threads and dump the usage */
@@ -471,8 +467,6 @@ void rtems_stack_checker_report_usage_with_plugin(
RTEMS_DECONST( rtems_printer *, printer ) RTEMS_DECONST( rtems_printer *, printer )
); );
#endif #endif
printer = NULL;
} }
void rtems_stack_checker_report_usage( void ) void rtems_stack_checker_report_usage( void )

View File

@@ -299,6 +299,7 @@ libscore_a_SOURCES += src/threadentryadaptorpointer.c
libscore_a_SOURCES += src/threadgetcputimeused.c libscore_a_SOURCES += src/threadgetcputimeused.c
libscore_a_SOURCES += src/threadglobalconstruction.c libscore_a_SOURCES += src/threadglobalconstruction.c
libscore_a_SOURCES += src/threaditerate.c libscore_a_SOURCES += src/threaditerate.c
libscore_a_SOURCES += src/threadname.c
libscore_a_SOURCES += src/threadscheduler.c libscore_a_SOURCES += src/threadscheduler.c
libscore_a_SOURCES += src/threadtimeout.c libscore_a_SOURCES += src/threadtimeout.c
libscore_a_SOURCES += src/threadwaitgetid.c libscore_a_SOURCES += src/threadwaitgetid.c

View File

@@ -11,7 +11,7 @@
* COPYRIGHT (c) 1989-2008. * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* *
* Copyright (c) 2014, 2016 embedded brains GmbH. * Copyright (c) 2014, 2017 embedded brains GmbH.
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
@@ -1951,6 +1951,12 @@ RTEMS_INLINE_ROUTINE void _Thread_Remove_timer_and_unblock(
#endif #endif
} }
size_t _Thread_Get_name(
const Thread_Control *the_thread,
char *buffer,
size_t buffer_size
);
/** @}*/ /** @}*/
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2017 embedded brains GmbH.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/score/threadimpl.h>
#include <string.h>
size_t _Thread_Get_name(
const Thread_Control *the_thread,
char *buffer,
size_t buffer_size
)
{
const char *name;
name = the_thread->Join_queue.Queue.name;
if ( name != NULL && name[ 0 ] != '\0' ) {
return strlcpy( buffer, name, buffer_size );
} else {
return _Objects_Name_to_string(
the_thread->Object.name,
false,
buffer,
buffer_size
);
}
}