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.
Prerequisites
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';
$sugar_config['xhprof_config']['sample_rate'] = 1;
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>';
SugarCRM XHProf Viewer Screenshots
There are three different dimensions of information collected for every single request. Check out the screenshots below.