How does XHProf work with Dev Desktop in Mac OS X?
XHProf is a function-level, hierarchical profiler for PHP. It has a simple HTML-based user interface. It was developed originally by Facebook and was open sourced in 2009. The difficult part of getting XHProf working on Acquia Dev Desktop has been done for you: the PHP extension (that is, the raw data collection component implemented in C) has been compiled for versions of PHP supplied with Acquia Dev Desktop that support XHProf (5.3, 5.4, 5.5, 5.6). PHP 7 does not support XHProf.
Setting up xhprof
All you need to do to enable the XHProf extension on a Mac is to make a very simple change to the relevant
php.ini file. The Acquia Dev Desktop Control Panel interface shows you exactly where these are located on your computer and provides a quick way of editing them. Go to Settings > Config to see the location of your
php.ini files, along with an Edit link. Alternatively, you can edit them directly with another text editor that you prefer.
php.ini file, you should see a line for the XHProf extension, but this is commented out by default, like so:
To enable the extension, remove the semi-colon from the beginning of this line. It's also a good idea to explicitly set an output directory for XHProf. This is where the extension stores temporary files when it collects data. The lines in your
php.ini will look similar to the following:
This is the default directory for XHProf to use and will need to be created if it doesn't already exist on your computer. You also need to ensure that the webserver has permission to write to this directory. In the case of Acquia Dev Desktop, this means that your user needs to have write permissions in that directory. So you could create and set the permissions like this:
cd /var/tmp/ sudo mkdir xhprof sudo chown $(whoami) xhprof
In the command-line entries shown here,
$(whoami) returns the UNIX user name.
After making changes to
php.ini, you must restart the webserver. The simplest way of doing this is to Stop and then Start the whole stack using the Acquia Dev Desktop Control Panel. You can then check the PHP info to make sure that XHProf shows up under the xhprof heading. The Config screen in Acquia Dev Desktop also provides an easy link to this.
You can enable the XHProf PHP extension under multiple different PHP versions at the same time (each has its own
php.ini configuration file and version of the extension itself). If you have any problems (for example, if XHProf doesn't show up in your PHP info), check the Apache error logs for clues as to what has gone wrong.
Seeing xhprof data
XHProf's PHP extension collects data about what PHP is doing, but does not provide a user interface. The way you actually interact with the XHProf interface will depend on the version of Drupal you're using.
For Drupal 7, you can use use the Devel module's XHProf integration. For Drupal 7, there is an XHProf module, which provides its own XHProf interface. There's not much to configure for the XHProf module; simply enable profiling and choose whether to include admin pages.
After this is done, you should find the actual XHProf output under Reports.