Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Sat Mar 14, 2009 12:23 am Reply with quote

Profiling with Xampp, Xdebug and Webgrind

Intro;
This tutorial will help you setup your xampp package to make use of the xdebug debugger extension and the webgrind GUI frontend (for xdebug).

Xampp;
http://www.apachefriends.org/en/xampp.html
Xampp Site wrote:

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start.


XDebug;
http://www.xdebug.org/index.php
Xdebug Site wrote:

The Xdebug extension helps you debugging your script by providing a lot of valuable debug information. The debug information that Xdebug can provide includes the following:

  • stack traces and function traces in error messages with:

    • full parameter display for user defined functions
    • function name, file name and line indications
    • support for member functions

  • memory allocation
  • protection for infinite recursions

Xdebug also provides:

  • profiling information for PHP scripts
  • code coverage analysis
  • capabilities to debug your scripts interactively with a debug client



Webgrind;
http://code.google.com/p/webgrind/
Webgrind Site wrote:

Webgrind is an Xdebug profiling web frontend in PHP5. It implements a subset of the features of kcachegrind and installs in seconds and works on all platforms. For quick'n'dirty optimizations it does the job. Here's a screenshot showing the output from profiling:


Ok here we go

I'm going to assume you have xampp installed and setup if not you can get it from here

http://www.apachefriends.org/download.php?xampp-win32-1.7.0-installer.exe

You will see me reference <xampp> directory a number of times.This is obviously the directory you installed xampp.for me it is

Code:


D:/xampp


Download xdebug server install and configure in php

Download the following extension
http://www.xdebug.org/files/php_xdebug-2.0.4-5.2.8.dll
Note: This is suitable for xampp version 1.7, otherwise you may need a different version of the extension (see the xdebug site)

And place it in;
Code:


<xampp>/php/ext


Open: <xampp>/apache/bin/php.ini and make the following configuration changes:

Code:


implicit_flush = On


Find the heading [Zend] and coment them all out.

Underneath the zend heading there should be a heading called xdebug (if not create it) and add the following
Note: Make sure you change the directories appropriately.And create the profiler folder i.e xdebug.profiler_output_dir.

Code:


[xdebug]
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.show_local_vars=1
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir="D:/xampp/profiler"
zend_extension_ts="D:/xampp/php/ext/php_xdebug-2.0.4-5.2.8.dll"


So you should now have something similar to the following

Code:


[Zend]
;zend_extension_ts = "D:\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
;zend_extension_manager.optimizer_ts = "D:\xampp\php\zendOptimizer\lib\Optimizer"
;zend_optimizer.enable_loader = 0
;zend_optimizer.optimization_level=15
;zend_optimizer.license_path =
; Local Variables:
; tab-width: 4
; End:

[xdebug]
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.show_local_vars=1
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir="D:/xampp/profiler"
zend_extension_ts="D:/xampp/php/ext/php_xdebug-2.0.4-5.2.8.dll"


If you have trouble, I did come accross the following in my travels
Quote:

Note: The _ts above corresponds to THREAD SAFE. If you have trouble seeing xdebug in your phpinfo output, check the Thread Safe field in the top section. If it is Thread Safe: No, then take the _ts off and just use zend_extension=.
Also, check the 'Debug Build' field. If it is 'yes' you will need 'debug' in this field name. Here are the possible combinations you could end up with:

zend_extension (I ended up with this on Ubuntu+xampp)
zend_extension_ts (I ended up with this on Windows XP+xampp)
zend_extension_debug
zend_extension_debug_ts


Restart Apache and open your web browser and goto your localhost

Code:


http://localhost/xampp/


And on the left click phpinfo()

now scroll down and look for xdebug (see the following image)

Only registered users can see links on this board! Get registered or login!



Next download webgrind, extract and put it in your root folder
http://webgrind.googlecode.com/files/webgrind-release-1.0.zip

Example
Code:


<xampp>/htdocs/webgrind


ok to actually profile a page you will need to initiate it using XDEBUG_PROFILE

So lets say we have a local instalation of ravennuke 2.3 (what else) located here

Code:


http://localhost/rn23/index.php


To profile the page you would use the following in your browser address bar

Code:


http://localhost/rn23/index.php?XDEBUG_PROFILE


The above will create a file similar to the following in the profiler directory you set up earlier

Code:


cachegrind.out.3616


Now browse to webgrind
Note: webgrind requires no configuration as it reads the php.ini file to locate the profiler directory.
Code:


http://localhost/webgrind


In the drop/list box at the top select the file that is listed there (see the example image below)

Only registered users can see links on this board! Get registered or login!

And click the Update button on the right

And the final results......

Only registered users can see links on this board! Get registered or login!


Some more examples

In the following image you can see that block-Survey has an extremely high cost time compared the the rest....So if you click where the red circle is, It will take you to the troublesome code. (see next image)

Only registered users can see links on this board! Get registered or login!

Only registered users can see links on this board! Get registered or login!

xdebug also provides nice error messages

Only registered users can see links on this board! Get registered or login!

The End


Last edited by testy1 on Sat Mar 14, 2009 4:36 pm; edited 1 time in total 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sat Mar 14, 2009 8:40 am Reply with quote

testy1, thanks for these nice instructions, although, you may need to tidy up some of the bbcode as its not displaying properly.

However, the example you give towards the bottom is completely bogus. If you have ShortLinks turned on, there is no way that the very small Survey block is going to cause the ShortLinks part to be the worse section of code. If the results are real in that that particular block is showing up, it has to be something within the block itself causing the issue, not shortlinks.

So, one has to be careful how they read and interpret the results. That really goes with any profiler. None of them are perfect, especially when run against something as complex as a CMS where there are many included files, many function calls, different classes, etc.

And, no, I do not wish that I were you... Wink

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
duck
Involved
Involved



Joined: Jul 03, 2006
Posts: 273

PostPosted: Sat Mar 14, 2009 10:53 am Reply with quote

Very Nice Tut! Thanks!
 
View user's profile Send private message
testy1







PostPosted: Sat Mar 14, 2009 4:47 pm Reply with quote

montego wrote:

And, no, I do not wish that I were you... Wink


ROTFL

The problematic bit of code was actually this

Code:


$file = file_exists('blocks/'.$blockfile);
    if (!$file) {
        $content = _BLOCKPROBLEM;
    } else {
        include_once('blocks/'.$blockfile);
    }


And when I changed it to the following it dropped it by 2.4ms

Code:


if (file_exists('blocks/'.$blockfile)) {
      include_once('blocks/'.$blockfile);
   } else {
      $content = _BLOCKPROBLEM;
   }


EDIT: to me it made more sense to assume the file would be there and if not display the error?
 
montego







PostPosted: Tue Mar 17, 2009 6:44 am Reply with quote

Very good assumption and I like the way you switched that around. Amazing isn't it just what a simple change like this can make? If I can remember to log this, I will so we change it permanently within RN. There is code all over the place just like this. Amazing the amount of time we've spent on cleaning up *nuke, but still so much more to do. Sad

Thanks!
 
testy1







PostPosted: Tue Mar 17, 2009 3:44 pm Reply with quote

It is amazing to me, Im not normally known for my common sense ROTFL
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©