Skip to content

feat: Add executor timing stats with thread config support#88

Merged
qzhhhi merged 2 commits into
mainfrom
dev/rt
Jul 7, 2026
Merged

feat: Add executor timing stats with thread config support#88
qzhhhi merged 2 commits into
mainfrom
dev/rt

Conversation

@qzhhhi

@qzhhhi qzhhhi commented Jul 7, 2026

Copy link
Copy Markdown
Member
  • Add optional thread_config support for the executor update thread
  • Log cumulative and 5s window timing stats for start lateness, update duration, skipped cycles, and top component costs
  • Vendor a local TDigest utility for percentile reporting
  • Switch affected packages to C++23 for std::format and std::expected
  • Allow starting the executor with an empty components list for testing

主要变更

  • 为执行器更新线程新增可选 thread_config 支持:可通过配置解析并应用线程名、CPU 亲和性、调度策略(policy)、优先级(priority)与 nice(nice),并在配置校验与应用失败时返回错误结果。
  • 彻底改造更新线程的调度与统计框架:根据“计划开始时间/实际结束时间”推导下一次计划迭代,落后时自动计算并跳过周期,同时累计跳过次数;对每次迭代记录计划迟到与更新耗时的分布(用 TDigest 做 p50/p99/最大值等),并在每个 5 秒窗口到点输出累计与窗口统计(含启动迟到/更新持续时间、跳过占比,以及 5 秒内组件耗时 top3/占比)。
  • 新增本地 TDigest 实现,用于分位数(quantile)与累计分布统计。
  • 将相关包切换到 C++23:使用 CMake 标准变量强制 CMAKE_CXX_STANDARD 23,以便使用 std::formatstd::expected 等能力。
  • 允许在测试场景下以空 components 列表启动执行器;同时调整 main()components 参数读取逻辑的处理方式(不再基于布尔返回值抛出显式异常)。

其他

  • 新增公开接口:rmcs_utility::ThreadConfig(线程配置解析与应用)、rmcs_utility::TDigest(分位数统计)。

- Add optional `thread_config` support for the executor update thread
- Log cumulative and 5s window timing stats for start lateness, update duration, skipped cycles, and top component costs
- Vendor a local `TDigest` utility for percentile reporting
- Switch affected packages to C++23 for `std::format` and `std::expected`
- Allow starting the executor with an empty `components` list for  testing
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b4fc8ad7-d6ad-479c-98f4-6dd7d0064b3b

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab6585 and 5f341fc.

📒 Files selected for processing (2)
  • rmcs_ws/src/rmcs_executor/src/executor.hpp
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • rmcs_ws/src/rmcs_executor/src/executor.hpp
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp

Walkthrough

本次改动将 rmcs_executorrmcs_utility 的 C++ 标准升级至 23,重写了 Executor 更新线程实现,简化了 main.cppcomponents 参数读取的错误处理,并新增了 TDigestThreadConfig 两个工具类。

Changes

Executor 线程调度与统计

Layer / File(s) Summary
C++ 标准升级配置
rmcs_executor/CMakeLists.txt, rmcs_utility/CMakeLists.txt
两个包均改为通过 CMAKE_CXX_STANDARD 23 并启用 CMAKE_CXX_STANDARD_REQUIRED,替代原先追加 -std=c++20 的方式。
头文件依赖与线程配置接入
rmcs_executor/src/executor.hpp
新增标准库头及 tdigest/thread_config 依赖;start() 读取 thread_config 参数并在工作线程中构造、移动并应用该配置。
统计数据结构定义
rmcs_executor/src/executor.hpp
新增累计与窗口维度的统计结构、线程状态结构,以及窗口级组件耗时聚合结构。
线程主循环与迭代调度
rmcs_executor/src/executor.hpp
新增 thread_mainexecute_update_iterationrecord_start_latenessrecord_update_durationcalculate_next_iteration_time,实现按计划时间推导下一迭代、跳过周期计数与迟到/耗时记录。
周期性统计日志输出
rmcs_executor/src/executor.hpp
新增 log_due_reportslog_cumulative_statslog_window_statscollect_top_component_statsformat_top_component_stats 及格式化辅助函数,用于每 5 秒输出累计与窗口统计并重置窗口计数。
components 参数读取简化
rmcs_executor/src/main.cpp
移除参数获取失败时抛出异常的分支,改为忽略返回值。

TDigest 与 ThreadConfig 工具类新增

Layer / File(s) Summary
TDigest 类型与接口声明
rmcs_utility/include/rmcs_utility/tdigest.hpp
新增 Centroid 结构体、比较运算符,以及 TDigest 模板类的接口声明与内部数据结构。
构造、插入与合并实现
rmcs_utility/include/rmcs_utility/tdigest.hpp
实现 TDigest 的构造/移动/赋值、insert(const TDigest&)reset()get(),以及缩放函数与 merge() 压缩逻辑。
分位数与累计分布计算
rmcs_utility/include/rmcs_utility/tdigest.hpp
实现 quantile(p)cumulative_distribution(x),处理空/单 centroid 及边界插值情况。
ThreadConfig 构造与访问器
rmcs_utility/include/rmcs_utility/thread_config.hpp
新增两个构造函数解析 spec,及 name/cpus/policy/priority/nice 只读访问器。
应用到当前线程
rmcs_utility/include/rmcs_utility/thread_config.hpp
实现 apply_to_current_thread(),依次设置调度策略、nice、CPU 亲和性与线程名。
字段解析与跨字段校验
rmcs_utility/include/rmcs_utility/thread_config.hpp
新增解析工具函数、parse_fields/assign_field 字段分派、policy/cpus 解析,以及 validate 跨字段约束校验。

Estimated code review effort: 4 (Complex) | ~60 minutes

Suggested reviewers: creeper5820

Poem

兔子跳进代码林,标准升到二十三,
线程戴上新帽子,节拍跑得更整齐。
五秒一报小铃响,分位数里看高低,
🥕 耗时排行排前三,轻快更新向前提。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更的核心:执行器时序统计与线程配置支持。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/rt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
rmcs_ws/src/rmcs_utility/include/rmcs_utility/thread_config.hpp (1)

83-112: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

改用线程安全的错误信息格式化

这 4 处都在用 std::strerror,并发时可能串用同一个静态缓冲区;建议统一改成 std::system_category().message(error_code)errno 分支也改用同样的方式(可补 #include <system_error>)。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rmcs_ws/src/rmcs_utility/include/rmcs_utility/thread_config.hpp` around lines
83 - 112, The error formatting in ThreadConfig::apply uses std::strerror in
multiple failure paths, which is not thread-safe and can return mixed messages
under concurrency. Update the scheduling, nice, affinity, and name error
branches in thread_config.hpp to format messages via
std::system_category().message(error_code) instead of std::strerror, and apply
the same approach to the errno-based setpriority path; add the needed
system_error include if it is not already present.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rmcs_ws/src/rmcs_executor/src/executor.hpp`:
- Around line 125-126: The update_rate to period conversion in executor.hpp is
not validated, so non-finite, non-positive, or too-large values can produce an
invalid or zero period and break later logic. In start() of executor::Executor,
validate update_rate with std::isfinite(update_rate) and update_rate > 0.0
before computing the period, then verify the derived std::chrono::nanoseconds
period has a count greater than zero before using it; apply the check around the
existing period calculation and any code that relies on period.count().

In `@rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp`:
- Around line 158-168: `TDigest::insert` only updates `buffer` until `merge()`
is triggered, but the read paths (`quantile`, `cumulative_distribution`, `get`,
`size`, and the executor’s `maybe_quantile` call site) appear to read only from
`active`, so pending samples can be invisible. Update the `TDigest` read API to
include buffered samples, either by flushing a snapshot before queries or by
merging/considering `buffer` inside the query methods, and make the `executor`
path use the corrected `TDigest::quantile` behavior so `sample_count > 0` never
reports stale or empty results.
- Around line 256-264: Reject zero-sized TDigest construction in
TDigest::TDigest(size_t size) by validating size at the start of the constructor
and preventing creation when size == 0. The issue is that one/two and the active
digest end up with zero capacity, which later breaks merge normalization in
merge() via normalizer_fn on inactive.values.capacity(). Add an upfront guard in
the TDigest constructor to fail fast with a clear error or exception so callers
cannot instantiate TDigest(0).
- Around line 305-318: The TDigest::insert(const TDigest& src) implementation
only copies src.active->values and ignores any pending samples still sitting in
src.buffer, so merge the source digest state first (on a local copy) before
inserting its centroids into this digest. Update TDigest::insert to work from a
merged copy of src, then feed that copy’s active values through the existing
buffer/merge flow so max_val/min_val and the actual data stay consistent.
- Around line 41-47: The tdigest.hpp header uses std::pair and std::make_pair
without explicitly including the required <utility> header, relying on indirect
includes. Update the header’s include list to add <utility> so the template code
in tdigest.hpp remains self-contained and compiles independently.

---

Nitpick comments:
In `@rmcs_ws/src/rmcs_utility/include/rmcs_utility/thread_config.hpp`:
- Around line 83-112: The error formatting in ThreadConfig::apply uses
std::strerror in multiple failure paths, which is not thread-safe and can return
mixed messages under concurrency. Update the scheduling, nice, affinity, and
name error branches in thread_config.hpp to format messages via
std::system_category().message(error_code) instead of std::strerror, and apply
the same approach to the errno-based setpriority path; add the needed
system_error include if it is not already present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 794a3821-8ac4-4416-b7e2-018af9763e6c

📥 Commits

Reviewing files that changed from the base of the PR and between 2c63c7d and 4ab6585.

📒 Files selected for processing (6)
  • rmcs_ws/src/rmcs_executor/CMakeLists.txt
  • rmcs_ws/src/rmcs_executor/src/executor.hpp
  • rmcs_ws/src/rmcs_executor/src/main.cpp
  • rmcs_ws/src/rmcs_utility/CMakeLists.txt
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp
  • rmcs_ws/src/rmcs_utility/include/rmcs_utility/thread_config.hpp

Comment thread rmcs_ws/src/rmcs_executor/src/executor.hpp Outdated
Comment thread rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp
Comment thread rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp
Comment thread rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp Outdated
Comment thread rmcs_ws/src/rmcs_utility/include/rmcs_utility/tdigest.hpp

@creeper5820 creeper5820 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AC

@qzhhhi qzhhhi merged commit 5e049d5 into main Jul 7, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in RMCS Jul 7, 2026
@qzhhhi qzhhhi deleted the dev/rt branch July 7, 2026 13:48
qzhhhi added a commit that referenced this pull request Jul 7, 2026
- Add optional `thread_config` support for the executor update thread
- Log cumulative and 5s window timing stats for start lateness, update duration, skipped cycles, and top component costs
- Vendor a local `TDigest` utility for percentile reporting
- Switch affected packages to C++23 for `std::format` and `std::expected`
- Allow starting the executor with an empty `components` list for  testing
creeper5820 pushed a commit that referenced this pull request Jul 8, 2026
- Add optional `thread_config` support for the executor update thread
- Log cumulative and 5s window timing stats for start lateness, update duration, skipped cycles, and top component costs
- Vendor a local `TDigest` utility for percentile reporting
- Switch affected packages to C++23 for `std::format` and `std::expected`
- Allow starting the executor with an empty `components` list for  testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants