Jump to the content part
DubGeiser Home

Ramblings

Profiling PHP apps on Mac OS X

2010-06-10 22:02:06, by Per

As a reminder to self, but if it helps anybody, great!

Note that these steps where performed on a MacBook5.1, running OS X 10.5.8, Apache 2 with PHP 5.3.

Xdebug

Simplest way to get Xdebug up and running, I think, is to download the Komodo RemotePHP debugging package, extract it somewhere and copy over the relevant xdebug.so file over to something like /usr/libexec/xdebug.so (for me the file was under the 5.3 directory, because I'm on PHP 5.3, duhu).

Next, configure php so that xdebug is used. Add following to php.ini:

[xdebug]
zend_extension=/usr/libexec/xdebug.so
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir=/tmp/
For the exact options, visit the xdebug website. For my main setup I keep de profiling trigger based, so by adding ?XDEBUG_PROFILE=1 to the url I'm testing, the profiling process is triggered. However, if I'm doing a more intense profiling session, I set the xdebug.profiler_enable option to 1, the xdebug.profiler_enable_trigger to 0 and restart apache.

We now have debugging and profiling set up. Xdebug generates cachegrind compatible files, these are text and you can probably read them, but they really need parsing so the data can be presented in a more meaningful way. Now, on Mac, I could use macports to install Kcachegrind, but I really do not want to wait for a couple of hours until all necessary KDE libs have been compiled from source. I could go for Maccallgrind, but not being free (as in both speech and beer), it rubs me the wrong way. And you know what happens if something rubs me the wrong way... hmz, actually you don't and that's probably better ;-)

But, there's Webgrind, which is BSD licensed, yippie!

Webgrind

Installing Webgrind is pretty straightforward: download the zipfile, extract it where it can be served by Apache and basically you're done. If Webgrind cannot find the cachegrind files, double check the xdebug.profiler_output_dir setting in php.ini and the $storageDir and $profilerDir in config.php of the Webgrind install.

Click around in your application under test, then point your browser to the webgrind app, select a cachegrind file, have a ball... or not... at this point, I really don't care ;-)