giljoy 0.1: Find which C functions are holding the global interpreter lock (GIL)

Itamar Turner-Trauring itamar at itamarst.org
Tue Jul 20 15:43:04 CEST 2010


Ever wondered which C extension functions ought to be releasing the
global interpreter lock? giljoy might be able to help.

 http://itamarst.org/software/giljoy-0.1.tar.gz


Giljoy helps you find C functions that are holding the GIL; in some
cases they could release the GIL, thus making your program more
concurrent. The program uses sampling, so it finds the functions that
most frequently hold the GIL, and may miss infrequently called
functions.

Theory of operation: a preloaded module sets a C variable indicating
which thread has GIL. A separate program attaches gdb and then inspects
the C variable.


= Supported Platforms =
The program was only tested on Ubuntu 10.4 with Python 2.6; it will
probably only run on modern versions of Linux. Since it involves large
amounts of duct tape and magic pixie dust, it may not work without
some tweaking -- please let me know if you have any problems!


= Requirements =
pygdb 0.2: http://code.google.com/p/pygdb/
Python with debug symbols (e.g. "apt-get install python2.6-dbg" on
Ubuntu).


= Sample Output =
Here you can see a large chunk of the time the GIL is held by a C
function that ought to release the GIL (nogil_sleep, which calls usleep
which calls nanosleep). The rest of the time the GIL is held by internal
Python functions that cannot be changed.

$ ./giljoy example.py
Functions that held GIL, by percentage seen (194 samples):
37%: nanosleep(/lib/libc.so.6)
     < usleep(/lib/libc.so.6)
     < nogil_sleep(nogilexample.c)
     < call_function(../Python/ceval.c)
     < PyEval_EvalFrameEx(../Python/ceval.c)
24%: PyEval_EvalFrameEx(../Python/ceval.c)
 3%: frame_dealloc(../Objects/frameobject.c)
     < fast_function(../Python/ceval.c)
     < call_function(../Python/ceval.c)
     < PyEval_EvalFrameEx(../Python/ceval.c)
... etc. ...



More information about the Python-announce-list mailing list