Magento Debugging Using Profiler

0

Magento is the biggest PHP-based ecommerce platform. The primary purpose of the platform is to cover all the needs of ecommerce store owners. It is easy to use, universal and flexible. A lot of things are changed from year to year in Magento. Servers that deploy Magento have become more powerful, the number of developers & extensions has grown significantly. As a result, we have a wide choice of the solutions that can be implemented with our Magento stores.

Making a Magento store faster is pretty much an easy process but unfortunately, very often it is hard to predict how good a particular add-on is, and whether it is suitable for the Magento store. It is not about guessing or assuming something that might be slow, but it is digging into what’s happening behind the scenes and measuring what is eating more memory or time.

When it comes to debugging, we have many tools i.e. xdebug, New Relic, etc. You can get useful information when using these tools and check your website with their colorful graphical outputs. But these debuggers don’t have much idea about the structure of your Magento application. And that is why Magento has an internal debugger named as “Profiler“.

The Magento Profiler is the internal Magento Debugging toolm. It plays a significant role in Magento development. It is a tool which allows you to collect different information about controllers, actions, blocks, templates, events, observers, etc. on the various application execution stages. The Magento Profiler also allows you to get a report about how long each part of a Magento store is being loaded. With the help of this report, we can investigate and see what slows down the page load time.

When you successfully turn on the Magento Profiler, you can see the output in the footer area of any Magento page which reports the time a block of code took in execution, number of times the block of the code executed & memory used by it while rendering a Magento page.

Magento Profiler Output
In the above screenshot, you can see the table with following headers:

  • Code Profiler
  • Time
  • Cnt
  • Emalloc
  • RealMem

Code Profiler holds the name of a block of code.
Time indicates the total time a block of code took in execution.
Cnt stands for “count” holds an integer value which shows how many times a block of code executed.
Emalloc is the minus value from the amount of memory allocated to PHP without “true” parameter passed in PHP memory_get_usage() function.
RealMem is also the minus value from the amount of memory allocated to PHP but with “true” parameter passed in PHP memory_get_usage() function.

Enabling Magento Profiler

To turn on the Magento Profiler and perform debugging, you have to do the following things.
1. Login to your Magento Admin Panel.

Magento Login
2. Navigate to System > Configuration.

Magento System Configuration
3. Tap Developer under the ADVANCED menu.

Magento Advanced Developer
4. Extend the Debug panel.

Magento Debug
5. Enable Profiler by selecting “Yes” from the drop-down menu and click Save Config button.

Enable Magento Profiler
6. Now open index.php file found in the root folder of Magento installation.

Magento Index PHP
7. Search for “Varien_Profiler::enable();” and uncomment it by removing hashtag in the start.

Magento Profile Enabled

Note: If you do not find “Varien_Profiler::enable();” then place it somewhere before “Mage::run($mageRunCode, $mageRunType);

Now load any of your Magento store pages and see the output in the footer area as shown in the above screenshot.

Conclusion

There is one thing each and every web developer is doing from day to day, no matter how experienced a developer he is and how well he writes code. He may know his snippets very well, but usually, he has to integrate his work into other different solutions which were, unfortunately, created by someone else. Here web developer meets the thing that can turn his life into the nightmare if he is following a wrong path – The Debugging.

Debugging is an efficient process to locate and fix the bugs in applications. Magento Ecommerce Platform supports a lot of useful tools to make the Magento Debugging process faster and handy. Also, if you need to improve your Magento development environment and want to make debugging less painful, Magento has its internal debugger “Magento Profiler.”

I hope that with the use of Magento Profiler, you can make your Magento stores faster in speed and can also fix your buggy codes which increase the page load time. If you have any other issues to discuss, feel free to share it in the comments section.

Share.

About Author

Fayyaz is a Magento Community Manager at Cloudways - A Managed Magento Hosting Platform. He writes about Magento Tutorials at Magenticians as well as share his knowledge with the Magento Community. Fayyaz is a food lover and enjoys driving. You can email him at m.fayyaz@cloudways.com