Inconsistent behaviour for RAM and CPU Monitoring
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 323
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 12
Description
Describe the bug
The Hardware CPU Module and the RAM Module show inconsistent behavior how the handle child processes.
While RAM uses the Memory of all child process
https://github.com/mlco2/codecarbon/blob/66cc37220f4c2c7b67d0424945d6a13c1b309b23/codecarbon/external/ram.py#L288-L298
CPU Limits itself to the main process https://github.com/mlco2/codecarbon/blob/66cc37220f4c2c7b67d0424945d6a13c1b309b23/codecarbon/external/hardware.py#L247-L253
Expected behavior
Similar behavior for booth, I would be in favor of having "process" and "process_tree" as option
Solution
Adding a "process_tree" option or exchanging the CPU Part with something similar to this:
elif self._tracking_mode == "process_tree":
# Sum CPU percent for process and its children
total_cpu_load = self._process.cpu_percent(interval=0.5)
for child in self._process.children(recursive=True):
try:
total_cpu_load += child.cpu_percent(interval=0.0)
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
cpu_load = total_cpu_load / self._cpu_count
power = self._tdp * cpu_load / 100
logger.debug(
f"CPU load {self._tdp} W and {cpu_load * 100:.1f}% => estimation of {power} W for process tree {self._pid}."
)
Cheers
Dominik
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the child-process handling in external/ram.py at lines 288-298 with the CPU logic in external/hardware.py at lines 247-253. Review how tracking modes are represented, then determine whether both modules should support process and process_tree consistently; the work is done when CPU and RAM apply the agreed behavior to child processes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100