Skip to content

feat(processes): read cumulative CPU time per process - #5

Draft
mxrsv wants to merge 1 commit into
mainfrom
stats-pages-roles
Draft

mxrsv wants to merge 1 commit into
mainfrom
stats-pages-roles

Conversation

@mxrsv

@mxrsv mxrsv commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • The app's Agents page needs a session cost that keeps counting while its window is closed, which summing CPU percent samples cannot give (stats pages spec AG6, DA-core). The same proc_pid_rusage call that reads the footprint now also reads user plus system time, including the children a process has reaped, so a session's finished builds still count (open question 7: include child time).
  • proc_pid_rusage keeps these times in Mach absolute-time units, so they are converted through mach_timebase_info (1 ns per tick on Intel, 125/3 ns on Apple silicon), as sysinfo 0.32 does for the same kernel counters. The trap is recorded in docs/internals/traps.md; the glossary gains "CPU time".
  • ProcessInfo.cpu_time_ns and FfiProcessInfo.cpu_time_ns (#[uniffi(default = None)], so existing Swift initialisers still compile) are None exactly when the footprint is: another user's process, or one that is gone. The CLI JSON is unchanged (serde(skip)).

The app pins this commit in a separate change (plan task C2) once it is on main.

Testing

Written in a Linux cloud session, so the macOS tests have not run. This stays a draft until they pass on a Mac.

  • cargo fmt --all --check
  • cargo test --workspace --all-targets --locked: not run on macOS. On Linux, cargo test -p tiny-ffi --locked gives 188 passed and 5 failed; the same 5 fail on 9ea3e6c without this change (chflags, lsof, running as root). cargo test -p tiny --locked passes. tiny-core's own tests do not compile on Linux before or after this change (macOS-only test code). The three unit tests of the tick conversion pass.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean for the macOS target (--target aarch64-apple-darwin, type-checks the macOS code and tests without running them); on Linux the 7 errors are the same as on 9ea3e6c.

To run on a Mac, they settle the units question:

  • busy_child_cpu_time_grows_and_matches_ps: a busy child's time grows and matches ps -o time= and the child's own getrusage, within 20 ms and 5%.
  • reaped_children_count_in_cpu_time: a child that reaped a busy grandchild reads the grandchild's time too.
  • own_process_is_readable_and_another_users_is_not and exited_child_not_yet_reaped_is_unreadable_not_zero now cover the CPU time as well.

Generated by Claude Code

The app's agent sessions need a cost that keeps counting while its
window is closed, which summing CPU percent samples cannot give. The
same proc_pid_rusage call that reads the footprint now also reads user
plus system time, including reaped children's, so a session's finished
builds still count. The kernel keeps these in Mach absolute-time units,
so they are converted through mach_timebase_info (125/3 ns per tick on
Apple silicon). ProcessInfo and FfiProcessInfo carry it as cpu_time_ns,
None exactly when the footprint is; the CLI JSON is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0156zWNYXA7UAxNLGbLUrpFx
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants