Skip to content

Commit

Permalink
Make a CPU bar on the first frame as well
Browse files Browse the repository at this point in the history
Use CPU percentages for the first frame, before we have managed to
capture any timings.
  • Loading branch information
walles committed Jul 7, 2022
1 parent 4cab344 commit 333736e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions px/px_category_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,39 @@ def ram_by_user(length: int, all_processes: List[px_process.PxProcess]) -> str:
)


def create_cpu_getter(
all_processes: List[px_process.PxProcess],
) -> Callable[[px_process.PxProcess], Optional[float]]:
"""
Getter for cpu_time_seconds if there are any, otherwise for cpu_percent (of
which we know there are a bunch).
"""
for process in all_processes:
if process.cpu_time_seconds is None:
continue
if process.cpu_time_seconds > 0:
return lambda p: p.cpu_time_seconds

return lambda p: p.cpu_percent


def cpu_by_program(length: int, all_processes: List[px_process.PxProcess]) -> str:
# FIXME: If all CPU times are zero / unset, use CPU percentages instead.
# That would make the switch between the first and the second screen frames
# less jarring to look at.
return render_bar(
length,
cluster_processes(
all_processes,
lambda process: process.command,
lambda process: process.cpu_time_seconds,
create_cpu_getter(all_processes),
),
)


def cpu_by_user(length: int, all_processes: List[px_process.PxProcess]) -> str:
# FIXME: If all CPU times are zero / unset, use CPU percentages instead.
# That would make the switch between the first and the second screen frames
# less jarring to look at.
return render_bar(
length,
cluster_processes(
all_processes,
lambda process: process.username,
lambda process: process.cpu_time_seconds,
create_cpu_getter(all_processes),
),
)

0 comments on commit 333736e

Please sign in to comment.