Skip to content

Commit

Permalink
Self review
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Mar 28, 2024
1 parent 2c81d80 commit ee86034
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
11 changes: 4 additions & 7 deletions px/px_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions px/px_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 3 additions & 8 deletions px/px_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ee86034

Please sign in to comment.