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

  • 05
    May

    blog Traveling It just occured to me that I havn't updated this website with a blog post saying that I am now on my big bike tour. I left at the end of February with my Dad and we rode down to Clermont Ferrand in sometimes very cold and wet conditions, to meet u...

  • 23
    Mar

    blog The Auto Route Bundle I have almost finished my first `symfony-cmf` bundle, the `RoutingAutoBundle`.

  • 04
    Mar

    blog Race Day Race Day

  • 11
    Oct

    blog FInding lost commits How many times have you done some work on some branch, which was not the right branch, only to go back to the branch you __thought__ you were working on, only to find out that your precious commit has dissapeared, where is it?

  • 02
    Sep

    blog Moving email to the console !Disclaimer -- this is a work in progress and if anything is a personal reference...

  • 18
    Aug

    blog 3 days on the Loire "Where shall I go?"

  • 15
    Jul

    blog Cycling in England and Wales and France Eurostar Bon Voyage 14 euros to St. Pancras station and train then metro to Wimbledon Park rendezvous avec mon frere and coffee in a wimbledon high-street café. Bikes locked and not stolen. Books bought. More coffee. Dinner etc. Later left in morning e...

  • 22
    May

    blog Paris to Amsterdam: Paris to Brussels I left Paris at 6:30 in the morning reasoning that I would be able to cover the distance to Brussels in 12 hours. I felt the chill in my eyes 2 miles from my appartement and I realised I had forgotten to bring my new sunglasses. I returned to the appar...

  • 24
    Mar

    blog From blueprint to bootstrap I have just finished updating my Symfony2 <a href="http://github.com/dantleech/TrainerBundle">Trainer</a> application to use <A href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a>.

  • 14
    Feb

    blog DOMNodeList doesn't implement Traversable interface in PHPv5.3.2-1ubuntu4.14 So I have just spent about 4 hours scratching my head, then cursing at my computer as for some inexplicable reason TWIG would not iterate over my DONNodeList.