Keeping your Magento fit with built in profiler

Featured Image

Default Magento installation has this great feature called “Profiler” that can play important role with your custom Magento development. This feature is meant to be be used for developer only. If used properly it can help you get valuable information of certain code parts during development.

To turn the “Profiler” on you have to do two things:

  • Login to your Magento admin, go to “System > Configuration > Advanced > Developer > Debug > Profiler > Yes
  • Open your root index.php file of your Magento installation then look for commented “Varien_Profiler::enable();” part and uncomment it. If there is no “Varien_Profiler::enable();” then place it somewhere before “Mage::run($mageRunCode, $mageRunType);”
  • .

    If you where successful with turning on “Profiler” you should see the output in the footer area of any Magento page, like shown on the photo below.

    As you can see, it shows the table with following headers: “Code Profiler“, “Cnt“, “Emalloc“, “RealMem“.

    Code Profiler” column basically holds the value of your custom timer name. In my example, this would be “inchoo::test”. This is freely taken/assigned value. Try to use meaningful names for your timers.

    Cnt” column stands for “count”, and it holds the integer value of how many times have you “started” your timer with the same name. For example if I were to have my “Varien_Profiler::start(‘inchoo::test’);” called 2 times somewhere in my code, then my “Cnt” column would hold the value “2” in it. Like shown on the photo below.

    Emalloc” column stands for “Amount of memory allocated to PHP”. Its a mix of core PHP memory_get_usage() function without “true” parameter passed to it, minus timer values.

    RealMem” column also stands for “Amount of memory allocated to PHP” whose final value is also obtained trough memory_get_usage(true) function minus timer values but this time with “true” parameter passed in.

    Please see the official PHP documentation on memory_get_usage() function for more info.

    Besides these basic information, one can get more info by calling “Varien_Profiler::getSqlProfiler($conn);” like on the example shown below.

    $conn = Mage::getSingleton('core/resource')->getConnection('core_setup');
    $conn->getProfiler()->setEnabled(true);
     
    echo Varien_Profiler::getSqlProfiler($conn);

    More info on this on of my older articles here.

    Hope this demystifies the whole “profiler” topic a little bit.

    It’s not a bad idea to use profiler features during development as you can react on time on certain possibly bloated code areas.

    Cheers.

    Interested in hiring us?

    Have a chat with us. You would be surprised how small changes can make your business even more successful.


    7 comments

    1. Thanks for ones marvelous posting! I definitely
      enjoyed reading it, you could be a great author.I will
      be sure to bookmark your blog and will eventually come back from now on.
      I want to encourage you continue your great posts, have a nice afternoon!

    2. Great post and very well explanation.
      Its clear to understand and very help full to all magento developer.
      Thanks for sharing such a great knowledge with us.

    3. I just can’t get this to work on 1.7.

      The profiler displays but all the columns are empty/blank!

    4. You also need to enable developer mode in magento and in index.php enable profiler:

      Varien_Profiler::enable();
    5. Hi,

      I tried to turn the feature on as described, but I am getting only the headers from the table without any content.
      Caches were disabled.
      (Turned on the feature in admin and changed index.php as described)

      Any idea why it doesn’t work?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.