本文整理汇总了PHP中Zend_Db_Profiler::getQueryProfiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Db_Profiler::getQueryProfiles方法的具体用法?PHP Zend_Db_Profiler::getQueryProfiles怎么用?PHP Zend_Db_Profiler::getQueryProfiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Db_Profiler
的用法示例。
在下文中一共展示了Zend_Db_Profiler::getQueryProfiles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertDbQuery
public function assertDbQuery($sqlPart, $message = null)
{
$queryProfiles = $this->_profiler->getQueryProfiles();
$this->_test->assertTrue(is_array($queryProfiles), "No database queries were made.");
$ranQuery = false;
if (is_array($sqlPart)) {
$query = $sqlPart[0];
$params = $sqlPart[1];
} else {
$query = $sqlPart;
}
foreach ($queryProfiles as $profile) {
if (strpos($profile->getQuery(), $query) !== false) {
if (isset($params) && $profile->getQueryParams() == $params) {
$ranQuery = true;
break;
} else {
if (!isset($params)) {
$ranQuery = true;
break;
}
}
}
}
$this->_test->assertTrue($ranQuery, $message . PHP_EOL . "Should have run SQL query containing '{$query}'." . (isset($params) ? PHP_EOL . "Should have been passed parameters: " . print_r($params, true) : ''));
}
示例2: getQueries
/**
* Returns all the db queries made
*
* @return array
*/
public function getQueries()
{
if ($this->_profiler->getQueryProfiles() != null) {
return $this->_profiler->getQueryProfiles();
}
return array();
}
示例3: getAllQuerys
private function getAllQuerys()
{
foreach ($this->doctrineProfiler->queries as $query) {
$this->executedQuerys[] = ['sql' => $query['sql'], 'params' => $query['params'], 'execution' => $query['executionMS']];
$this->executeTime += $query['executionMS'];
}
foreach ($this->zendProfiler->getQueryProfiles() as $queryProfile) {
$this->executedQuerys[] = ['sql' => $queryProfile->getQuery(), 'params' => $queryProfile->getQueryParams(), 'execution' => $queryProfile->getElapsedSecs()];
}
}
示例4: _getProfilerMarkup
private function _getProfilerMarkup(Zend_Db_Profiler $profiler)
{
$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();
$longestTime = 0;
$longestQuery = null;
$lines = array();
$html = "<h2>Db Profiler</h2>\n";
$lines[] = "The following queries were executed during the request:";
$profiles = $profiler->getQueryProfiles();
if (!$profiles) {
return $html;
}
foreach ($profiles as $query) {
$sql = $query->getQuery();
$elapsedSecs = $query->getElapsedSecs();
if ($elapsedSecs > $longestTime) {
$longestTime = $query->getElapsedSecs();
$longestQuery = $sql;
}
$lines[] = "[{$elapsedSecs}] {$sql}";
}
$lines[] = 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds';
$lines[] = 'Average query length: ' . $totalTime / $queryCount . ' seconds';
$lines[] = 'Queries per second: ' . $queryCount / $totalTime;
$lines[] = 'Longest query length: ' . $longestTime;
$lines[] = "Longest query: \n" . $longestQuery;
foreach ($lines as $line) {
$html .= '<p>' . $line . '</p>' . "\n";
}
return $html;
}
示例5: getStats
/**
* Get debug information
* @return string - html formated results
*/
public static function getStats($showCacheQueries = true, $showQueries = false, $showAutoloaded = false, $showInclided = false)
{
$str = '';
if (self::$_scriptStartTime) {
$str .= '<b>Time:</b> ' . number_format(microtime(true) - self::$_scriptStartTime, 5) . "sec.<br>\n";
}
$str .= '<b>Memory:</b> ' . number_format(memory_get_usage() / (1024 * 1024), 3) . "mb<br>\n" . '<b>Memory peak:</b> ' . number_format(memory_get_peak_usage() / (1024 * 1024), 3) . "mb<br>\n" . '<b>Includes:</b> ' . sizeof(get_included_files()) . "<br>\n" . '<b>Autoloaded:</b> ' . sizeof(self::$_loadedClasses) . "<br>\n";
if (self::$_dbProfiler) {
$str .= '<b>Queries:</b> ' . self::$_dbProfiler->getTotalNumQueries() . '<br>' . '<b>Queries time:</b> ' . number_format(self::$_dbProfiler->getTotalElapsedSecs(), 5) . 'sec.<br>';
if ($showQueries) {
$profiles = self::$_dbProfiler->getQueryProfiles();
if (!empty($profiles)) {
foreach ($profiles as $queryProfile) {
$str .= "\n<br> " . $queryProfile->getQuery();
}
}
}
$str .= "<br>\n";
}
if ($showAutoloaded) {
$str .= "<b>Autoloaded:</b>\n<br> " . implode("\n\t <br>", self::$_loadedClasses) . '<br>';
}
if ($showInclided) {
$str .= "<b>Includes:</b>\n<br> " . implode("\n\t <br>", get_included_files());
}
if (!empty(self::$_cacheCores) && self::$_cacheCores) {
$body = '';
$globalCount = array('load' => 0, 'save' => 0, 'remove' => 0, 'total' => 0);
$globalTotal = 0;
foreach (self::$_cacheCores as $name => $cacheCore) {
if (!$cacheCore) {
continue;
}
$count = $cacheCore->getOperationsStat();
$count['total'] = $count['load'] + $count['save'] + $count['remove'];
$globalCount['load'] += $count['load'];
$globalCount['save'] += $count['save'];
$globalCount['remove'] += $count['remove'];
$globalCount['total'] += $count['total'];
$body .= '
<tr align="right">
<td align="left" >' . $name . '</td>
<td>' . $count['load'] . '</td>
<td>' . $count['save'] . '</td>
<td>' . $count['remove'] . '</td>
<td style="border-left:2px solid #000000;">' . $count['total'] . '</td>
</tr>';
}
$body .= '
<tr align="right" style="border-top:2px solid #000000;">
<td align="left" >Total</td>
<td>' . $globalCount['load'] . '</td>
<td>' . $globalCount['save'] . '</td>
<td>' . $globalCount['remove'] . '</td>
<td style="border-left:2px solid #000000;">' . $globalCount['total'] . '</td>
</tr>';
$str .= '<div style=" padding:1px;"> <center><b>Cache</b></center>
<table cellpadding="2" cellspacing="2" border="1" style="font-size:10px;">
<tr style="background-color:#cccccc;font-weight:bold;">
<td>Name</td>
<td>Load</td>
<td>Save</td>
<td>Remove</td>
<td style="border-left:2px solid #000000;">Total</td>
</tr>
' . $body . '
</table>
</div>';
}
return '<div id="debugPanel" style="position:fixed;font-size:12px;left:10px;bottom:10px;overflow:auto;max-height:300px;padding:5px;background-color:#ffffff;z-index:1000;border:1px solid #cccccc;">' . $str . ' <center><a href="javascript:void(0)" onClick="document.getElementById(\'debugPanel\').style.display = \'none\'">close</a></center></div>';
}