Search This Blog

Wednesday, February 3, 2010

KcacheGrind Profiling for PHP -Speed up Your Scripts

To check the time taken to execute a query we can use \timing on the psql prompt with Analyze and Verbose
To check the render engine we can use fire bug and firephp with YSlow,Jiffy etc., (even we can debug javascript and go for line by line execution of all the client side script )

For PHP code

While we write a code or test a code we are not able to clearly check how much time it will take for executing part of code (loops,functions) , How many times each function are called etc., to track this we have many tools like APD,XDebug

Herewith I am giving the steps to install and check the efficiency of code using XDebug



Installation and configuring(XDebug)

1) sudo pecl install xdebug

2) zend_extension =/usr/lib64/php5/extensions/xdebug.so
or
zend_extension =/usr/lib/php5/extensions/xdebug.so
xdebug.profiler_enable=1
xdebug.profiler_output_dir=[/home/myhome/apdtrace/]

3) sudo httpd restart

Now try to view the output of your phpinfo() function. If you find xdebug word in that then it means you have successfully installed xdebug.

Install kcachegrind
option 1
use YAST->software Management->Search->kcachegrind
accept the proposal
option 2
sudo apt-get -y install kcachegrind (for debian Systems)

Add these Lines on your code(recommended) or php.ini
ini_set('xdebug.collect_vars', 'on');
ini_set('xdebug.collect_params', '4');
ini_set('xdebug.dump_globals', 'on');
ini_set('xdebug.dump.SERVER', 'REQUEST_URI');
ini_set('xdebug.show_local_vars', 'on');

execute your code on browser you will get a file named cachegrind.out. on your output directory
open the file with your kcachegrind now you can clearly dissect your code and remove unnecessary code and loops and check the speed again

No comments:

Post a Comment