Last active
January 18, 2016 09:10
-
-
Save atishgoswami/03ed44423ff371dd7761 to your computer and use it in GitHub Desktop.
Magento2 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 | |
//app/etc/env.php | |
//Add following to default connection config array | |
[ | |
'profiler' => [ | |
'class' => '\Magento\Framework\DB\Profiler', | |
'enabled' => true, | |
], | |
] |
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
//After the index.php code add this | |
/** @var \Magento\Framework\App\ResourceConnection $res */ | |
$res = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\App\ResourceConnection'); | |
/** @var Magento\Framework\DB\Profiler $profiler */ | |
$profiler = $res->getConnection('read')->getProfiler(); | |
echo "<table cellpadding='0' cellspacing='0' border='1'>"; | |
echo "<tr>"; | |
echo "<th>Time <br/>[Total Time: ".$profiler->getTotalElapsedSecs()." secs]</th>"; | |
echo "<th>SQL [Total: ".$profiler->getTotalNumQueries()." queries]</th>"; | |
echo "<th>Query Params</th>"; | |
echo "</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 '<td>', json_encode($query->getQueryParams()), '</td>'; | |
echo '</tr>'; | |
} | |
echo "</table>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment