-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[msh][kservice]Add thread usage support. #10644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
🏷️ Tag: kernelReviewers: GorrayLi ReviewSun hamburger-os lianux-mm wdfk-prog xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2025-08-29 10:36 CST)
📝 Review Instructions
|
wdfk-prog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
c99577a to
c899360
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds thread CPU usage statistics functionality to RT-Thread, allowing users to monitor CPU usage percentage for individual threads. The feature is controlled by the RT_USING_CPU_USAGE_TRACER configuration option and integrates with the existing thread listing command.
- Adds a new API
rt_thread_get_usage()to calculate thread CPU usage percentage - Updates the thread list command to display CPU usage information
- Enhances configuration documentation for the CPU usage tracer feature
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/kservice.c | Implements rt_thread_get_usage() function to calculate thread CPU usage percentage |
| include/rtthread.h | Adds function declaration for the new CPU usage API |
| src/Kconfig | Updates help text and formatting for CPU usage tracer configuration |
| components/finsh/cmd.c | Modifies thread list output to include CPU usage column |
| /* Calculate thread usage percentage: (thread_time * 100) / total_time */ | ||
| rt_ubase_t usage = (thread_time * 100U) / total_time; | ||
| return (rt_uint8_t)(usage > 100U ? 100U : usage); |
Copilot
AI
Aug 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential integer overflow in multiplication operation. / 乘法操作可能存在整数溢出。
English: The multiplication thread_time * 100U could overflow if thread_time is large. Consider using 64-bit arithmetic or checking for overflow before multiplication to prevent incorrect results.
中文:如果 thread_time 很大,乘法操作 thread_time * 100U 可能会溢出。建议使用 64 位算术或在乘法前检查溢出,以防止错误结果。
Example/示例:
rt_uint64_t usage64 = ((rt_uint64_t)thread_time * 100U) / total_time;
rt_ubase_t usage = (rt_ubase_t)(usage64 > 100U ? 100U : usage64);| /* Calculate thread usage percentage: (thread_time * 100) / total_time */ | |
| rt_ubase_t usage = (thread_time * 100U) / total_time; | |
| return (rt_uint8_t)(usage > 100U ? 100U : usage); | |
| /* Calculate thread usage percentage: (thread_time * 100) / total_time, using 64-bit arithmetic to avoid overflow */ | |
| rt_uint64_t usage64 = ((rt_uint64_t)thread_time * 100U) / total_time; | |
| rt_ubase_t usage = (rt_ubase_t)(usage64 > 100U ? 100U : usage64); | |
| return (rt_uint8_t)usage; |
拉取/合并请求描述:(PR description)
添加线程使用率功能,默认不使能:
使能后:
[
为什么提交这份PR (why to submit this PR)
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up