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.cziv...@research.gla.ac.uk
> To: tutor@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@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
                                          
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to