Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

How to install XHProf (for Drupal)

Parent Feed: 

XHProf is a hierarchical profiler for PHP. It reports function-level call counts and inclusive and exclusive metrics such as wall (elapsed) time, CPU time and memory usage. A function's profile can be broken down by callers or callees. The raw data collection component is implemented in C as a PHP Zend extension called xhprof. XHProf has a simple HTML based user interface (written in PHP). The browser based UI for viewing profiler results makes it easy to view results or to share results with peers. A callgraph image view is also supported.

Install XHProf

I made sure xhprof-0.9.2 was installed inside the www-directory of the webserver.

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar xvf xhprof-0.9.2.tgz
cd ./xhprof-0.9.2/extension/
phpize
./configure --with-php-config=/usr/local/bin/php-config
sudo make
sudo make install
sudo make test

The php-config file on my machine was located in /usr/local/php-config . Php-config is a file that lists the location of your php-installation. Xhprof needs it for its configuration. If you cannot find the file, you can simply execute ./configure without the parameter.

If phpize is not found, you have to install php5-dev

sudo apt-get install php5-dev

The first time, make install and the make test both failed with me, but xhprof worked nevertheless.

Set up PHP

In php.ini I set up this at the end of the file:

[xhprof]
extension=/path/to/xhprof-0.9.2/extension/modules/xhprof.so
xhprof.output_dir="/var/tmp/xhprof"

Create the directory: /var/tmp/xhprof

xhprof will keep its logfiles in there (files that are needed for the page analysis)

Set up your webserver

Create an entry for /path/to/xhprof-0.9.2/ in your webserver’s configuration (point xhprof.localhost to the /path/to/xhprof-0.9.2/. If local, setup your hostfile correctly (eg: 127.0.0.1  xhprof.localhost)

Restart php and your webserver.

Set up Drupal

When using Drupal, install Devel, and activate the XHProf settings (admin/settings/devel) and point to /path/to/xhprof-0.9.2/ and the path to the website: http://xhprof.localhost/xhprof_html

Devel will create a link at the end of each page that points to XHProf.

Troubleshooting

If you get the error that the function xhprof_enable is unknown, then it’s because XHProf wasn’t properly installed. Try to install it again and make sure you have restarted php.

If the link in Drupal to XHProf doesn’t work, check if the run parameter in the url is supplied. If not, try to install XHProf again and make sure you have restarted php. A typical error for this is: “No XHProf runs specified in the URL.

For errors concerning php-config and phpize, see above.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web