How to enable Magento 2 Profiler

Magento 2 features a built-in Profiler, which allows you to monitor your store´s performance and optimize memory and time of code execution. Moreover, Profiler can display dependency graphs, which allows you to catch objects, created by Magento, but in fact never used.

Dependency graph is displayed at the bottom of each page, making it very handy in tuning-up of your store.

You can also direct profiling information to the special CSV file, which allows you to analyze it in a spreadsheet. This mode also can be used, when Profiler conflicts with your theme.

In versions, prior to 2.2 there was a special CLI command, that enabled/disabled Profiler. But currently there is only one way to enable it - editing your .htaccess file.

Here is what you need to do:

  1. Log in to your FTP/SSH, and navigate to root directory of your store.
  2. Open .htaccess file, and add there the following line (usually at the beginning): SetEnv MAGE_PROFILER "html"
  3. If you wish to direct profiling information to CSV file, replace “html” with “csvfile”. Then all output will be stored in var/log/profiler.csv file.
  4. Log in to your SSH/CLI shell, navigate to your store root directory and switch your store to developer mode with bin/magento deploy:mode:set developer command.

This will enable Magento 2 Profiler on your store.

Did you know…

… that our company offers a special package, that can return back CLI command for enabling/disabling profiler. It is a free product, available from Github.

After installation, you need to know only two commands, one for enabling (bin/magento mirasvit:profiler:enable) and one for disabling (bin/magento mirasvit:profiler:disable). No more .htaccess editing and so simple.

Additionally, Mirasvit Magento 2 Profiler allows you to restrict profiling information display by IP.

Loading...