PHP Profiling Using Xdebug and Kcachegrind
Xdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file. This allows you to use the KCacheGrind tool (Linux,) to analyse your profiling data.
Xdebug profiler is incorporated in the Xdebug tool. Therefore you first need to download, install, and enable Xdebug itself and after that enable the profiling functionality within it.
Install x-debug through apache
Enabling Xdebug integration with the PHP engine
Once xdebug is installed, you can enable the xdebug(profiler) to work with PHP by adding following lines at the end of php.ini file.
You can run this command yo find the path to xdebug.so
Replace this path in "zend_extension= ...."
Xdebug Settings
- xdebug.profiler_append:
Type: integer, Default value: 0
Setting it to 1 will not overwrite the exisitng profiler file when a new request is made but append the new profiling in same file.
- xdebug.profiler_enable:
Type: integer, Default value: 0
Setting it to 1 will enable xdebug profiler which creates a file in the "profiler_output_dir" directory but If you want to selectively enable the profiler, set "profiler_enable_trigger" as 1
- xdebug.profiler_enable_trigger
Type: integer, Default value: 0When this setting is set to 1, you can trigger the generation of profiler files by using the XDEBUG_PROFILE GET/POST parameter, or set a cookie with the name XDEBUG_PROFILE. If you want to profile a particular url you can append "?XDEBUG_PROFILE=1" at the end.
eg: http://somedomain.com/test?XDEBUG_PROFILE=1 (make sure xdebug.profiler_enable is set to 0) - xdebug.profiler_output_name
Type: string, Default value: cachegrind.out.%p This setting determines the name of the file that is used to dump traces into. The setting specifies the format with format specifiers, very similar to sprintf() and strftime(). There are several format specifiers that can be used to format the file name.
- xdebug.profiler_output_dir
Type: string, Default value: /tmp The directory where the profiler output will be written to, make sure that the user who the PHP will be running as has write permissions to that directory.
Once all of this settings is set, run any project in your browser and this should generate a profiler file in above mentioned directory. Keep it mind, "profiler_enable" set to 1 will profile all of the PHP process everytime it runs so you might end up having a lots and lots of profiler files in your system.
Installing KCACHEGRIND
KCachegrind is a tool used for profile data visualization. Visit this link for more details (http://kcachegrind.sourceforge.net/html/Documentation.html)
Thanks for the always useful information. This is great information to help peoples and nice article written by writer. CnX Player is a powerful & efficient 4K ultra HD enabled video player for Windows 10 PC & Tablet, Android and iOS – iPhone & iPad.
ReplyDeleteDownload Media Player for Windows 10 - Microsoft Store
Download Video Player for Android from Google Play
Download Video Player for iPhone/iPad from Apple App Store
Nice Article thanks For giving me Nice Information.
ReplyDeleteMGSU BA 3rd year result