2013-12-20 75 views
4

我試圖在複雜的Python應用程序(OpenERP)中跟蹤調用流和代碼。爲了使它更復雜,OpenERP擁有自己的繼承系統,它與普通的Python繼承並行。跟蹤代碼中的所有語句

我想要做的是使用模塊/函數名稱來執行代碼的完整列表。

我已經嘗試了Eclipse調試器,並且我理解pdb的工作方式非常相似,但是逐步執行過程需要很長時間。

我也嘗試用跟蹤啓動應用程序,但在我想跟蹤的點之前獲得太多不必要的跟蹤。我曾嘗試排除模塊和目錄,但沒有多大幫助。

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 

我想這樣做的是在代碼中設置斷點,但不是那麼單步調試代碼,開始記錄到文件,然後。

我也試過使用裝飾器,例如http://eli.thegreenplace.net/2012/08/22/easy-tracing-of-nested-function-calls-in-python/http://code.activestate.com/recipes/577551/,但它們沒有覆蓋我的需求。

編輯

我現在已經使用Python跟蹤模塊嘗試,加入這行來在Eclipse中VM Arguements箱:-m跟蹤-t --trace

這將啓動生產我正在尋找的是逐行跟蹤,但是當OpenERP完全啓動時停止工作。請參閱下面的控制檯輸出(冗長)提取。

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

看到一個更強大的解決方案,而是一個一直運行,而不是一個時間點,在這裏:Finding full pathname in a Python trace

回答

1

我不知道如何設置跟蹤像你想要做的;我所能提供的是,大部分與數據存儲和檢索相關的有趣調用都通過.../openerp/osv/目錄中的osv.py,fields.pyorm.py

1

如果您只想跟蹤正在進行的確切呼叫,請使用--log-level。使用--log-level=debug_rpc將爲您提供正在執行的函數的確切名稱和參數。