How to enable Magento 2 profiler?


Surely you’ve heard about it before while looking for Magento 2 installation and launch lifehacks. So, it’s about time to put the things right.

What is Magento 2 profiler?

Magento 2 has a built-in profiler, which is used to identify performance problems on the server. With the use of the profiler, you can see the execution time of certain chunks of code including the time for each query and executed parameters. Thus, we can get the execution time of code blocks and optimize memory and time spent.

Magento 2 supports 3 profiler formats:

  • HTML;
  • CSVfile;
  • Firebug.

The built-in profiler formats can be used for:

  • analyzing performance tasks;
  • display dependency graphs on a Magento page;
  • reveal unused dependencies to cut down on memory and time.

How to enable Magento 2 profiler?

Magento profiler can help you with the store performance tuning before the store release or during the exploitation.
The old UI for enabling/disabling the profiler is not available in Magento 2 and the profiler is disabled by default.
To enable one of the profiler formats mentioned above, you can edit .htaccess (a configuration file for Apache Web Server software):

  • Choose one of the next expressions:

1. SetEnv MAGE_PROFILER "html" outputs in the footer of a web store page opened in a browser.
¡To enable the HTML profiler, you can also edit index.php with the next expression: $_SERVER["MAGE_PROFILER"]="html"!
2. SetEnv MAGE_PROFILER "csvfile" outputs into var/log/profiler.csv.
3. SetEnv MAGE_PROFILER "firebug" outputs into var/log/profiler.csv.

Magento 2 profiler is not working: eliminate the glitch

There are cases when HTML profiler won’t work. The reason is that the HTML code causes javascript execution errors. You can crack the problem by using other profile modes (csvfile, etc.) or make sure the HTML profiler doesn’t influence the functionality.

Rate the answer?