diff --git a/px/px_process.py b/px/px_process.py index fe65aba..6885f1d 100644 --- a/px/px_process.py +++ b/px/px_process.py @@ -91,7 +91,7 @@ def __init__( memory_percent: Optional[float] = None, cpu_percent: Optional[float] = None, cpu_time: Optional[float] = None, - aggregated_cpu_time: Optional[float] = None, + aggregated_cpu_time: float = 0.0, ) -> None: self.pid: int = pid self.ppid: Optional[int] = ppid @@ -178,12 +178,9 @@ def set_cpu_time_seconds(self, seconds: Optional[float]) -> None: self.cpu_time_s = seconds_to_str(seconds) self.cpu_time_seconds = seconds - def set_aggregated_cpu_time_seconds(self, seconds: Optional[float]) -> None: - self.aggregated_cpu_time_s: str = "--" - self.aggregated_cpu_time_seconds = None - if seconds is not None: - self.aggregated_cpu_time_s = seconds_to_str(seconds) - self.aggregated_cpu_time_seconds = seconds + def set_aggregated_cpu_time_seconds(self, seconds: float) -> None: + self.aggregated_cpu_time_s = seconds_to_str(seconds) + self.aggregated_cpu_time_seconds = seconds def match(self, string, require_exact_user=True): """ diff --git a/px/px_terminal.py b/px/px_terminal.py index 0cce65e..8194bde 100644 --- a/px/px_terminal.py +++ b/px/px_terminal.py @@ -409,9 +409,9 @@ def to_screen_lines( if sort_order == px_sort_order.SortOrder.AGGREGATED_CPU: if proc.pid <= 1: # Both the kernel (PID 0) and the init process (PID 1) will just - # have contain the total time of all other processes. Since we - # only use this max value for highlighting (see below), if we - # include these only they will be highlighted. So we skip them. + # contain the total time of all other processes. Since we only + # use this max value for highlighting (see below), if we include + # these only they will be highlighted. So we skip them. continue cpu_time_seconds = proc.aggregated_cpu_time_seconds if cpu_time_seconds is not None and cpu_time_seconds > max_cpu_time_seconds: diff --git a/px/px_top.py b/px/px_top.py index 835ace8..df1b6b1 100644 --- a/px/px_top.py +++ b/px/px_top.py @@ -126,13 +126,6 @@ def get_notnone_cpu_time_seconds(proc: px_process.PxProcess) -> float: return 0 -def get_notnone_aggregated_cpu_time_seconds(proc: px_process.PxProcess) -> float: - seconds = proc.aggregated_cpu_time_seconds - if seconds is not None: - return seconds - return 0 - - def get_notnone_memory_percent(proc: px_process.PxProcess) -> float: percent = proc.memory_percent if percent is not None: @@ -174,7 +167,9 @@ def sort_by_cpu_usage_tree( def sort_children(proc: px_process.PxProcess) -> None: proc.children = sorted( - proc.children, key=get_notnone_aggregated_cpu_time_seconds, reverse=True + proc.children, + key=lambda child: child.aggregated_cpu_time_seconds, + reverse=True, ) for child in proc.children: sort_children(child)