Using SugarCRM XHProf Viewer to profile Sugar server-side performance

Post originally written by Vadzim Ramanenka.

Sugar Performance Engineer Vadzim Ramanenka shares some tips for profiling Sugar code using our newly launched SugarCRM XHProf Viewer open source project.

Profiling Sugar softly

Whenever you encounter that something is not working as fast as you would like, you need a way to look “under the hood” and understand what exactly is slowing things down. Sugar 7.7.0 added a built-in capability to collect detailed performance profiling data and store it in files. Recently, we released an open source SugarCRM XHProf Viewer project which can be used to visualize performance bottlenecks.

Read on to learn how to configure both Sugar and the Viewer in a few simple steps.


You need to have a copy of Sugar on-site installed where you have file system access such as on your local machine. We rely on the xhprof php extension so you are required to have it installed on the version of PHP configured with Sugar as well.

Enabling XHProf logging in Sugar

First of all we have to create a directory which Sugar will use to store profiling information. I use /tmp/profile_files/sugar in this example but you can choose any location. Just make sure the target directory exists and that Apache has write permissions to it.After that, there are a few lines of configuration should be added to the config_override.php file to ask Sugar to start collecting profiling data. This is an example of a bare minimum configuration:
$sugar_config['xhprof_config']['enable'] = true;$sugar_config['xhprof_config']['log_to'] = '/tmp/profile_files/sugar';
By default, Sugar profiles only 10% (1 in 10) of the incoming requests. If you want to profile all requests then add this line to config_override.php:
$sugar_config['xhprof_config']['sample_rate'] = 1;
For additional configuration options please refer to the xhprof_config setting documentation in the Sugar Developer Guide.Now open Sugar and start clicking around. If you’ve done everything right files should start appearing in /tmp/profile_files/sugar.

Configuring SugarCRM XHProf Viewer

Download the latest release of the Viewer and extract it somewhere under your server's web root directory.By default, the Viewer looks for profiling data under /tmp/profile_files and subdirectories. If you want to change this then create a config_override.php file in the Viewer's root directory with the following content:
<?php$config['profile_files_dir'] = '<PROFILE FILES LOCATION>';
And replace <PROFILE FILES LOCATION>  with the directory that you specified in Sugar’s config_override.php.This is pretty much it. Have fun!

SugarCRM XHProf Viewer Screenshots

There are three different dimensions of information collected for every single request. Check out the screenshots below.