Profiling with XDebug and KCacheGrind

Posted on 27th April, 2011 | Tagged:

On using the Symfony2 profiler I was a /little/ disapointed with the lack of detailed timing information (e.g. time taken to render templates, time taken on the database, etc), but then I remembered how little value these timings has in Symfony 1.x — they basically didnt help very much with identifying why the application was slow. Fortunately there is a (much) better way to profile your application. XDebug and KCacheGrind.

XDebug provides the data and KCacheGrind provides amazing visualizations which identify percisecly where and why your applcation is slow.

Enabling XDebug Profile

To enable profiles to be written (I assume you have already installed XDebug) add the following lines to php.ini

xdebug.profiler_enable=1
xdebug.profiler_output_dir=/tmp

; This line is optional ...
xdebug.profiler_output_name=cachegrind.out.%p

This will enable the profiler upon restarting apache and subsequently a profile will be written for each request and the files are not very small and will slow down your website, so you should only enable profiling to collect data and disable it again afterwards.

-rw-r--r-- 1 www-data www-data 22M Apr 27 23:23 cachegrind.out.10371
-rw-r--r-- 1 www-data www-data 4.4M Apr 27 23:23 cachegrind.out.10373

Profile files in /tmp

Visualizing with KCacheGrind

Install KCacheGrind

apt-get install kcachegrind

Note that there are versions for windows and mac on the website.

Load the profile

C’est puissant!

Comments

Be the first to leave a comment.

Post new comment


type "i hate spam" in UPPER CASE

Tags

10 Latest Items