I'm trying to trace the flow of calls and code in a complex Python application(OpenERP). To make it more complicated, OpenERP have their own inheritance system that lives in parallel with normal Python inheritance.
What I would like to do is to have a full listing of code executed, with module / function names.
I have tried the Eclipse debugger, and I understand pdb works in much the same way, but the stepping through process takes too long.
I have also tried launching the application with trace, but am getting too much unnecessary tracing prior to the point where I want to trace. I did try excluding modules and directories but it didn't help much.
python -m trace -t --ignore-dir=/home/sean/unifield/utp729b/unifield-server --ignore-dir=/home/sean/unifield/utp729b/unifield-web --ignore-module=SocketServer,socket,threading,tiny_socket,__init__,trace,netsvc,posixpath,zipfile,config,genericpath,orm openerp-server.py --db_host=localhost --db_port=5432 --db_user=openerp --db_password=xxxx --addons-path=/home/sean/unifield/utp729b/unifield-addons,/home/sean/unifield/utp729b/sync_module_prod,/home/sean/unifield/utp729b/unifield-wm > /home/sean/trace.log
What I would like to do is to set a breakpoint in the code, but instead of then stepping through the code, start the logging to a file then.
I also tried using a decorator, with examples http://eli.thegreenplace.net/2012/08/22/easy-tracing-of-nested-function-calls-in-python/ and http://code.activestate.com/recipes/577551/, but they did not cover my needs.
EDIT
I have now tried using the Python trace module, by adding this line to the VM Arguements box in Eclipse: -m trace -t --trace
This starts producing what I am looking for, a line by line trace, but then when OpenERP fully starts up is stops working. See (lengthy) extract from console output below.
pydevd_tracing.py(46): if TracingFunctionHolder._warn:
pydevd_tracing.py(62): TracingFunctionHolder._original_tracing(tracing_func)
pydevd_tracing.py(69): TracingFunctionHolder._warn = True
pydevd_tracing.py(71): TracingFunctionHolder._lock.release()
pydevd.py(1075): try:
pydevd.py(1077): threading.settrace(self.trace_dispatch) # for all future threads
pydevd.py(1081): try:
pydevd.py(1082): thread.start_new_thread = pydev_start_new_thread
pydevd.py(1083): thread.start_new = pydev_start_new_thread
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1088): time.sleep(0.1) # busy wait until we receive run command
pydevd.py(1087): while not self.readyToRun:
pydevd.py(1090): PyDBCommandThread(debugger).start()
pydevd.py(1092): pydev_imports.execfile(file, globals, locals) #execute the script
[2014-01-05 18:33:51,992][?] INFO:server:OpenERP version - 6.0.3
[2014-01-05 18:33:51,993][?] INFO:server:addons_path - /home/sean/unifield/utp729b/unifield-addons,/home/sean/unifield/utp729b/sync_module_prod,/home/sean/unifield/utp729b/unifield-wm
[2014-01-05 18:33:51,993][?] INFO:server:database hostname - localhost
[2014-01-05 18:33:51,993][?] INFO:server:database port - 5432
[2014-01-05 18:33:51,994][?] INFO:server:database user - openerp
[2014-01-05 18:33:51,994][?] INFO:server:initialising distributed objects services
[2014-01-05 18:33:52,316][?] INFO:web-services:starting HTTP service at 0.0.0.0 port 8069
[2014-01-05 18:33:52,316][?] INFO:web-services:starting HTTPS service at 0.0.0.0 port 8071
[2014-01-05 18:33:52,317][?] INFO:web-services:Registered XML-RPC over HTTP
[2014-01-05 18:33:52,318][?] INFO:web-services:starting NET-RPC service at 0.0.0.0 port 8070
[2014-01-05 18:33:52,318][?] INFO:server:Starting 3 services
[2014-01-05 18:33:52,319][?] INFO:server:OpenERP server is running, waiting for connections...
[2014-01-05 18:34:02,476][utp729b_HQ_01] INFO:init:module base: loading objects
[2014-01-05 18:34:02,478][utp729b_HQ_01] INFO:init:module base: registering objects
[2014-01-05 18:34:03,060][utp729b_HQ_01] INFO:init:module base: loading objects
[2014-01-05 18:34:03,185][utp729b_HQ_01] INFO:init:module msf_button_access_rights: loading objects
[2014-01-05 18:34:03,186][utp729b_HQ_01] INFO:init:module msf_button_access_rights: registering objects
[2014-01-05 18:34:03,203][utp729b_HQ_01] INFO:init:module spreadsheet_xml: loading objects
EDIT 2
See a more robust solution, but one which runs always and not a point in time, here: Finding full pathname in a Python trace
If you want to just trace the exact calls that are being made, just use
--log-level
. using--log-level=debug_rpc
will give you the exact name and parameters of the functions that are being executed.I do not know how to set up tracing like you want to do; all I can offer is that most of the interesting calls relating to the storing and retrieving of data goes through
osv.py
,fields.py
, andorm.py
in the.../openerp/osv/
directory.