Skip to content

Conversation

@Rbb666
Copy link
Member

@Rbb666 Rbb666 commented Aug 28, 2025

拉取/合并请求描述:(PR description)

添加线程使用率功能,默认不使能:

image

使能后:

image image

[

为什么提交这份PR (why to submit this PR)

你的解决方案是什么 (what is your solution)

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
  • .config:
  • action:

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@Rbb666 Rbb666 requested a review from Guozhanxin August 28, 2025 11:18
@github-actions
Copy link

github-actions bot commented Aug 28, 2025

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: Maihuanyi

Changed Files (Click to expand)
  • components/finsh/cmd.c

🏷️ Tag: kernel

Reviewers: GorrayLi ReviewSun hamburger-os lianux-mm wdfk-prog xu18838022837

Changed Files (Click to expand)
  • src/Kconfig
  • src/kservice.c

📊 Current Review Status (Last Updated: 2025-08-29 10:36 CST)

  • GorrayLi Pending Review
  • Maihuanyi Pending Review
  • ReviewSun Pending Review
  • hamburger-os Pending Review
  • lianux-mm Pending Review
  • wdfk-prog Pending Review
  • xu18838022837 Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

Copy link
Contributor

@wdfk-prog wdfk-prog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Rbb666 Rbb666 force-pushed the usage branch 4 times, most recently from c99577a to c899360 Compare August 28, 2025 15:24
@Rbb666 Rbb666 changed the title [Add][kservice]Add thread usage support. [msh][kservice]Add thread usage support. Aug 29, 2025
Copy link
Contributor

Copilot AI left a 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

Comment on lines +576 to +578
/* 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);
Copy link

Copilot AI Aug 29, 2025

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);
Suggested change
/* 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;

Copilot uses AI. Check for mistakes.
@Rbb666 Rbb666 merged commit bc4c036 into RT-Thread:master Aug 30, 2025
126 of 127 checks passed
@Rbb666 Rbb666 deleted the usage branch August 30, 2025 05:14
@Rbb666 Rbb666 added this to the v5.2.2 milestone Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants