|
| 1 | +--- |
| 2 | +group: config-guide |
| 3 | +title: Enable profiling (MAGE_PROFILER) |
| 4 | +version: 2.2 |
| 5 | +github_link: config-guide/bootstrap/mage-profiler.md |
| 6 | +functional_areas: |
| 7 | + - Configuration |
| 8 | + - System |
| 9 | + - Setup |
| 10 | +--- |
| 11 | + |
| 12 | +Magento profiling enables you to: |
| 13 | + |
| 14 | +- Enable a built-in profiler. |
| 15 | + |
| 16 | + You can use a built-in profiler with Magento to perform tasks such as analyzing performance. The nature of profiling depends on the analytical tools you use. We support multiple formats, including HTML. When you enable the profiler, a `var/profiler.flag` file generates indicating the profiler is enabled and configurations. When disabled, this file is deleted. |
| 17 | + |
| 18 | +- Display dependency graphs on a Magento page. A *dependency graph* is a list of object dependencies and all of their all their dependencies, and all the dependencies for those dependencies, and so on. |
| 19 | + |
| 20 | + 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. |
| 21 | + |
| 22 | +Magento provides the base functionality in [Magento\\Framework\\Profiler]({{ site.mage2000url }}lib/internal/Magento/Framework/Profiler.php){:target="_blank"}. |
| 23 | + |
| 24 | +You can enable and configure the profiler using a [MAGE_PROFILER](#variable) variable or the [command line](#cli). |
| 25 | + |
| 26 | +## Set MAGE_PROFILER {#variable} |
| 27 | + |
| 28 | +You can set the value of `MAGE_PROFILER` in any of the ways discussed in [Set the value of bootstrap parameters]({{ page.baseurl }}/config-guide/bootstrap/magento-how-to-set.html). |
| 29 | + |
| 30 | +`MAGE_PROFILER` supports the following values: |
| 31 | + |
| 32 | +- `1` to enable a specific profiler's output. |
| 33 | + |
| 34 | + You can also use one of the following values to enable a specific profiler: |
| 35 | + |
| 36 | + - `csvfile` which uses [Magento\\Framework\\Profiler\\Driver\\Standard\\Output\\Csvfile]({{ site.mage2000url }}lib/internal/Magento/Framework/Profiler/Driver/Standard/Output/Csvfile.php){:target="_blank"} |
| 37 | + - Any other value (except `2`), including an empty value, which uses [Magento\\Framework\\Profiler\\Driver\\Standard\\Output\\Html]({{ site.mage2000url }}lib/internal/Magento/Framework/Profiler/Driver/Standard/Output/Html.php){:target="_blank"} |
| 38 | + |
| 39 | +- `2` to enable dependency graphs. |
| 40 | + |
| 41 | + Dependency graphs typically display at the bottom of a page. The following figure shows portion of the output: |
| 42 | + |
| 43 | +  |
| 44 | + |
| 45 | +## CLI commands {#cli} |
| 46 | + |
| 47 | +You can enable or disable the profiler using CLI commands: |
| 48 | + |
| 49 | +- `dev:profiler:enable <type>` enables the profiler with `type` of `html` (default) or `csvfile`. When enabled, a flagfile `var/profiler.flag` is created. |
| 50 | +- `dev:profiler:disable` disables the profiler. When disabled, the flagfile `var/profiler.flag` is removed. |
| 51 | + |
| 52 | +To enable dependency graphs, use the variable option. |
| 53 | + |
| 54 | +To enable or disable the profiler: |
| 55 | + |
| 56 | +1. Log in to your Magento server. |
| 57 | +1. Change to your Magento installation directory. |
| 58 | +1. As the Magento file system owner, enter the following command to configure the profiler: |
| 59 | + |
| 60 | + To enable the profiler using type `html` and create a flagfile: |
| 61 | + |
| 62 | + ```bash |
| 63 | + php bin/magento dev:profiler:enable html |
| 64 | + ``` |
| 65 | + |
| 66 | + To enable the profiler using type `csvfile` and create a flagfile: |
| 67 | + |
| 68 | + ```bash |
| 69 | + php bin/magento dev:profiler:enable csvfile |
| 70 | + ``` |
| 71 | + |
| 72 | + To disable the profiler and remove the flagfile: |
| 73 | + |
| 74 | + ```bash |
| 75 | + php bin/magento dev:profiler:disable |
| 76 | + ``` |
0 commit comments