4

I'm debugging huge web app which was not written by me. That is why i need a way to print every stack call somewhere (stdout or file).

This discussion did not help me. I was thinking about pdb but it requires interaction while i'm looking for automated solution. I have only one function call at the beginning of execution of my app and want to see all other calls it makes.

The behaviour should be somewhat similar to Unix tee command. Python interpreter should execute code and at the same time it should log all function calls from different modules.

Any suggestions?

Edited:

#!/usr/bin/env python
import openerp
if __name__ == "__main__":
    openerp.cli.main()

So from this point i'd like to log all function calls that main() does.

Community
  • 1
  • 1
vwvolodya
  • 2,324
  • 2
  • 20
  • 30
  • Were none of the answers helpful? What about http://stackoverflow.com/a/16200714/3001761? – jonrsharpe Mar 25 '15 at 14:05
  • 1
    print inspect.stack() does not provide any information in my case since i have imported function call in my entry point to the program. So, answering your question no they were not. – vwvolodya Mar 25 '15 at 14:13
  • 1
    Could you provide a [minimal example](http://stackoverflow.com/help/mcve) of the code you're running and want to log? It might help others identify appropriate solutions. – jonrsharpe Mar 25 '15 at 14:17

1 Answers1

3

If you use the python trace module you can debug each funcion or line where that interpreter executes.

The trace moudule can be called from the cli without modifying the program:

  #print each executed line:
  python -m trace --count -C . -t MypyFile.py
  #print only called functions:
  python -m trace --listfuncs MypyFile.py

With -t each line is traced and with -l each function called.

More info : https://docs.python.org/2/library/trace.html