Varien Profiler for Magento

Do you have slow page load times? Are you developing a plugin and suddenly it's making your site run VERY slow?

In order to address performance issues within your code, you can use an out of the box solution provided by Magento. It is the Varien Profiler. It basically monitors the time and memory allocation of your application loading cycle at specific intervals you set. It's also very easy to use.

  1. //First, enable the profiler
  2. Varien_Profiler::enable();
  3.  
  4. //Second, start the profiler with a special key
  5. Varien_Profiler::start('my-special-key');
  6.  
  7. //do some php code
  8.  
  9. //next, stop your profiler with the same key
  10. Varien_Profiler::stop('my-special-key');
  11.  
  12. //Last, disable your profiler
  13. Varien_Profiler::disable();

Now you've captured how long it's taken to execute your code.

But where do you see it?

In order to do that, you have to go into your Magento admin panel and go to System->Configuration->Advanced->Developer. Go to the Debug tab and enable the profiler.

enable-varien-profiler

Click save, refresh the cache and go to your frontend. Load a page and scroll to the bottom. You should see something new.

varien-profile

Its an output of your profile you just ran.

Also, if you want to profile your whole application and see where there are bottlenecks, simply go into your index.php file and uncomment the following line:

uncomment-this-line-to-enable-profiler

Just don't forget to comment it out again once you are done!

Now you will be able to check and see any bottlenecks or resource hogs in your application.

I hope this helps.

Until next time.

This entry was posted in Magento on by .

About Ryan Street

Ryan Street is a Plus Certified Magento Developer who loves everything related to Magento, WordPress, PHP, and programming. When not turning coffee into code, he is usually spotted somewhere online answering questions and helping people.

2 thoughts on “Varien Profiler for Magento

    1. Ryan Street Post author

      You can always check system logs and exception logs to see if there is an error, but unless you’ve configured logs yourself, there isn’t any that log automatically.

Leave a Reply