Created
November 9, 2017 08:04
-
-
Save phamngsinh/194cbe902b51be2ff01f6d8ddd4bc34f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| First in app/etc/env.php we have to add "profiler" key in the connection array: | |
| return array ( | |
| .... | |
| 'db' => | |
| array ( | |
| ..... | |
| array ( | |
| 'default' => | |
| array ( | |
| .... | |
| 'profiler' => [ | |
| 'class' => '\Magento\Framework\DB\Profiler', | |
| 'enabled' => true, | |
| ], | |
| ), | |
| ), | |
| ), | |
| ...... | |
| ); | |
| ======= | |
| $bootstrap->run($app); //This should be the last line | |
| //After Than add these | |
| /** @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