Skip to content

fix: add process_tree tracking mode for consistent CPU/RAM monitoring#1141

Closed
wangwangbobo wants to merge 1 commit intomlco2:masterfrom
wangwangbobo:fix-cpu-process-tree-tracking
Closed

fix: add process_tree tracking mode for consistent CPU/RAM monitoring#1141
wangwangbobo wants to merge 1 commit intomlco2:masterfrom
wangwangbobo:fix-cpu-process-tree-tracking

Conversation

@wangwangbobo
Copy link
Copy Markdown

Description

This PR adds a new process_tree tracking mode to the CPU monitoring module to make its behavior consistent with RAM monitoring.

Related Issue

Fixes #976

Changes

  • Add process_tree as a valid tracking_mode option in CPU class initialization
  • Implement process_tree mode that sums CPU percent for the main process and all child processes
  • This matches the behavior of RAM monitoring which already includes child processes

Code Changes

codecarbon/external/hardware.py:

  • Line 199: Added process_tree to allowed tracking modes
  • Lines 333-345: Added new process_tree branch with CPU percent summation logic

Testing

The implementation follows the same pattern as RAM monitoring (codecarbon/external/ram.py) which already uses child process tracking.


Type: Bug Fix
Lines Changed: ~14 lines
Tracking Mode: New option for consistent process tree monitoring

- Add 'process_tree' as a valid tracking_mode option
- Implement process_tree mode to sum CPU percent for process and children
- Makes CPU monitoring behavior consistent with RAM monitoring
- Fixes issue mlco2#976
@wangwangbobo wangwangbobo requested a review from a team as a code owner March 26, 2026 10:14
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.

Inconsistent behaviour for RAM and CPU Monitoring

2 participants