Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
devops
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
devops
Commits
ac28b90c
Commit
ac28b90c
authored
Sep 07, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
futex-pylat: print py-level tracebacks that trigger long-blocked futex syscall
parent
5be1d464
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
futex-pylat
futex-pylat
+83
-0
No files found.
futex-pylat
0 → 100755
View file @
ac28b90c
#!/usr/bin/env python
"""print py-level tracebacks that trigger long-blocked futex syscall
usage: futex-pylat <tid> <too_long_ms>
FIXME traces only one thread instead of whole process.
"""
from
__future__
import
print_function
from
ptrace.debugger
import
PtraceDebugger
,
ProcessSignal
from
ptrace.func_call
import
FunctionCallOptions
import
os
,
sys
from
time
import
time
def
main
():
dbg
=
PtraceDebugger
()
try
:
_main
(
dbg
)
finally
:
dbg
.
quit
()
def
_main
(
dbg
):
tid
=
int
(
sys
.
argv
[
1
])
too_long_ms
=
float
(
sys
.
argv
[
2
])
dbg
.
traceFork
()
# forks
dbg
.
traceExec
()
dbg
.
traceClone
()
# threads
# NOTE we trace only one thread
# TODO -> attach all threads from /proc/<pid>/tasks
print
(
"Attaching to tid%d"
%
tid
)
proc
=
dbg
.
addProcess
(
tid
,
is_attached
=
False
)
syscall_options
=
FunctionCallOptions
()
# setup to break at first syscall
proc
.
syscall
()
def
_
(
syscall
):
return
(
not
syscall
.
name
.
startswith
(
"futex"
))
proc
.
syscall_state
.
ignore_callback
=
_
sys_start
=
0.
while
1
:
if
not
dbg
:
break
# proc exited
# wait for next syscall event (enter/exit)
try
:
event
=
dbg
.
waitSyscall
()
except
ProcessSignal
as
event
:
event
.
display
()
event
.
process
.
syscall
(
event
.
signum
)
continue
assert
event
.
process
is
proc
state
=
proc
.
syscall_state
syscall
=
state
.
event
(
syscall_options
)
if
syscall
:
if
state
.
syscall
is
not
None
:
sys_start
=
time
()
#print("enter %s" % syscall)
else
:
sys_end
=
time
()
lat
=
sys_end
-
sys_start
if
lat
>
too_long_ms
*
1E-3
:
#print("exit %s" % syscall)
print
(
">>> %s
\
t
lat: %.3fms"
%
(
syscall
.
name
,
lat
*
1E3
))
# a syscall was detected to block > too_long
# -> dump state of python threads
#
# --nonblocking because are we already holding the thread in stopped state.
os
.
system
(
"py-spy dump --nonblocking --pid %d"
%
tid
)
# break at next syscall
proc
.
syscall
()
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment