Debugging and Profiling Open ERP
I've found the debug command by accident, but after reading all the other methods in the tools module, it turned out to be a really useful module. A short description of some debugging related commands follows.
- debug
- profile
- logged
The debug command
This one is even properly documented.
>>> from tools.misc import debug >>> pp debug.__doc__
Here follows its docstring:
This method allow you to debug your code without print Example:
>>> def func_foo(bar) ... baz = bar ... debug(baz) ... qnx = (baz, bar) ... debug(qnx) ... >>> func_foo(42)
This will output on the logger:
[Wed Dec 25 00:00:00 2008] DEBUG:func_foo:baz = 42 [Wed Dec 25 00:00:00 2008] DEBUG:func_foo:qnx = (42, 42)
To view the DEBUG lines in the logger you must start the server with the option --log-level=debug
The logged command
This one is even cooled than debug is! It prints data related to a function call. The arguments, the return value, and the time spent in the function. I've found it especially useful to find out the order of calls before a given method got called.
>>> from tools.misc import logged
The logged command is a decorator, so use it as such:
>>> @logged >>> def myfunc(arg): ... print arg
This one requires --log-level=debug too.
The profile command
The profile command uses Python's cProfiler to create a profile data file. This is a class decorator, and you should pass the output filename at init.
>>> from tools.misc import logged
>>> @profile('output.data')
>>> def myfunc(arg):
... print arg
KUDOS for these nice functions!
blog comments powered by Disqus