LAMPSetting up KCachegrind in Ubuntu

Setting up KCachegrind in Ubuntu

There are a couple of ways to see cachegrind outputs

  • KCachegrind ( KDE Based )
  • Webgrind

If you absolutely hate KDE, then you might want to consider Webgrind – but it is not as comprehensive as KCachegrind

Setting Up

  • Running instance on Ubuntu ( i am Ubuntu 13.04 on a VM )
  • Running instance of Apache, PHP with xdebug installed
  • A very quick way to set up your environment is using these commands
sudo apt-get install tasksel
sudo tasksel ( select the LAMP and follow instructions )
sudo apt-get install php5-xdebug
  • Next install KCachegrind using the command ( big package )
 sudo apt-get install kcachegrind

 xdebug settings

  • We then make sure we have the following things in the xdebug.ini ( some of them might be set – skip them – check phpinfo() output )
  • Mine is /etc/php5/conf.d/20-xdebug.ini 
  • You can find xdebug.ini if you look at your phpinfo() output under Additional .ini files parsed 
 xdebug.remote_enable = 1
 xdebug.remote_connect_back = 1
 xdebug.profiler_enable = 0
 xdebug.profiler_enable_trigger = 1
 xdebug.profiler_output_dir = /tmp
 xdebug.remote_handler = dbgp
 xdebug.remote_port = 9000
  • Save and exit the ini file
  • Restart apache and verify that all your ini settings are reflected in phpinfo() xdebug section

Generating the profile files

If you are just using a browser

  • append XDEBUG_PROFILE=1  ( in the GET/POST request to your script )
  • eg: localhost/index.php?XDEBUG_PROFILE=1

If you are using an IDE,

  • make sure port 9000 is open
  • xdebug is allowed to accept external connections
  • you have installed a browser xdebug extension like Easiest Xdebug for firefox
  • you have enabled Profiling
  • Then make a request to your favourite PHP script

Looking at the results

  • This will create a cachegrind file in /tmp directory – something like cachegrind.out.2955
  • Open this file using KCachegrind
  • Start scratching your head and try to improve things 🙂

Categories: LAMP


No Comments Yet. Be the first?

Post a comment

Your email address will not be published. Required fields are marked *