Skip to content

feat: 增加线程启动计数与切换时间戳,调整线程列表输出调整输出格式 - #10689

Open
meng-plus wants to merge 3 commits into
RT-Thread:masterfrom
meng-plus:feat/thread_tracer
Open

meng-plus wants to merge 3 commits into
RT-Thread:masterfrom
meng-plus:feat/thread_tracer

Conversation

@meng-plus

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

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(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自查

@github-actions

github-actions Bot commented Sep 12, 2025

Copy link
Copy Markdown

📌 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
Copy Markdown
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
Copy Markdown
Contributor

cmd.c的289行没对齐

@ReviewSun

Copy link
Copy Markdown
Contributor

LGTM

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

Rbb666 commented Sep 13, 2025

Copy link
Copy Markdown
Member

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

@meng-plus

meng-plus commented Sep 13, 2025

Copy link
Copy Markdown
Contributor Author

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

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

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

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

@hamburger-os

Copy link
Copy Markdown
Contributor

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

@meng-plus

Copy link
Copy Markdown
Contributor Author

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

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

@dongly

dongly commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown
Member

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

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

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

🏷️ Tag: kernel

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

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

📊 Current Review Status (Last Updated: 2026-09-24 16:55 CST)


📝 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.

@meng-plus
meng-plus force-pushed the feat/thread_tracer branch from a45f4a8 to 1a0e926 Compare August 6, 2026 06:55
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

at32f415-start

  • ROM: .text -24 B (-0.0%, 65,376 B / 262,144 B, total: 25% used)

esp32-c3

  • drom0_0_seg: .flash.rodata -8 B (-0.0%, 410,980 B / 8,388,576 B, total: 5% used)
  • iram0_2_seg: .flash.text -32 B (-0.0%, 229,562 B / 8,388,576 B, total: 3% used)

gd32105r-start

  • CODE: .text -24 B (-0.0%, 69,292 B / 262,144 B, total: 26% used)

hc32f334

  • FLASH: .text -20 B (-0.0%, 99,548 B / 131,072 B, total: 76% used)

hpmicro-hpm5301evklite

  • DLM: .bss +16 B (+0.0%, 58,272 B / 130,304 B, total: 45% used)
  • ILM: .fast +32 B (+0.1%, 38,240 B / 131,072 B, total: 29% used)
  • XPI0: .fast +32 B, .text +224 B (+0.2%, 125,224 B / 1,048,576 B, total: 12% used)

infineon-psoc6

  • flash: .text -24 B (-0.0%, 116,148 B / 262,144 B, total: 44% used)

k230

  • SRAM: .bss +64 B, .eh_frame +48 B, .text +64 B (+0.0%, 1,128,691 B / 268,300,288 B, total: 0% used)

loongson-ls1cdev

  • Code: .text -32 B (-0.0%, 363,272 B)

nordic-nrf51822

  • FLASH: .text -32 B (-0.1%, 51,976 B / 262,144 B, total: 20% used)

nuvoton-m487

  • CODE: .text -40 B (-0.0%, 355,968 B / 524,288 B, total: 68% used)

qemu-virt64-aarch64

  • Code: .eh_frame +8 B, .text +368 B (+0.0%, 1,077,596 B)
  • Data: .bss +112 B, .data +8 B (+0.0%, 517,640 B)

raspberry-pico-rp2040

  • FLASH: .rodata -8 B, .text -24 B (-0.0%, 114,104 B / 2,097,152 B, total: 5% used)

renesas-ra2l1

  • FLASH: .text -24 B (-0.0%, 98,232 B / 262,144 B, total: 37% used)

simulator

  • Code: .rela.dyn -72 B, .rodata -64 B, .text -25 B (-0.0%, 2,672,534 B)
  • Data: .data -64 B (-0.0%, 1,608,964 B)

stm32f407-rt-spark

  • CODE: .text -24 B (-0.0%, 86,024 B / 1,048,576 B, total: 8% used)

stm32l475-atk-pandora-llvm

  • ROM: .text -24 B (-0.0%, 82,628 B / 524,288 B, total: 16% used)

wch-ch32v208w-r0

  • FLASH: .text -400 B (-0.3%, 159,552 B / 491,520 B, total: 32% used)

x86

@meng-plus
meng-plus force-pushed the feat/thread_tracer branch 3 times, most recently from f28c6f9 to 52089b8 Compare September 17, 2026 03:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants