Bookmarklet To Run XDebug Profiler

5th February 2013 - 2 minutes read time

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.

  1. xdebug.profiler_enable=0
  2. xdebug.profiler_output_dir=/tmp/xdebug_profiles
  3. xdebug.profiler_enable_trigger=1
  4. 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

Permalink
A post on how to interpret the output would be extremely useful.

Tjorriemorrie (Mon, 02/11/2013 - 07:37)

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.

Frank (Tue, 02/12/2013 - 07:52)

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!

Add new comment

The content of this field is kept private and will not be shown publicly.