Bookmarklet To Run XDebug Profiler

XDebug is a great PHP debugging tool, but it also comes with a very useful profiler that can tell you all sorts of information about your PHP application. This includes things like memory footprint and CPU load but will also have detailed information about the entire callstack of the code that was run. To enable the profiler part of XDebug you just need to set up a few rules in your xdebug.ini file.

xdebug.profiler_enable=0
xdebug.profiler_output_dir=/tmp/xdebug_profiles
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_name=cachegrind.out.%p

On some systems the profiler will cause the application to slow down so I normally explicitly set profiler_enable to be 0 (the default value) and use the profiler_enable_trigger to only profile the application when I need to. This helps as you can quickly end up with lots and lots of profiler output files, which can be a pain to inspect. With the profiler_enable_trigger in place you then append XDEBUG_PROFILE=true to the URL at any time in order to run a profile. Note that any positive value will cause the profiler to trigger.

The only problem I have is remembering the trigger needed to call the profiler, which I normally end up having to look up. So I created a little bookmarklet that will take the current URL and just append the correct flag.

javascript: window.location = window.location.protocol + '//' + window.location.hostname + window.location.pathname + '?XDEBUG_PROFILE=true';

Here it is in link form.

Xdebug Profiler

Just drag the above bookmarklet into your bookmark folder and you can run the XDebug profiler whenever you want with just a click of a button.

To view the output of the XDebug profiler I can recommend using KCachegrind. This provides all of the information like CPU load and memory uses as well as interactive graphs of the callstack.

Comments

A post on how to interpret the output would be extremely useful.
Permalink
I use the Xdebug Helper Addon, usable in Chrome and Firefox. Have more functions and is easy to use . Also I use the alternative to KCachegrind: Webgrind - usefull, for users, there will a output inside the browser.
Permalink
The last time I looked at a web based kcachegrind alternative the output was pretty poor. That version looks good, and produces the call stack graphs that were lacking the last time I looked. Thanks!
Name
Philip Norton
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
5 + 10 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.