...composed of an indefinite, perhaps infinite number of hexagonal galleries...

© 1994-2017. David Sklar. All rights reserved.

PHP 5, Xdebug 2, and KCachegrind on Windows

I think Xdebug is swell. It provides much helpful insight on what’s happening inside your PHP programs and makes me a speedier bug-finder and bug-fixer.

One of the big changes between Xdebug 1 and Xdebug 2 is in profiling output. In Xdebug 1, profiling output is displayed when you call the xdebug_dump_function_profile() function. You can put it at the bottom of the page you’re profiling, stick it in a popup window with some fancy JavaScript and output buffering footwork. You can also have the debugging output written to a textfile.

Xdebug 2 goes a different route. Instead of generating plain text or HTML profiling reports, it produces a profiling data file in Calltree Profile Format. This is meant to be read by a program like KCacheGrind.

While this makes the profiling data a little less immediate, because you have to fire up a separate application to view it, it also makes the data much more useful. KCacheGrind displays graphical call trees, provides for sorting the profiling data in various ways, and is in general a very flexible and powerful app for this kind of data analysis.

For a while, though, I was out of luck, since KCacheGrind requires KDE, which I assumed only runs on Linux. However, once I found the KDE on Cygwin project, getting KCacheGrind up and running on Windows was a snap.

I just followed the instructions and everything installed in a few minutes (I already had Cygwin installed). KCacheGrind is in the kdesdk package. One thing to watch out for: The KDE/Cygwin installation instructions tell you to run “rebaseall” after installing. This shell script uses Cygwin’s rebase.exe program. Visual Studio.NET also ships with a rebase.exe executable with different command line syntax, so make sure your path is set up (or edit /usr/bin/rebaseall) so that the Cygwin version is called, not the MS version.

Tagged with php