Keeping your Magento fit with built in profiler

Keeping your Magento fit with built in profiler

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.

    You made it all the way down here so you must have enjoyed this post! You may also like:

    How To Connect Google Analytics 4 To Magento 2 Bojan Mareljic
    Bojan Mareljic, | 35

    How To Connect Google Analytics 4 To Magento 2

    MageMeter – a new way to present and share Magento performance benchmarks Ivona Namjesnik
    Ivona Namjesnik, | 0

    MageMeter – a new way to present and share Magento performance benchmarks

    Analyze Magento speed and performance Stanislav Mihic
    Stanislav Mihic, | 2

    Analyze Magento speed and performance

    10 comments

    1. i was getting issues where i couldnt see my changes, clearing the caches didnt work, clearing the sessions didnt work.

      For some reason it fixed everything once i ran a re-index via SSH then magento worked perfectly.

    2. 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!

    3. 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.

    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> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

    Tell us about your project

    Drop us a line. We'd love to know more about your project.