Created
December 13, 2016 08:15
-
-
Save kandy/4e07735185dfdfe30cb58eba5cc87ece to your computer and use it in GitHub Desktop.
db profiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add to bootstrap.php | |
register_shutdown_function(function (){ | |
if (strpos(@$_SERVER['HTTP_ACCEPT'], 'text/html') !== false) { | |
/** @var \Magento\Framework\App\Resource $adapter */ | |
$adapter = \Magento\Framework\App\ObjectManager::getInstance() | |
->get('Magento\Framework\App\ResourceConnection'); | |
// composer.phar require "jdorn/sql-formatter:1.3.*@dev" | |
// require_once '/home/user/.composer/vendor/jdorn/sql-formatter/lib/SqlFormatter.php'; | |
/** @var Zend_Db_Profiler $profiler */ | |
$profiler = $adapter->getConnection('read')->getProfiler(); | |
if ($profiler->getEnabled()) { | |
echo "<table cellpadding='0' cellspacing='0' border='0'>"; | |
echo '<tr><th>', $profiler->getTotalElapsedSecs(), 's ','</th><th>', $profiler->getTotalNumQueries() , 'queries', '</th><th>', microtime(1) - $_SERVER['REQUEST_TIME_FLOAT'], '</th></tr>'; | |
foreach ($profiler->getQueryProfiles() as $query) { | |
/** @var Zend_Db_Profiler_Query $query*/ | |
echo '<tr>'; | |
echo '<td>', number_format(1000 * $query->getElapsedSecs(), 2), 'ms', '</td>'; | |
echo '<td>', $query->getQuery(), '</td>'; | |
echo '</tr>'; | |
} | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'db' => | |
array ( | |
'table_prefix' => '', | |
'connection' => | |
array ( | |
'default' => | |
array ( | |
'host' => 'localhost', | |
'dbname' => 'magento2', | |
'username' => 'root', | |
'password' => '', | |
'model' => 'mysql4', | |
'initStatements' => 'SET NAMES utf8;', | |
'active' => '1', | |
'profiler' =>[ 'enabled' =>1] // << add this line | |
), | |
), | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment