Cachegrind-less profiling with Xdebug 2.0

      6 Comments on Cachegrind-less profiling with Xdebug 2.0

If you are not familiar with Xdebug it is an extension that allows you to profile your application for various things like performance and memory usage. One of its more usefull features is the ability to profile your application to find out what method are taking the longest so you can clean up those bottlenecks in your application.

This was pretty simple in Xdebug 1.x as it provided a method call for outputting all the profile information in a nice table format up to that point. Since Xdebug 2.x this option has given way to cachegrind files.

Cachegrind provides a nice graphical display of your profiling information but I run Mac OSX and due to my local development environment Fink and Ports are out of the question as they tend to step all over my local development environment so getting KCacheGrind up and running was not going to be fun so much fun I have not even bothered to try and tackle it yet.

What I needed was a way to replicate the old Xdebug 1.x functionality. From this the idea of “PHPGrind” was born. Right now its just a proof of concept but I am hoping with some more understanding of the cachegrind format I can make it into something as useful as the graphical versions.

Xdebug outputs cachegrind files into your temp directory based on the pid of the running process so what we can do is grab the pid of the current page and pass it on to a pop-up window that loads PHPGrind.

PHPGrind then does a very rough parsing of the cachegrind file and compiles and array of data, sorts it by time per function and provides a nice tabled format like what you may of been used to with Xdebug 1.x

You can see both a demo and access the source code at

The code currently available was thrown together over lunch and regex is not my strong point so its not the prettiest nor the fastest solution for parsing cachegrind files but it works.