Skip to content
Snippets Groups Projects
Commit baeb7432 authored by William Henrotin's avatar William Henrotin
Browse files

[IMP] doc: add profiler example

The built-in Odoo profiler can be used directly into the logs. This
information was not given in the documentation. This commit add it. An
example on how to use is shown as well as the produced result.
parent 8e515693
No related branches found
No related tags found
No related merge requests found
......@@ -7,16 +7,17 @@ Profiling Odoo code
This tutorial requires :ref:`having installed Odoo <setup/install>`
and :doc:`writing Odoo code <backend>`
Graph a method Up to 10.0
=========================
Graph a method
==============
Odoo embeds a profiler of code. This embeded profiler output can be used to
generate a graph of calls triggered by the method, percentage of time taken in
the method itself as well as time taken in method and it's sub-called methods.
generate a graph of calls triggered by the method, number of queries, percentage
of time taken in the method itself as well as time taken in method and it's
sub-called methods.
.. code:: python
from openerp.tools.misc import profile
from odoo.tools.profiler import profile
[...]
@profile('/temp/prof.profile')
@api.multi
......@@ -36,6 +37,44 @@ A tool called *xdot* will display the resulting graph:
xdot /temp/prof.xdot
The profiler can be also used without saving data in a file.
.. code:: python
@profile
@api.model
def mymethod(...):
The statistics will be displayed into the logs once the method to be analysed is
completely reviewed.
.. code:: bash
2018-03-28 06:18:23,196 22878 INFO openerp odoo.tools.profiler:
calls queries ms
project.task ------------------------ /home/odoo/src/odoo/addons/project/models/project.py, 638
1 0 0.02 @profile
@api.model
def create(self, vals):
# context: no_log, because subtype already handle this
1 0 0.01 context = dict(self.env.context, mail_create_nolog=True)
# for default stage
1 0 0.01 if vals.get('project_id') and not context.get('default_project_id'):
context['default_project_id'] = vals.get('project_id')
# user_id change: update date_assign
1 0 0.01 if vals.get('user_id'):
vals['date_assign'] = fields.Datetime.now()
# Stage change: Update date_end if folded stage
1 0 0.0 if vals.get('stage_id'):
vals.update(self.update_date_end(vals['stage_id']))
1 108 631.8 task = super(Task, self.with_context(context)).create(vals)
1 0 0.01 return task
Total:
1 108 631.85
Dump stack
==========
......@@ -56,6 +95,7 @@ Install pyflame and flamegraph
.. code:: bash
# These instructions are given for Debian/Ubuntu distributions
sudo apt install autoconf automake autotools-dev g++ pkg-config python-dev python3-dev libtool make
git clone https://github.com/uber/pyflame.git
git clone https://github.com/brendangregg/FlameGraph.git
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment