generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 21
lockup: Print tasks which have been on-cpu for too long #109
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) 2024, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ | ||
import argparse | ||
|
||
from drgn import Program | ||
from drgn.helpers.common import escape_ascii_string | ||
from drgn.helpers.linux.cpumask import for_each_online_cpu | ||
from drgn.helpers.linux.percpu import per_cpu | ||
|
||
from drgn_tools.bt import bt | ||
from drgn_tools.corelens import CorelensModule | ||
from drgn_tools.task import task_lastrun2now | ||
from drgn_tools.util import timestamp_str | ||
|
||
|
||
def scan_lockup( | ||
prog: Program, min_run_time_seconds: int = 1, skip_swapper: bool = True | ||
) -> None: | ||
""" | ||
Scan potential lockups on cpus. | ||
|
||
:param prog: drgn program | ||
:param min_run_time_seconds: int | ||
:param skip_swapper: bool | ||
""" | ||
nr_processes = 0 | ||
for cpus in for_each_online_cpu(prog): | ||
runqueue = per_cpu(prog["runqueues"], cpus) | ||
curr_task_addr = runqueue.curr.value_() | ||
curr_task = runqueue.curr[0] | ||
comm = escape_ascii_string(curr_task.comm.string_()) | ||
pid = curr_task.pid.value_() | ||
run_time = task_lastrun2now(curr_task) | ||
prio = curr_task.prio.value_() | ||
if run_time < min_run_time_seconds * 1e9: | ||
continue | ||
if skip_swapper and comm == f"swapper/{cpus}": | ||
continue | ||
print(f"CPU {cpus} RUNQUEUE: {runqueue.address_of_().value_():x}") | ||
print( | ||
f" PID: {pid:<6d} TASK: {curr_task_addr:x} PRIO: {prio}" | ||
f' COMMAND: "{comm}"', | ||
f" LOCKUP TIME: {timestamp_str(run_time)}", | ||
) | ||
print("\nCalltrace:") | ||
bt(task_or_prog=curr_task.address_of_()) | ||
print() | ||
nr_processes += 1 | ||
|
||
print( | ||
f"We found {nr_processes} processes running more than {min_run_time_seconds} seconds." | ||
) | ||
|
||
|
||
class LockUp(CorelensModule): | ||
"""Print tasks which have been on-cpu for too long""" | ||
|
||
name = "lockup" | ||
|
||
def add_args(self, parser: argparse.ArgumentParser) -> None: | ||
parser.add_argument( | ||
"--time", | ||
"-t", | ||
type=float, | ||
default=2, | ||
help="list all the processes that have been running more than <time> seconds", | ||
) | ||
|
||
def run(self, prog: Program, args: argparse.Namespace) -> None: | ||
scan_lockup(prog, args.time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) 2024, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ | ||
from drgn_tools import lockup | ||
|
||
|
||
def test_lockup(prog): | ||
lockup.scan_lockup(prog) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.