It's Tuesday - what a day to visit jfoobar!

 

Profilers, profiles and profiling

It has been a while since I have been able to write any kind of blog due to insane busy schedule and lots of travel (almost Platinum member in less then 4 months :-D). Having some days off (and with that time to start writing) I ran into a discussion on the Joomla CMS development mailing list talking about the performance of Joomla 1.6 compared to Joomla 1.5. I replied with a very short hierarchical map of a basic page view that was created with Xdebug for profiling a simple profile snapshot.

In this article I want to explain the basics of profiling and profiling tools available in Joomla and PHP. In follow up articles I will explain the usage of the tools presented in this blog. I will also try to set up a performance analyses so we can see what the state of Joomla 1.6 is, but that is also for later concern. This article is based on tools that are freely available for almost all platforms.

Joomla profiling

Joomla has an internal profile mechanism. It times performance from within the code-base, and gives some information about execution timings and memory usage. Profiling can be activated in the Global Configuration -> System under Debug settings.

Image of Joomla 1.6 debug settings

After enabling this setting some profiling information will be rendered in the front-end. A default installation gives the following results on my system (left out all specific queries). This gives a nice overview of the timing on my test system. Around 0.5 second to render the page, and a dazzling 13Mb of internal memory used to render the page.

**Profile Information**

Application 0.002 seconds (+0.002); 0.50 Mb (+0.50) - afterLoad
Application 0.121 seconds (+0.119); 5.12 Mb (+4.62) - afterInitialise
Application 0.154 seconds (+0.034); 6.88 Mb (+1.76) - afterRoute
Application 0.469 seconds (+0.315); 11.38 Mb (+4.50) - afterDispatch
**Memory Usage**

12,962,136
**24 Queries Logged**

You can add your own profiling information in your extension to validate the timing and memory usage of your extension. Most of the times you do this after you have almost finalized your extension and want to do a final piece of quality assurance. But if you want to validate the bahaviour of your code in more detail, PHP offers you some real professional tools to profile your application. Let us take a look on this.

PHP profiling

When you develop for PHP there are a truckload of free tools available to help you improve the quality of your code as I already explained in the continuous integration building blocks blog-post from past year. When you write unit tests and enabled XDebug, you will not only have the testing results available. XDebug can do a lot more then only helping you with debugging, or generating code coverage reports, it also provides you with the opportunity to profile you code.

When you have XDebug installed, you need to set it up for generating the profile files, also referred to as cachegrind files. I use the following settings in my php.ini file to generate these cachegrind files:

; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=1
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
;xdebug.profiler_output_name=crc32

See the documentation setting of XDebug to understand the meaning of these settings. Make sure to restart Apache to apply the settings. From then on there will be files with the following pattern "cachegrind.out.xxxxxx" where the xxxxxx refers to the process id of the http request. Make sure the volume has enough space, since these files can be very big on a CMS like Joomla.

Screenshot of KCachegrind

The generated cachegrind files can be analysed using KCacheGrind (Linux) or Webgrind (Windows). I have found the Linux tools to be easier to install and more complete, but it is of course up to you what to use. KCachegrind can generate hierarchical overviews that give absolute, but also percentage of total use within the run. When you have setup Xdebug properly, you can drill even down on the execution flow, up till the source-code. This actually enables you to determine potential code that can be improved.

About the author Wilco Jansen

Wilco was born in 1967 in the Netherlands where he still lives. After years of being a programmer Wilco has worked as project manager and IT manager. Discovered Joomla! when he was creating his own content management system, and never lost focus after then. Joined core team as development coordinator in May 2006 just helping to make Joomla! even better then it is already. Wilco has been deeply involved in the Joomla project as Google summer of code program manager 2006, 2007 and 2008 editions, co-organizer of the Google Highly Participation contest in 2008, first ever development coordinator, creator of the Joomla bug squad, member of the board of Open source matters, regular speaker on world wide conference advocating Joomla and much, much more. Wilco has a bachelor degree in business and information engineering and studied Master of Science knowledge and information engineering at the Middlesex University in London.

More about Wilco Jansen

Like it? Share it!

There are 0 comments posted.

Help for creating beautiful comments.

Enter Your Details:
Enter Your Comments:
I'm finished with the form Your form will be checked and you'll get a preview.
moovur promo

Blogging team

We have a team that works on the blogs presented on this site. Below you will find all present members who are actively working on blogs on this site.


Please contact us if you are interested in helping us out with the creation of the blogs.

Post translations

jfoobar has readers from all over the world and in many languages. If you create a translation of one of our posts and link to it than please let us know so we can add a link back to the translation at the original post.

JFoobar friends on Twitter

Follow JFoobar on twitter

Sponsored Links

Latest Comments

Aaron wrote:
2009-12-23 13:19:22 - Genius! Thanks, Wilco. I've been dying to take .
Posted in How to downlo .
Amy Stephen wrote:
2009-12-22 18:39:37 - Happy Birthday to one of Joomla!'s most noble - .
Posted in Mister Joomla .
Antonie de Wilde wrote:
2009-12-22 09:30:26 - Congrats Robin. Have a good day and watch out w .
Posted in Mister Joomla .
Robert wrote:
2009-12-22 08:51:02 - Happy Birthday Robin .
Posted in Mister Joomla .
Arno wrote:
2009-12-22 08:43:28 - Happy Birthday Robin, love your suit, you wife .
Posted in Mister Joomla .
Brian Teeman wrote:
2009-12-22 00:17:41 - Happy Birthday Robin, Welcome to the big four oh .
Posted in Mister Joomla .