Skip to content

Conversation

meng-plus
Copy link
Contributor

@meng-plus meng-plus commented Sep 12, 2025

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

[

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

增加线程运行日志 线程计数与上次执行时间计数 方便跟踪运行情况

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

  1. 在可配置宏RT_USING_CPU_USAGE_TRACER增加两个参数 ctx_last_time ctx_count
  2. 在cmd中增加日志打印
  3. 打印常量字符串的rt_kprintf 改为rt_kputs

注意

SMP 部分我未用过,不确定这样是否合适 单核心M4上已经验证

thread           pri  status      sp     stack size max used left tick   error  tcb addr   usage count    last time
---------------- ---  ------- ---------- ----------  ------  ---------- ------- ---------- ----- -------- ----------
uart2             18  suspend 0x0000019c 0x00001000    12%   0x00000064 EINTRPT 0xa0049080   0%      63       935
uart4             20  suspend 0x000000a4 0x00001000    07%   0x00000064 EINTRPT 0xa0046828   0%       5       715
uart3             18  suspend 0x000000cc 0x00001000    06%   0x00000064 EINTRPT 0xa0043e88   0%      56       945
can_rx            25  suspend 0x000000bc 0x00000800    21%   0x00000003 EINTRPT 0xa0041cc8   3%      34       926
tshell            20  running 0x00000234 0x00001000    16%   0x00000002 OK      0xa0040770   1%      12       948
LVGL              20  ready   0x00000124 0x00002000    36%   0x00000004 ETIMOUT 0x10009d04  38%     163       952
tidle0            31  ready   0x0000007c 0x00000100    48%   0x0000001c OK      0x10009c4c  44%     141       929
timer              4  suspend 0x0000010c 0x00000400    46%   0x00000005 EINTRPT 0x10009dbc   0%     117       948
main              10  suspend 0x00000144 0x00000800    25%   0x00000010 EINTRPT 0xa003fc50  10%       1         1

msh >ps
thread           pri  status      sp     stack size max used left tick   error  tcb addr   usage count    last time
---------------- ---  ------- ---------- ----------  ------  ---------- ------- ---------- ----- -------- ----------
uart2             18  suspend 0x0000019c 0x00001000    12%   0x00000064 EINTRPT 0xa0049080   0%    6677    100145
uart4             20  suspend 0x000000a4 0x00001000    07%   0x00000064 EINTRPT 0xa0046828   0%     352     99952
uart3             18  suspend 0x000000cc 0x00001000    06%   0x00000064 EINTRPT 0xa0043e88   0%    9978    100165
can_rx            25  suspend 0x000000bc 0x00000800    24%   0x00000002 EINTRPT 0xa0041cc8   5%    4907    100123
tshell            20  running 0x00000234 0x00001000    16%   0x0000000a OK      0xa0040770   0%      24    100166
LVGL              20  suspend 0x00000124 0x00002000    38%   0x0000000a EINTRPT 0x10009d04  34%   26873    100166
tidle0            31  ready   0x0000004c 0x00000100    48%   0x0000001c OK      0x10009c4c  58%   26699    100158
timer              4  suspend 0x0000010c 0x00000400    46%   0x00000002 EINTRPT 0x10009dbc   0%    4870    100154
main              10  suspend 0x00000144 0x00000800    25%   0x00000010 EINTRPT 0xa003fc50   0%     101    100105

请提供验证的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自查

Copy link

github-actions bot commented Sep 12, 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/scheduler_mp.c
  • src/scheduler_up.c

📊 Current Review Status (Last Updated: 2025-09-12 17:06 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.

@ReviewSun
Copy link
Contributor

注意空格代码对齐。麻烦改一下

@meng-plus meng-plus force-pushed the feat/thread_tracer branch 2 times, most recently from 2d31456 to 3c7a768 Compare September 12, 2025 08:41
@ReviewSun
Copy link
Contributor

cmd.c的289行没对齐

@ReviewSun
Copy link
Contributor

LGTM

@meng-plus meng-plus changed the title feat: 优化线程列表输出,增加CPU使用率跟踪功能,调整输出格式 feat: 增加线程启动计数与切换时间戳,调整线程列表输出调整输出格式 Sep 12, 2025
@Rbb666 Rbb666 requested review from Rbb666 and Guozhanxin September 13, 2025 03:35
@Rbb666
Copy link
Member

Rbb666 commented Sep 13, 2025

这个功能有什么作用呢?感觉查看计数的方法并不是很直观

@meng-plus
Copy link
Contributor Author

meng-plus commented Sep 13, 2025

这个功能有什么作用呢?感觉查看计数的方法并不是很直观

count计数功能,可以帮助统计 消费者线程执行次数 活跃度 实际执行频率

last time 记录上次执行的时间, 排查线程是否被阻塞 锁死时间 以及实时性判定

它是占用率表现的信息补充,更加细节的了解线程的执行情况

@hamburger-os
Copy link
Contributor

我也感觉切换次数+切换时间这两个原始指标看起来不太直观。
切换次数换成累计运行时间,或者占用比例,是否是更好的选择。

@meng-plus
Copy link
Contributor Author

我也感觉切换次数+切换时间这两个原始指标看起来不太直观。
切换次数换成累计运行时间,或者占用比例,是否是更好的选择。

累计运行时间里面已经有了 thread->user_time

@dongly
Copy link
Contributor

dongly commented Sep 18, 2025

stack size,left tick 现在是十六进制的,是否改为10进制.我认为这样更直观点

@Rbb666 Rbb666 added the -1 No vote label Sep 20, 2025
@BernardXiong
Copy link
Member

last time,感觉是一份参考,或者说非常弱的参考 (实时系统不那么看这份last time)。感觉这样修改意义不大呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-1 No vote component: finsh Component Kernel PR has src relate code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants