I usually use oprofile. Typically, I write a small piece of python to call the
extension multiple times so it runs the critical code for about a minute (10
seconds will probably do, too), then the extension code is the only thing
showing up near the top of the oprofile stats.
It is important that nothing else is running on the machine when you run
your extension for profiling, since oprofile is a kernel-level tool and sees
the entire system.
Last time I looked at the docs (ca. 5 years ago...) you had to be root for
"opcontrol --start". I'm not sure if that's still a requirement.
The commands I use are:

opcontrol --reset; opcontrol --start # root
# run as usual (not root)
opcontrol --shutdown # root
opreport -l > report
opannotate --source > annotated
grep '^[ 0-9][ 0-9][ 0-9][ 0-9][ 0-9][0-9] ' annotated | sort -n

You may need "yum install oprofile" or similar.



________________________________
From: Alexey Akimov <alexey.akimo...@gmail.com>
To: Development of Python/C++ integration <cplusplus-sig@python.org>
Sent: Sat, February 27, 2010 7:52:17 PM
Subject: [C++-sig] profiling python extension

Dear all,

Does anyone know how one may profile a python extention? There is a bunch of 
literature on profiling of pure binaries (programs and even libraries), pure 
python code, etc. However the profiling of a python module from python script 
seems a tricky procedure. 
What I tried is to pass variant=profile to bjam. Everything works fine and I 
get .so library corresponding to my module (placed into /profile sub-directory 
of this particular build). When I execute the python script invoking my 
module's functions (performance of those functions is most interesting for me) 
there is no any output generated (something similar to gmon.out). So that is 
basically my question - how can I retrieve the profiling information about my 
extension? Of course I can compile a normal executable using the functions in 
the module and then use a standard approach (and of course gprof), but I hope 
that there should be more straightforward and easy way to do this (hopefully by 
passing some arguments to bjam).
Thanks in advance.

Alexey
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to