Magento 2 : What is profiler, what is it's purpose and how can it be used?

We can use a built-in profiler with Magento to perform tasks such as analyzing performance.

It can tell us in intricate detail which blocks of code are used in the loading of a slow page, and how long it takes each block to complete its task.

The nature of profiling depends on the analytical tools we use. Currently, Magento supports multiple formats like HTML, CSV or Firebug.

To enable profiler, we just need to add a SetEnv MAGE_PROFILER "html" to .htaccess. We can also use "csvfile" or "firebug" instead of "html". In case of "csvfile", you can find the report in var/log dir.

Now if we go to any of the front facing pages, including the home page, at the bottom will be the profiler output.

enter image description here

The columns are as follows:

  • Timer Id: This gives the name of the block of code being executed
  • Time: The time it took to complete in seconds
  • Avg: The average time it took to complete in seconds
  • Cnt: Short for Count. This represents the number of times this individual block ran to generate the output required
  • Emalloc: The amount of memory PHP ( the programming language on which Magento runs) assigned to this single operation. This is again represented in bytes.
  • RealMem: The actual amount of memory used to perform the operation.

Apart from this basic MAGE_PROFILER, M2 also provides a database profiler to debug DB operations as well. Kindly refer to below links for more details about its configurations.

http://devdocs.magento.com/guides/v2.0/config-guide/db-profiler/db-profiler.html https://magento.stackexchange.com/a/97024