Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel workers under the lead process in the GUI #291

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions pgactivity/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ def sorted(processes: List[T], *, key: SortKey, reverse: bool = False) -> List[T
... user="postgres",
... client="local",
... cpu=0.1,
... mem=0.994_254_939_413_836,
... read=0.1,
... write=0.282_725_318_098_656_75,
... state="idle in transaction",
... query="UPDATE pgbench_accounts SET abalance = abalance + 141 WHERE aid = 1932841;",
... duration=0.1,
... wait="ClientRead",
... io_wait=False,
... is_parallel_worker=False,
... ),
... LocalRunningProcess(
... pid="6240",
... application_name="pgbench",
... database="pgbench",
... user="postgres",
... client="local",
... cpu=0.1,
... mem=0.993_254_939_413_836,
... read=0.1,
... write=0.282_725_318_098_656_75,
Expand All @@ -179,7 +196,7 @@ def sorted(processes: List[T], *, key: SortKey, reverse: bool = False) -> List[T
... write=0.113_090_128_201_154_74,
... state="active",
... query="UPDATE pgbench_accounts SET abalance = abalance + 3062 WHERE aid = 7289374;",
... duration=None,
... duration=0.01,
... wait=False,
... io_wait=False,
... is_parallel_worker=True,
Expand All @@ -188,14 +205,21 @@ def sorted(processes: List[T], *, key: SortKey, reverse: bool = False) -> List[T

>>> processes = sorted(processes, key=SortKey.cpu, reverse=True)
>>> [p.pid for p in processes]
['6228', '6239']
['6228', '6239', '6240']
>>> processes = sorted(processes, key=SortKey.mem)
>>> [p.pid for p in processes]
['6239', '6228']
['6240', '6239', '6228']

When using the 'duration' sort key, processes are also sorted by ascending PID:
>>> processes = sorted(processes, key=SortKey.duration, reverse=True)
>>> [p.pid for p in processes]
['6239', '6228']
['6239', '6240', '6228']
"""

# If we filter by duration, we also need to filter by ascending pid
if key == SortKey.duration:
processes = builtins.sorted(processes, key=lambda p: p.pid, reverse=False)

return builtins.sorted(
processes,
key=lambda p: getattr(p, key.name) or 0, # TODO: avoid getattr()
Expand Down