views:

144

answers:

3

Hello! This is a question about Python native c file _lsprof. How does _lsprof.profile() profiler counts total time spent on a function f in a multi-threaded program if the execution of f is interrupted by another thread?

For example:

def f():
linef1
linef2
linef3

def g():
lineg1
lineg2

And at the execution we have, f and g not being in the same thread:

linef1
linef2
lineg1
linef3
lineg2

Then will the total runtime of f be perceived as the amount of time needed to do:

linef1
linef2
linef3

or will it be the effective latency time:

linef1
linef2
lineg1
linef3

in the results of _lsprof.profile()?

+1  A: 

Quoting from the documentation for setprofile:

The function is thread-specific, but there is no way for the profiler to know about context switches between threads, so it does not make sense to use this in the presence of multiple threads.

Andrew Dalke
A: 

Thank you for this answer! Actually I am running one profiler in each context, so the question make sense. From the tests I made the profiler would measure "linef1 linef2 linef3" in the above example.

A: 

if you want to profile a multithreaded python app please see: http://code.google.com/p/yappi/

sumercip