Home > LAMP > Setting 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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: