Last updated March 19, 2014. Created by erikwebb on October 19, 2010.
Edited by Ron Williams, kbrinner, Elijah Lynn, siliconmeadow. Log in to edit this page.

xhprof is a utility for profiling PHP. Unlike Xdebug profiling, it profiles both CPU cycles and memory usage (Xdebug 2.0.0RC4 and later only provides memory usage information in function traces).

See Installing XHProf for MAMP on Mac OS 10.6 (Snow Leopard) if you are using MAMP.

  1. Download the latest xhprof release
    1. By following command:
      1. sudo pecl install xhprof-beta (if that doesn't work try just xhprof)
    2. Or Manually
      1. Download from PECL - pecl d xhprof-0.9.4. Confirm this is the latest version of xhprof before downloading
      2. Extract the xhprof PECL package - tar xzf xhprof-0.9.4.tgz
      3. Compile the xhprof package.
        cd xhprof-0.9.4/extension
        phpize
        ./configure
        make
        sudo make install
        Here's the trick if you're running Mac OS X Snow Leopard in 64-bit, you must add the correct architecture flags to the compilation process -
        CFLAGS="-arch x86_64 -arch i386"
        ./configure
      4. If the Compilation step 3 above doesn't work for you, download xhprof.so from https://github.com/cam8001/php-xhprof-mamp
      5. Copy xhprof.so to /Applications/MAMP/bin/php/php5.x.x/lib/php/extensions/no-debug-non-zts-200xxxxx/ (replacing x with your PHP version and date) - make sure you're doing this to the correct version of php - check which php to confirm
  2. Now add the newly created xhprof extension to your php.ini file using this configuration -
    [xhprof]
    extension=xhprof.so
    xhprof.output_dir=/private/tmp
  3. Restart Apache and double-check that the xhprof extension is properly loading -
    apachectl restart
    php -m | grep xhprof
  4. Devel module (as of 6.x-1.23 or 7.x-*) now supports integrating with XHprof and can be configured on the Devel configuration page. A separate XHProf module now exists to provide more native integration with Drupal and will replace any Devel module functionality.
  5. To use the Drupal XHProf module, download either by clicking on the download link on the project page or running drush dl XHProf (note that drush dl xhprof will not work - it needs to be capitalized)
  6. Enable XHProf drush en xhprof -y
  7. Check the module configuration at admin/config/development/xhprof - if you have successfully enabled xhprof you should see so here.
  8. Once you have the xhprof extension working and the Drupal xhprof module enabled, you can load a page of your website, the scroll to the bottom of the page, and click on the small XHProf output link in the lower left corner. If you ever want to view a list of all XHProf reports, go to admin/reports/xhprof for a complete list
  9. The Drupal implementation of XHProf lacks the ability to view the 'callgraph' - this is a really useful chart of how the functions all relate to each other and helps to visualize what is going on.
  10. To access the callgraphs, go to http://[xhprof.loc]/xhprof_html/index.php (or whatever you set up for your localhost of XHProf in step x) and click on any of the report numbers. There will be a link near the top that reads 'View Full Callgraph'. If you click on this and you get an error (instead of a nice chart) you probably need to install Graphviz. You can grab the .pkg for the appropriate version for your OS at http://www.graphviz.org/Download_macos.php. Click through the installation and then the graphs should work.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

I had to run phpize before ./configure.

To install the extension in MAMP on Snow Leopard I needed to:

- get the MAMP components (src for all)
- create the include/php folders inside /Applications/MAMP/bin/php5.[x]/
- copy php src into /Applications/MAMP/bin/php5.[x]/include/php
- run configure on the php source before I could phpize to build the extension as detailed here http://forum.mamp.info/viewtopic.php?f=2&t=8109&p=17406&hilit=phpize#p17706

cd /Applications/MAMP/bin/php5.[x]/include/php
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
./configure --with-config-file-path=/Applications/MAMP/bin/php5.[x]/bin/php-config

- then I could run phpize & make :)

Thanks, added phpize to the original post.

Erik Webb
Technical Team Lead, Acquia

The Devel module now integrates with XHProf. You should use it instead of steps 4-6.

Agreed, thanks for the reminder.

Erik Webb
Technical Team Lead, Acquia

To install via pecl

1. Update pear using "sudo pear update pear"
2. Install using "sudo pecl install channel://pecl.php.net/xhprof-0.9.2"

Have fun and check my Drupal Profile: http://drupal.org/user/519

I found this resource very valuable in setting up xhprof with Devel on Ubuntu 13.04.

http://www.pixelite.co.nz/article/profiling-drupal-7-performance-xhprof-...

-----------------------------------------------
The Future is Open!