Odoo Performance Profile for debugging
- Tek Siong, Hock
- May 7
- 3 min read
If you are on Odoo 16 and below, and need a good tool for debugging the performance of your Odoo system, this will be the right content for you.
This is for Ubuntu set up
Install py-spy (pip install py-spy) - more details on (https://github.com/benfred/py-spy)
Install pgbadger - more details on (https://github.com/darold/pgbadger)
pgbadger should be already installed if you have postgresql but to just to make sure you can check by typing pgbadger

Change config (sudo pico /etc/postgresql/12/main/postgresql.conf)
Note: 12 is the version of the postgresql you are using, if you are not sure you can try to ls to check which folder is exists there
logging_collector = on
log_directory = '/var/log/postgresql'
log_file_mode = 0777
log_rotation_age = 0
log_rotation_size = 0
4. Restart psql (sudo service postgresql restart)
5. Start your odoo-bin shell, below here is options you can try to do it
odoo-bin shell
Check where is your odoo-bin with sudo service odoo status

In my case it's in folder /usr/bin, to be noted odoo is executable not a folder. Start by login as odoo user (sudo su odoo -s /bin/bash) then run your shell (odoo shell -c '[odoo_conf]' -d '[db_name]')
Open new terminal and run your py-spy
a. Create a new folder
b. sudo su
c. sudo env "PATH=$PATH" py-spy record --format speedscope --pid [pid]
d. If py-spy is not detected you can try to install it again here (pip install py-spy)
e. After running commands at c points, the terminal will run at standby mode until you exit it (ctrl+c). Once it has been exited it will generate a json file on your selected folder. The json file will be used to do the profiling / performance check.

7. From the json file you had, you can open https://www.speedscope.app/ and import the generated json earlier. Click left heavy on the left top of the screen as example below and you are ready to do profiling.

8. Before doing every new performance check make sure to run (psql -U postgres -c "select pg_rotate_logfile();") or if not working you can try (sudo -u postgres psql -c "select pg_rotate_logfile();") on a new terminal. This command allows rotating log files, so the actual log file wouldn't be too big to open or take too much time to open.

Profiling Phase
Below here will be the detailed steps and information about how you do all the profiling by using https://www.speedscope.app/ and py-spy.
Rotate log file (Point 8)
Open your odoo bin shell (Point 5)
Activate py-spy (Point 6)
Try running some codes in odoo bin shell
For example here i have run my local odoo to confirm 50 SO at the same time.
sale_ids = env['sale.order'].search([("state", "=", "sale"),],limit=500).ids
env['sale.order'].with_context(active_model='sale.order',active_ids=sale_ids)._action_confirm()
After successfully running the command close your shell and py-spy
Depending on where you run your py-spy, a json file will be generated on the selected folders. You can download the json file to your local computer then open https://www.speedscope.app/ and browse or import the json file

After successfully imported, select left heavy on the top left, then it will be displayed like below. This is where you start doing your performance testing. Start from the top you can see the time it takes to actually do all your command. As seen on image below it takes 4.20s to confirm 50 SO, and below it will list all of the functions that have been runned due to your command. From there you can start doing your performance test.

You can try checking its function one by one, which takes too much time. If you hover over it, it can also refer to the line of code location.

Comments