/** * Assert that the given number of SQL queries were made. * * @param integer $queryCount */ public function assertTotalNumQueries($queryCount, $msg = null) { if (!$msg) { $msg = "Failed asserting that " . (int) $queryCount . " SQL queries were made."; } $this->_test->assertEquals($queryCount, $this->_profiler->getTotalNumQueries(), $msg); }
public function collect(\Enlight_Controller_Action $controller) { $totalQueriesZend = $this->zendProfiler->getTotalNumQueries(); $totalQueriesDoctrine = count($this->doctrineProfiler->queries); $this->executeTime = $this->zendProfiler->getTotalElapsedSecs(); $this->getAllQuerys(); $result = ['db' => ['totalQueries' => $totalQueriesZend + $totalQueriesDoctrine, 'queryTime' => $this->executeTime, 'sqls' => $this->executedQuerys]]; return $result; }
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; }
/** * Returns total number of db query * * @return int */ public function getTotalQuery() { return $this->_profiler->getTotalNumQueries(); }
/** * 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>'; }