Skip to content

Commit

Permalink
fsnotify: print time spent waiting for each task
Browse files Browse the repository at this point in the history
This will pretty quickly help identify problematic fsnotify groups.

Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 committed Jul 22, 2024
1 parent d66d9fb commit 22d3c5b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions drgn_tools/fsnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
subsystem.
"""
import argparse
from datetime import timedelta
from typing import Dict
from typing import Iterator
from typing import Optional
from typing import Tuple

from drgn import cast
Expand All @@ -30,6 +32,7 @@
from drgn_tools.dentry import dentry_path_any_mount
from drgn_tools.dentry import sb_first_mount_point
from drgn_tools.task import is_group_leader
from drgn_tools.task import task_lastrun2now
from drgn_tools.util import type_has_member

FSNOTIFY_FLAGS = {
Expand Down Expand Up @@ -196,6 +199,16 @@ def fsnotify_summarize_object(kind: str, obj: Object) -> str:
return "(not implemented)"


def _print_waiter(task: Object, kind: str, pfx: Optional[str]):
if not pfx:
pfx = ""
wait_time = task_lastrun2now(task)
wait_time_fmt = str(timedelta(seconds=wait_time / 1000000000))
print(
f"{pfx}[PID: {task.pid.value_()} COMM: {task.comm.string_().decode()}] WAIT: {kind} DURATION: {wait_time_fmt}"
)


def print_waitqueue(
wq: Object, indent: int = 2, stack_trace: bool = False
) -> None:
Expand Down Expand Up @@ -229,9 +242,7 @@ def print_waitqueue(
if func == "pollwake":
wqueues = cast("struct poll_wqueues *", entry.private)
task = wqueues.polling_task
print(
f"{pfx}[PID: {task.pid.value_()} COMM: {task.comm.string_().decode()} WAIT: select]"
)
_print_waiter(task, "select", pfx)
if stack_trace:
bt(task, indent=indent + 2)
elif func == "ep_poll_callback":
Expand All @@ -255,9 +266,7 @@ def print_waitqueue(
info = slab_object_info(entry.private)
if info and info.slab_cache.name.string_() == b"task_struct":
task = cast("struct task_struct *", entry.private)
print(
f"{pfx}[PID: {task.pid.value_()} COMM: {task.comm.string_().decode()} WAIT: direct]"
)
_print_waiter(task, "direct", pfx)
if stack_trace:
bt(task, indent=indent + 2)

Expand Down

0 comments on commit 22d3c5b

Please sign in to comment.