Enable profiling
With Commerce profiling, you can:
-
Enable a built-in profiler.
You can use a built-in profiler with Commerce to perform tasks such as analyzing performance. The nature of profiling depends on the analytical tools that you use. We support multiple formats, including HTML. When you enable the profiler, a
var/profiler.flagfile generates indicating the profiler is enabled and configurations. When disabled, this file is deleted. -
Display dependency graphs on a Commerce page.
A dependency graph is a list of object dependencies and all of their dependencies, and all the dependencies for those dependencies, and so on.
You should be particularly interested in the list of unused dependencies, which are objects that were created because they were requested in some constructor, but were never used (that is, none of their methods were called). As a result, processor time and memory spent to create these dependencies are wasted.
Commerce provides the base functionality in Magento\Framework\Profiler.
You can enable and configure the profiler using a MAGE_PROFILER variable or the command line.
Set MAGE_PROFILER
You can set the value of MAGE_PROFILER in any of the ways discussed in Set the value of bootstrap parameters.
MAGE_PROFILER supports the following values:
-
1to enable a specific profiler’s output.You can use one of the following values to enable a specific profiler:
csvfilewhich usesMagento\Framework\Profiler\Driver\Standard\Output\Csvfile- Any other value (except
2), including an empty value, which usesMagento\Framework\Profiler\Driver\Standard\Output\Html
-
2to enable dependency graphs.Dependency graphs typically display at the bottom of a page. The following figure shows portion of the output:
CLI commands
You can enable or disable the profiler using CLI commands:
dev:profiler:enable <type>enables the profiler withtypeofhtml(default) orcsvfile. When enabled, a flagfilevar/profiler.flagis created.dev:profiler:disabledisables the profiler. When disabled, the flagfilevar/profiler.flagis removed.
To enable dependency graphs, use the variable option.
To enable or disable the profiler:
-
Log in to your Commerce server.
-
Change to your Commerce installation directory.
-
As the file system owner, enable the profiler:
To enable the profiler using type
htmland create a flagfile:code language-bash bin/magento dev:profiler:enable htmlTo enable the profiler using type
csvfileand create a flagfile:code language-bash bin/magento dev:profiler:enable csvfileThe output is saved to
<project-root>/var/log/profiler.csv. Theprofiler.csvis overridden on each page refresh.To disable the profiler and remove the flagfile:
code language-bash bin/magento dev:profiler:disable