There's a new version of XHGui (well, a few months old) and it's fabulous! It's got a few new dependencies though so I thought I'd write down how I set up my version, in case it's helpful to anyone else (and so I feel like a pro next time I have to do this!). If you're not familiar with XHGui it's a fabulously easy and friendly way to profile your application; to understand which method calls in a page take the time and how many times they are made, so you can improve the performance of your application. All these instructions are for my 32-bit Ubuntu 12.10 system, hopefully they will work for you or you'll be able to adapt them as appropriate.
XHGui needs version numbers or fluffy animal names, because this is a really major release and quite different to what went before in both technology and in looks. In particular, it now uses MongoDB. If you're not familiar with MongoDB, it's a super-friendly NoSQL database that makes a really handy backend for this kind of unstructured data - because every run of every page will look different. Therefore you will need:
- MongoDB itself
- The pecl extension for mongo
- The xhprof pecl extension (read on if you're using PHP 5.4, there's a gotcha)
To get MongoDB, go to http://www.mongodb.org/ and find the instructions for your system. I use their apt repositories since they update quicker than Ubuntu's (for obvious reasons) and Mongo is a pretty young product so it updates a lot.
The pecl extension for Mongo should be easy enough:
pecl install mongo
The XHProf extension should be that easy, but isn't. There's an
xhprof-beta package available, but I found that this did not work when installed on my system. This turns out to be because it's not ready for PHP 5.4, so follow the instructions at http://michaelsanford.com/compiling-xhprof-for-php-5-4/ for now. The change is in the github project, so I assume facebook will roll a new release of xhprof at some point. This was the most difficult bit of setup for me so if you get this far, you're almost there!
You'll find the main project here: https://github.com/preinheimer/xhgui and I forked the repo onto my github account and cloned that, you could download the code direct from their repo, it doesn't matter. The project README is great and will show you how to set up, making the cache directory writeable and adding a line to enable profiling to your virtual host configuration (don't forget to restart Apache).
At this point, you're logging data when you make requests to whichever virtual host you added XHGui to, but how do you see the results? Set up another virtualhost (or if you're lazy like me, start the PHP 5.4 webserver instead) for the directory
/web/webroot and then request it. You will see a list of all the requests you have made, with the option to filter these in various ways. You can also drill into the detail for an individual request:
From this point you can start to drill in and look at all the various statistics collected by XHGui, identify pain points in your application, and compare two runs to measure how much you have improved things when you optimise.