There's more...

One further type of profiler that is available in Odoo generates a graph for the executed method. This profiler is available in the misc package, so you need to import it from there. It will generate a file with statistics data that will generate a graph file. To use this profiler, you need to pass the path of the file path as an argument. When this function is called, it will generate a file on the given location. Take a look at the following example, which generates the make_available.prof file on the desktop:

from odoo.tools.misc import profile
...
@profile('/Users/parth/Desktop/make_available.profile')
def make_available(self):
if self.state != 'lost':
self.write({'state': 'available'})
self.env['res.partner'].create({'name': 'test', 'email': '[email protected]'})
return True

When the make_available method is called, it will generate a file on the desktop. To convert this data into graph data, you will need to install the gprof2dot tool and then execute the given command to generate the graph:

gprof2dot -f pstats -o /Users/parth/Desktop/prof.xdot   /Users/parth/Desktop/make_available.prof

This command will generate the prof.xdot file on the desktop. Then, you can display the graph with xdot with the given command:

xdot /Users/parth/Desktop/prof.xdot

The preceding xdot command will generate the graph shown in the following screenshot:

Here, you can zoom in, check the call stack, and look at details of execution times for the methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset