After doing a fresh Ubuntu 10.10 install I spent some time re-installing some much relied on dev tools, 2 of which are XDebug and KCacheGrind. Their purpose is to add enhanced debugging and profiling capabilities to any dev environment. If you’re serious about seeing what your applications are doing at a lower level, or about performance, then leveraging these 2 tools are a must. They’re not very hard to install and once you get used to them, they’ll both turn into tools you continue to rely on.
Here’s how to install and configure them in an Ubuntu 10.10 environment. While some of these steps are Ubuntu specific, it should be easy to do the same in any other distro since there aren’t many steps involved (overall), and some of them aren’t specific to Ubuntu, but rather, PHP and XDebug.
First, install XDebug:
sudo apt-get install php5-xdebug
… and configure PHP to recognize XDebug and it’s profiling capabilities. To do so, you’ll need to find where xdebug.so was installed:
dpkg -L php5-xdebug | grep xdebug.so
Once you have the full path to xdebug.so, add the following lines to your php.ini file to enable XDebug and have it output cachegrind files to a specified directory:
zend_extension="[path to your xdebug.so file]" xdebug.profiler_enable=1 xdebug.profiler_output_dir="[directory to write cachegrind output files]"
Now just restart Apache:
sudo service apache2 restart
To confirm correct configuration, hit a phpinfo() page and check for 2 things:
- that you have a section titled XDebug
- that you have a cachegrind.out file in the xdebug.profiler_output_dir directory you specified above
If those 2 are confirmed then the install is working as expected.
Next up is to install KCacheGrind. Just a word of warning that this will take a few minutes since it’s a pretty big install:
sudo apt-get install kcachegrind
Once installed, you should be able to open KCacheGrind via Applications > Programming > KCacheGrind. Once running, choose File > Open, and browse to any of the cachegrind.out files to inspect their profile.