Tuesday, 5 September 2017

How to use profile in Odoo ?

How to use profile in Odoo ?

If you want to know number of queries, calls and time of each method you can use @profile in Odoo.

You can simply use profile by importing profile

from odoo.tools.profiler import profile

after importing you can add it in any method. Suppose If I want to know the executing time of partner creation, I can simply write the following code in file,

    def create(self, vals):

Now, restart your server.

Here, I had added @profile on res.partner creation. So When I create contact(res.partner) in Odoo the system logs entries.

calls     queries   ms
res.partner ------------------------- /home/XYZ/workspace/master/odoo/addons/base/res/res_partner.py, 489

1         0         0.02          @api.model
                                  def create(self, vals):
1         0         0.01              if vals.get('website'):
                                          vals['website'] = self._clean_website(vals['website'])
1         0         0.01              if vals.get('parent_id'):
                                          vals['company_name'] = False
1         0         0.02              tools.image_resize_images(vals)
1         20        97.75             partner = super(Partner, self).create(vals)
1         2         5.21              partner._fields_sync(vals)
1         0         0.18              partner._handle_first_contact_creation()
1         0         0.01              return partner

1         22        103.19  

Here, total 103.19 milliseconds time taken to create new partner..

There are more parameter you can pass in profile.

all methods for all odoo models by applying the optional filters.

1. param whitelist: None or list of model names to display in the log        
    ex.  @profile(whitelist=['sale.order', 'ir.model.data'])

2. param files: None or list of filenames to display in the log
    ex. @profile(files=['/home/openerp/odoo/odoo/addons/sale/models/sale.py'])

3. param list blacklist: list model names to remove from the log

4. param int minimum_time: minimum time (ms) to display a method
5. param int minimum_queries: minimum sql queries to display a method


No comments:

Post a Comment