[Tutor] trace / profile every function with inputs

rakesh sharma rakeshsharma14 at hotmail.com
Tue Feb 11 02:21:49 CET 2014


Hi,
Have tried inspect module in python.See this code
def foo():	print inspect.stack()[0][3]
	>>> foo()foo>>> 
this shall meet your purpose I believe
thanks,rakesh
> From: r.cziva.1 at research.gla.ac.uk
> To: tutor at python.org
> Date: Fri, 7 Feb 2014 16:07:58 +0000
> Subject: [Tutor] trace / profile every function with inputs
> 
> 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
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140211/7027ab8f/attachment.html>


More information about the Tutor mailing list