Profiling a Callback Function

N

Nikolaus Rath

Hello,

I am trying to profile a Python program that primarily calls a C
extension. From within the C extension, a callback Python function is
then called concurrently in several threads.

When I tried to profile this application with

import c_extension
def callback_fn(args):
# Do all sorts of complicated, time consuming stuff
pass

def main():
c_extension.call_me_back(callback_fn, some_random_args)

cProfile.run('main', 'profile.dat')

I only got results for main(), but no information at all about
callback_fn.


What is the proper way to profile such an application?


I already thought about this:

import c_extension

def callback_fn(args):
# Do all sorts of complicated, time consuming stuff
pass

def callback_wrapper(args):
def doit():
callback_fn(args)

cProfile.run('doit', 'profile.dat')

c_extension.call_me_back(callback_wrapper, some_random_args)


but that probably overwrites the profiling information whenever
callback_wrapper is called, instead of accumulating them over several
calls (with different arguments).


Best,


-Nikolaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top