Skip to content

Inconsistent behaviour for RAM and CPU Monitoring #976

@Matyro

Description

@Matyro

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

def process_memory_GB(self):
"""
Property to compute the process's total memory usage in bytes.
Returns:
float: RAM usage (GB)
"""
children_memories = self._get_children_memories() if self._children else []
main_memory = psutil.Process(self._pid).memory_info().rss
memories = children_memories + [main_memory]
return sum([m for m in memories if m] + [0]) / B_TO_GB

CPU Limits itself to the main process

elif self._tracking_mode == "process":
cpu_load = self._process.cpu_percent(interval=0.5) / 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 {self._pid}."
)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions