What is Magento 2 profiler?

Magento has an in-built profiler that can be used to identify performance problems on the server side. In a nutshell, the profiler can tell us the execution time of certain chunks of code. We always have a scenario to know which template is loaded on the page then this is helpful to debug the layout.

Magento supports three profiler outputs, namely html, csvfile, and firebug.

To enable the profiler, we can edit .htaccess and add one of the following expressions:

  • SetEnv MAGE_PROFILER “html”
  • SetEnv MAGE_PROFILER “csvfile”
  • SetEnv MAGE_PROFILER “firebug”

profiler-html

CLI commands

You can enable or disable the profiler using CLI commands:

  • dev:profiler:enable  enables the profiler with type of html (default) or csvfile. When enabled, a flagfile var/profiler.flag is created.
  • dev:profiler:disable disables the profiler. When disabled, the flagfile var/profiler.flag is removed.

To enable dependency graphs, use the variable option.

To enable or disable the profiler:

  1. Log in to your Magento server.
  2. Change to your Magento installation directory.
  3. As the Magento file system owner, enter the following command to configure the profiler:

To enable the profiler using type html and create a flagfile:

Enable database queries profiler

The Magento database profiler displays all queries executed on a page, including the time for each query and what parameters were executed.

Modify /app/etc/env.php to add the following in db connection default setting:

To configure the output, add the following after the $bootstrap->run($app); line in your <Magento Install Directory>/index.php file:

That’s how it will display on every page.

queries-profiler