magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Enable Magento_Profiler by SetEnv

Open mzeis opened this issue 14 years ago • 5 comments

As of Magento 1, you have to edit index.php to activate Magento_Profiler. In my opinion, it should not be necessary to edit any core files.

My proposal is to introduce code to app/bootstrap.php similar to:

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

One or more additional environment variables can allow to register the profile output classes.

Advantages:

  • No need to edit app/bootstrap.php
  • It's easy to set different settings for every environment (dev/stage/live etc.)

mzeis avatar Dec 15 '11 07:12 mzeis

What do you think about having a "index_dev.php" or somethink like this.

As we have it on Symfony or other frameworks. By this way, you don't need to define a var or something else ...

stephpy avatar Mar 13 '12 19:03 stephpy

Hi mzeis --

Currently in app/bootstrap.php the profiler enabling is hard-coded like this:

#Magento_Profiler::enable();
#Magento_Profiler::registerOutput(new Magento_Profiler_Output_Html());
#Magento_Profiler::registerOutput(new Magento_Profiler_Output_Firebug());
#Magento_Profiler::registerOutput(new Magento_Profiler_Output_Csvfile(__DIR__ . '/var/log/profiler.csv'));

How would you suggest to organize the $_SERVER variables, so that we'd have ability to enable any of profilers and not have to hardcode at the same time?

magento-team avatar Mar 13 '12 21:03 magento-team

Hi,

I suggest the following solution:

--- a/app/bootstrap.php
+++ b/app/bootstrap.php
@@ -89,7 +89,6 @@ if (file_exists($classMapPath)) {
     Magento_Autoload::getInstance()->addFilesMap($classMapPath);
 }

-#Magento_Profiler::enable();
-#Magento_Profiler::registerOutput(new Magento_Profiler_Output_Html());
-#Magento_Profiler::registerOutput(new Magento_Profiler_Output_Firebug());
-#Magento_Profiler::registerOutput(new Magento_Profiler_Output_Csvfile(__DIR__ . '/var/log/profiler.csv'));
+if (isset($_SERVER['MAGE_PROFILER_ENABLED'])) {
+    Magento_Profiler::enable();
+}
  1. Enable the profiler using SetEnv.
  2. Configure the profiler output formats in an existing XML file (e.g. local.xml) or in the admin panel. The list of output classes is only accessed when Magento_Profiler::display() is called so you have plenty of time to register output formats when reading the configuration from XML files or core_config_data.

This way profiling gets more comfortable and flexible. You can extend existing profiler formatters or create new ones, you can create a handy configuration interface.

mzeis avatar Mar 15 '12 21:03 mzeis

We have implemented enabling profiler, as well as the output, in bootstrap by specifying MAGE_PROFILER environment variable. The value can be 'csv', 'firebug' or any other for HTML. You'll see it in the source code with next update.

magento-team avatar Mar 20 '12 22:03 magento-team

Thanks!

mzeis avatar Mar 21 '12 04:03 mzeis