(gs):Install xhprof
- This page was last modified on March 20, 2011, at 15:00.
From (mt) Community Wiki
Contents |
Overview
XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level inclusive and exclusive wall times, memory usage, CPU times and number of calls for each function. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.
See more generic instructions at (gs):Install PECL extensions.
Install xhprof
This is based on http://techportal.ibuildings.com/2009/12/01/profiling-with-xhprof/
For (gs) Grid-Service, the steps are:
- Update the xhprof to latest version.
- Check PECL.
- Possiblly change the version of PHP to the current one on your (gs).
Set your site number variable and current php path for later use:
export SITEID=`pwd | awk -F\/ '{ print $3 }'`
export PHPPATH=`php5 -i | grep "Configure Command" | perl -pe "s/.*'.\/configure'\s*?'--prefix\=(.*?)'.*/\1/"`
If it does not yet exist, make the library folder for Zip:
mkdir -p /home/$SITEID/data/lib/php
As of this writing, the following will download the latest version of xhprof:
wget http://pecl.php.net/get/xhprof
Adjust this line to match the version of xhprof you downloaded in the previous step. Expand the xhprof archive using the following command:
tar zxvf xhprof-0.9.2.tgz
Enter extension directory under you specific version of xhprof. Again, adjust to your specific version:
cd ./xhprof-0.9.2/extension/
$PHPPATH/bin/phpize
./configure --with-php-config=$PHPPATH/bin/php-config
Configuration is now complete. Now you make xhprof:
make cd modules ls
If all went well, there you will see the results of your 'make'--xhprof.so
Just copy xhprof.so to your /home/XXXXX/lib/php directory (making this directory is outlined above in your instructions--if this doesn't exist, just create it)
cp modules/xhprof.so /home/$SITEID/data/lib/php/
Then in php.ini, add these lines by running the following command:
echo -e "\n; xhprof\nextension_dir=/home/$SITEID/data/lib/php\nextension=xhprof.so\n" >> /home/$SITEID/etc/php.ini
Now we just need to tell Apache where to find the module. You can add the line of code to your existing php.ini file, or you can copy the sample file first, then add the line.
If you need to copy the sample php.ini file, run this command (SKIP if you already have one):
cp /home/$SITEID/etc/php.ini.sample /home/$SITEID/etc/php.ini
Add the necessary directives to your php.ini file:
echo -e "\n; Zip for PHP 5\nextension_dir=/home/$SITEID/data/lib/php\nextension=zip.so\n" >> /home/$SITEID/etc/php.ini
Or, alternatively, open the php.ini file for editing:
vi /home/$SITEID/etc/php.ini
vi tip: Press "i" to enter "insert mode" so you can type and copy/paste. Press "Esc" to exit "insert mode" when you are done modifying the file. Type ":wq" to save and quit.
Add the following lines to your php.ini (be sure to replace 00000 with your site number):
extension_dir = /home/#####/data/lib/php/ [xhprof] extension=xhprof.so xhprof.output_dir="/home/#####/data/tmp/xhprof"
You might want to create the directory /home/#####/tmp/xhprof
Further instructions at http://techportal.ibuildings.com/2009/12/01/profiling-with-xhprof/
xhprof can work alone or, for example, with the Drupal development module.