Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
setup xhprof on ubuntu 12.10 / apache

Install XHProf

Pear

sudo pear upgrade PEAR
sudo pecl install xhprof-0.9.2

From source

Need the patch to avoid https://bugs.php.net/bug.php?id=61674

wget http://pecl.php.net/get/xhprof-0.9.2.tgz
tar -xzf xhprof-0.9.2.tgz && cd xhprof-0.9.2
wget https://github.com/facebook/xhprof/commit/a6bae51236.diff
patch -p1 < a6bae51236.diff
cd extension

phpize
./configure
make

sudo cp modules/xhprof.so $(php-config --extension-dir)/
echo "extension=xhprof.so" | sudo tee -a /etc/php5/conf.d/20-xhprof.ini
# Create an xhprof virtualhost now
wget https://raw.github.com/msonnabaum/xhprof-single-file/master/index.php -O /your/virtualhost/docroot/xhprof.php
sudo /etc/init.d/apache2 reload
php -i | grep xhprof

wget https://raw.github.com/msonnabaum/xhprof-single-file/master/index.php -O /your/project/path/xhprof.php

Drupal

Add the following to Drupal's index.php:

<?php
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
register_shutdown_function(function() {
  $xhprof_data = xhprof_disable();
  $namespace = 'sitename';
  $filename = '/tmp/' . uniqid() . '.' . $namespace . '.xhprof';
  file_put_contents($filename, serialize($xhprof_data));
});

Load the site, and you should now see some .xhprof files in /tmp. You can check the output using the script you installed at the xhprof virtualhost's index.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.