public function afterQuery($event, $connection) { $this->dbProfiler->stopProfile(); $this->queries[] = ['query' => $connection->getSQLStatement(), 'time' => $this->dbProfiler->getTotalElapsedSeconds()]; $this->dbProfiler->reset(); ++$this->counter; }
public function __destruct() { if ($this->_logger && $this->_profiler) { $this->_logger->log(sprintf('Total SQL execution time (%d queries): %.4f sec.', $this->_profiler->getNumberTotalStatements(), round($this->_profiler->getTotalElapsedSeconds(), 4)), $this->_priority); $this->_logger->commit(); } }
/** * Get html for sql section. * * @param \Phalcon\Db\Profiler $dbProfiler Database profiler. * @param int $totalSqlStatements Total count. * * @return string */ private function _getHtmlSql($dbProfiler, $totalSqlStatements) { $html = 'No Sql'; $dbProfiles = $dbProfiler->getProfiles(); if (!empty($dbProfiles)) { $longestQuery = ''; $longestQueryTime = 0; $html = $this->_viewRenderElement('Total count', $totalSqlStatements, null, true); $html .= $this->_viewRenderElement('Total time', round($dbProfiler->getTotalElapsedSeconds() * 1000, 4), null, true); $html .= $this->_viewRenderElement('Longest query', '<span class="code">%s</span> (%s ms)<br/>', null, true); foreach ($dbProfiles as $profile) { if ($profile->getTotalElapsedSeconds() > $longestQueryTime) { $longestQueryTime = $profile->getTotalElapsedSeconds(); $longestQuery = $profile->getSQLStatement(); } $html .= $this->_viewRenderElement('SQL', $profile->getSQLStatement()); $html .= $this->_viewRenderElement('Time', round($profile->getTotalElapsedSeconds() * 1000, 4) . ' ms<br/>', null, true); } $html = sprintf($html, $longestQuery, round($longestQueryTime * 1000, 4)); } return $html; }