Skip to content

Commit

Permalink
task: add for_each_task_in_group to iterate process threads
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 committed Jun 21, 2024
1 parent 0c8f6e1 commit 28daf8d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions drgn_tools/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,29 @@ def for_each_task_in_state(prog: drgn.Program, state: str) -> Iterable[Object]:
yield task


def for_each_task_in_group(
task: Object, include_self: bool = False
) -> Iterable[Object]:
"""
Iterate over all tasks in the thread group
Or, in the more common userspace terms, iterate over all threads of a
process.
:param task: a task whose group to iterate over
:param include_self: should ``task`` itself be returned
:returns: an iterable of every thread in the thread group
"""
if include_self:
yield task
for gtask in list_for_each_entry(
"struct task_struct",
task.thread_group.address_of_(),
"thread_group",
):
yield gtask


def count_tasks_in_state(prog: drgn.Program, state: str) -> int:
"""
Count all tasks in a given state.
Expand Down

0 comments on commit 28daf8d

Please sign in to comment.