Enable Magento_Profiler by SetEnv
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.)
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 ...
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?
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();
+}
- Enable the profiler using SetEnv.
- 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.
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.
Thanks!