[Tutor] trace / profile every function with inputs

Richard Cziva r.cziva.1 at research.gla.ac.uk
Fri Feb 7 17:07:58 CET 2014


Hi All,

I am struggling with a "simple" problem: I would like to print out every function that is being executed while my Python program is running. I can not modify the Python programs that I would like to profile.

Let me give an example. A program contains a function and a call like this:

def foo(x):
  y = math.cos(x)
  time.sleep(y+1)
  return x * 50

print foo(100)

I would like to retrieve an execution trace that shows me each function called (with the value or hash of the function arguments). According to the example, I am looking for a way to extract something similar:

foo(100)
math.cos(100)
time.sleep(0.87)

Things I have tried with only partial success:
- trace: couldn't get the function names in some cases
- profile / cProfile: no information about the arguments

Could you suggest me a way of doing this?

Thanks,
Richard


More information about the Tutor mailing list