Bookmarklet To Run XDebug Profiler

×

Error message

Warning: apc_store(): Potential cache slam averted for key 'www.hashbangcode.com::cache_bootstrap::variables' in DrupalAPCCache->set() (line 206 of /var/www/www.hashbangcode.com/2014-03-22-2105/docroot/sites/all/modules/contrib/apc/drupal_apc_cache.inc).

Tuesday, February 5, 2013 - 17:24

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
2
3
4
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.

Category: 
Tags: 
philipnorton42's picture

Philip Norton

Phil is the founder and administrator of #! code and is an IT professional working in the North West of the UK.
Google+ | Twitter

Comments

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

philipnorton42's picture
Submitted by philipnorton42 on Tue, 02/12/2013 - 12:03

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