Skip to content

Instantly share code, notes, and snippets.

@juliantaylor
Created September 22, 2015 23:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliantaylor/c09ead69e711ab47858e to your computer and use it in GitHub Desktop.
Save juliantaylor/c09ead69e711ab47858e to your computer and use it in GitHub Desktop.
python gil stap
# stap -g pygil.stp <pid> <minlocktime-in-mus>
global init = 0
global gpid = $1
global lock_start = 0
global mintime = $2
# may need to be libpython on some systems
probe process("/usr/bin/python-dbg").function("PyThread_acquire_lock")
{
if (init == 0) {
printf("init %d %d\n", gpid, mintime)
lock_start = gettimeofday_us()
init = 1
}
if (pid() == gpid) {
lock_start = gettimeofday_us()
}
}
probe process("/usr/bin/python-dbg").function("PyThread_release_lock")
{
if (pid() == gpid) {
if (init && gettimeofday_us() - lock_start > mintime) {
printf("unlock %d\n", gettimeofday_us() - lock_start);
raise(%{ SIGSTOP %}); # attach gdb, py-list
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment