* @brief Prints detailed information about a thread * * @param[in] thread Pointer to the thread structure to print information about * @param[in] maxlen Maximum length for thread name display * * @note This function prints: * - CPU core (SMP only) and priority * - Thread state (ready, suspended, init, close, running) * - Stack information (usage percentage, size, etc.) *
| 1694 | * - Thread name |
| 1695 | */ |
| 1696 | static void print_thread_info(struct rt_thread* thread, int maxlen) |
| 1697 | { |
| 1698 | rt_uint8_t *ptr; |
| 1699 | rt_uint8_t stat; |
| 1700 | |
| 1701 | #ifdef RT_USING_SMP |
| 1702 | if (RT_SCHED_CTX(thread).oncpu != RT_CPU_DETACHED) |
| 1703 | rt_kprintf("%3d %3d ", RT_SCHED_CTX(thread).oncpu, RT_SCHED_PRIV(thread).current_priority); |
| 1704 | else |
| 1705 | rt_kprintf("N/A %3d ", RT_SCHED_PRIV(thread).current_priority); |
| 1706 | #else |
| 1707 | rt_kprintf("%3d ", RT_SCHED_PRIV(thread).current_priority); |
| 1708 | #endif /*RT_USING_SMP*/ |
| 1709 | |
| 1710 | stat = (RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK); |
| 1711 | if (stat == RT_THREAD_READY) rt_kprintf(" ready "); |
| 1712 | else if ((stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) rt_kprintf(" suspend"); |
| 1713 | else if (stat == RT_THREAD_INIT) rt_kprintf(" init "); |
| 1714 | else if (stat == RT_THREAD_CLOSE) rt_kprintf(" close "); |
| 1715 | else if (stat == RT_THREAD_RUNNING) rt_kprintf(" running"); |
| 1716 | |
| 1717 | #if defined(ARCH_CPU_STACK_GROWS_UPWARD) |
| 1718 | ptr = (rt_uint8_t *)thread->stack_addr + thread->stack_size; |
| 1719 | while (*ptr == '#')ptr--; |
| 1720 | |
| 1721 | rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", |
| 1722 | ((rt_uint32_t)thread->sp - (rt_uint32_t)thread->stack_addr), |
| 1723 | thread->stack_size, |
| 1724 | ((rt_uint32_t)ptr - (rt_uint32_t)thread->stack_addr) * 100 / thread->stack_size, |
| 1725 | thread->remaining_tick, |
| 1726 | thread->error); |
| 1727 | #else |
| 1728 | ptr = (rt_uint8_t *)thread->stack_addr; |
| 1729 | while (*ptr == '#')ptr++; |
| 1730 | |
| 1731 | rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d", |
| 1732 | (thread->stack_size + (rt_uint32_t)(rt_size_t)thread->stack_addr - (rt_uint32_t)(rt_size_t)thread->sp), |
| 1733 | thread->stack_size, |
| 1734 | (thread->stack_size + (rt_uint32_t)(rt_size_t)thread->stack_addr - (rt_uint32_t)(rt_size_t)ptr) * 100 |
| 1735 | / thread->stack_size, |
| 1736 | RT_SCHED_PRIV(thread).remaining_tick, |
| 1737 | thread->error); |
| 1738 | #endif |
| 1739 | rt_kprintf(" %-.*s\n",rt_strlen(thread->parent.name), thread->parent.name); |
| 1740 | } |
| 1741 | |
| 1742 | /** |
| 1743 | * @brief Lists all processes and threads in the system |
no test coverage detected