Profiling Odoo code
Graph a method
Odoo embeds a profiler of code. This embedded profiler output can be used to generate a graph of calls triggered by the method, number of queries, percentage of time taken in the method itself as well as the time that the method took and its sub-called methods.
This produces a file called /temp/prof.profile
A tool called gprof2dot will produce a graph with this result:
A tool called xdot will display the resulting graph:
Log a method
Another profiler can be used to log statistics on a method:
The statistics will be displayed into the logs once the method to be analysed is completely reviewed.
Sending the SIGQUIT signal to an Odoo process (only available on POSIX) makes this process output the current stack trace to log, with info level. When an odoo process seems stuck, sending this signal to the process permit to know what the process is doing, and letting the process continue his job.
Tracing code execution
Instead of sending the SIGQUIT signal to an Odoo process often enough, to check where the processes are performing worse than expected, we can use the py-spy tool to do it for us.
As py-spy is installed, we now record the executed code lines. This tool will record, multiple times a second, the stacktrace of the process.
where <PID> is the process ID of the odoo process you want to graph.
To open profile.json you can use online tool speedscope.app.
To open profile.svg you should use browser, because other viewer may not support interactive part.