打开Profiler先切找到developer模式,.htaccess

SetEnv MAGE_MODE developer

查看内存及时间资源使用情况

.htaccess 文件设定

SetEnv MAGE_PROFILER html

这里查看到的结果中,Timer Id 对应如下代码的 $timerId:

\Magento\Framework\Profiler::start( $timerId );
\Magento\Framework\Profiler::stop( $timerId );

查看数据库资源使用情况

app/etc/env.php 配置文件中,在数据库设置中添加如下设定

'profiler' => [
    'class' => '\Magento\Framework\DB\Profiler',
    'enabled' => true
]

比如

'db' => [
    'table_prefix' => '',
    'connection' => [
        'default' => [
            'host' => 'localhost',
            'dbname' => 'ma2_foreverplay_bruce',
            'username' => 'root',
            'password' => '',
            'active' => '1',
            'profiler' => [
                'class' => '\Magento\Framework\DB\Profiler',
                'enabled' => true
            ],
        ],
    ],
]

index.php 文件末尾添加

/** @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>";

参考文档

http://devdocs.magento.com/gu...
http://devdocs.magento.com/gu...
http://devdocs.magento.com/gu...


猫之良品
2.5k 声望139 粉丝

资深Drupal, magento与Joomla


引用和评论

0 条评论