/**
  * Returns all the db queries made
  *
  * @return array
  */
 public function getQueries()
 {
     if ($this->_profiler->getQueryProfiles() != null) {
         return $this->_profiler->getQueryProfiles();
     }
     return array();
 }
Exemple #2
0
 protected function _initProfiler()
 {
     $this->bootstrap('db');
     $profiler = new Zend_Db_Profiler('All DB Queries');
     $profiler->setEnabled(true);
     $this->getResource('db')->setProfiler($profiler);
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 /**
  * 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);
 }
 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()];
     }
 }
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     $profile = $this->getQueryProfile($queryId);
     $this->_totalElapsedTime += $profile->getElapsedSecs();
     $this->_logger->info(implode(' ', array((string) round($profile->getElapsedSecs(), 5), $profile->getQuery(), ($params = $profile->getQueryParams()) ? implode(' ', $params) : null)));
 }
Exemple #7
0
 /**
  * Roll back a transaction and return to autocommit mode.
  *
  * @return Zend_Db_Adapter_Abstract
  */
 public function rollBack()
 {
     $this->_connect();
     $q = $this->_profiler->queryStart('rollback', Zend_Db_Profiler::TRANSACTION);
     $this->_rollBack();
     $this->_profiler->queryEnd($q);
     return $this;
 }
Exemple #8
0
 /**
  * Intercept the query end and log the profiling data.
  *
  * @param  integer $queryId
  * @throws Zend_Db_Profiler_Exception
  * @return void
  */
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     if (!$this->getEnabled() || $state == self::IGNORED) {
         return;
     }
     $profile = $this->getQueryProfile($queryId);
     echo (string) round($profile->getElapsedSecs(), 5) . PHP_EOL . $profile->getQuery() . PHP_EOL . (($params = $profile->getQueryParams()) ? $params : null) . PHP_EOL;
 }
Exemple #9
0
 /**
  * Obsługa rozpoczęcia kwerendy .
  * 
  * @param type $queryText
  * @param type $queryType
  * @return type 
  */
 public function queryStart($queryText, $queryType = null)
 {
     $queryId = parent::queryStart($queryText);
     if ($this->getEnabled()) {
         $message = "SQL({$queryId}): " . $queryText;
         // log the message as INFO message
         $this->_log->info($message);
     }
     return $queryId;
 }
Exemple #10
0
 /**
  * Intercept the query end and log the profiling data.
  *
  * @param  integer $queryId
  * @throws \Zend_Db_Profiler_Exception
  * @return void
  */
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     if (!$this->getEnabled() || $state == self::IGNORED) {
         return;
     }
     $profile = $this->getQueryProfile($queryId);
     $this->_totalElapsedTime += $profile->getElapsedSecs();
     $this->_totalQueries++;
     $logEntry = $profile->getQuery() . " | " . implode(",", $profile->getQueryParams());
     \Logger::debug($logEntry, ["connection" => $this->getConnectionId(), "queryNum" => $this->_totalQueries, "time" => (string) round($profile->getElapsedSecs(), 5)]);
     $this->queries[] = array("time" => $profile->getElapsedSecs(), "query" => $profile->getQuery() . " | " . implode(",", $profile->getQueryParams()));
 }
Exemple #11
0
 /**
  * Intercept the query end and log the profiling data.
  *
  * @param  integer $queryId
  * @throws Zend_Db_Profiler_Exception
  * @return void
  */
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     if (!$this->getEnabled() || $state == self::IGNORED) {
         return;
     }
     // get profile of the current query
     $profile = $this->getQueryProfile($queryId);
     // update totalElapsedTime counter
     $this->_totalElapsedTime += $profile->getElapsedSecs();
     // create the message to be logged
     $message = "\nElapsed Secs: " . round($profile->getElapsedSecs(), 5) . "\n";
     $message .= "Query: " . $profile->getQuery() . "\n";
     // log the message as INFO message
     $this->_log->info($message);
 }
 public function queryEnd($queryId)
 {
     $result = parent::queryEnd($queryId);
     if ($result == self::STORED) {
         $profile = $this->getLastQueryProfile();
         /* @var $profile Zend_Db_Profiler_Query */
         if (!isset($this->_types[$profile->getQueryType()])) {
             $this->_types[$profile->getQueryType()] = 0;
         }
         $this->_types[$profile->getQueryType()]++;
         $query = $profile->getQuery();
         $data = array('query' => $query, 'elapsed' => $profile->getElapsedSecs(), 'params' => $profile->getQueryParams());
         $data = json_encode($data);
         $queue = Mage::getStoreConfig(Eschrade_PubSubLogger_Model_Observer::SYSTEM_CONFIG_ENDPOINT) . '_pslogger_sql';
         $this->_observer->publish($queue, $data);
     }
 }
 public function __construct($enable)
 {
     parent::__construct($enable);
     $writer = new Kwf_Log_Writer_Stream(APP_PATH . '/querylog', 'w');
     $writer->setFormatter(new Zend_Log_Formatter_Simple("%message%\n"));
     $this->_logger = new Zend_Log($writer);
     /*
     foreach (new DirectoryIterator('/tmp') as $item) {
         if (substr($item->getFilename(), 0, 9) == 'querylog.') {
             $time = (int)(substr($item->getFilename(), 9, -2));
             if (time()-$time > 15*60) {
                 @unlink($item->getPathname());
             }
         }
     }
     */
 }
Exemple #14
0
 /**
  * Intercept the query end and log the profiling data.
  *
  * @param  integer $queryId
  * @throws Zend_Db_Profiler_Exception
  * @return void
  */
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     if (!$this->getEnabled() || $state == self::IGNORED) {
         return;
     }
     $profile = $this->getQueryProfile($queryId);
     $this->_totalElapsedTime += $profile->getElapsedSecs();
     $logEntry = "DB Query: " . (string) round($profile->getElapsedSecs(), 5) . " | " . $profile->getQuery() . " | " . implode(",", $profile->getQueryParams());
     Logger::debug($logEntry);
     if (!empty($_REQUEST["pimcore_dbprofile"])) {
         if (!is_resource($this->logFile)) {
             $logFile = dirname(PIMCORE_LOG_DEBUG) . "/dbprofile-" . $_REQUEST["pimcore_dbprofile"] . ".log";
             file_put_contents($logFile, "");
             $this->logFile = fopen($logFile, "a+");
         }
         fwrite($this->logFile, $logEntry . "\n");
     }
 }
Exemple #15
0
 /**
  * Ends a query. Pass it the handle that was returned by queryStart().
  *
  * @param int $queryId
  * @return string|void
  */
 public function queryEnd($queryId)
 {
     $this->_lastQueryId = null;
     return parent::queryEnd($queryId);
 }
Exemple #16
0
 protected function _initDbProfiler()
 {
     if (APPLICATION_ENV === 'development') {
         if (isset($_GET['_profileSql'])) {
             setcookie('_profileSql', $_GET['_profileSql']);
         }
         if (isset($_COOKIE['_profileSql'])) {
             $profiler = new Zend_Db_Profiler();
             $profiler->setEnabled(true);
             Zend_Db_Table_Abstract::getDefaultAdapter()->setProfiler($profiler);
             register_shutdown_function(array('Tools_System_Tools', 'sqlProfiler'));
         }
     }
 }
Exemple #17
0
/**
 * Get DB profiler
 *
 * @param string $connectionName
 * @return mixed|Zend_Db_Profiler
 */
function profiler($connectionName = 'core_read')
{
    if (false == ($profiler = Mage::registry('profiler'))) {
        /** @var $resource Mage_Core_Model_Resource */
        $resource = Mage::getSingleton('core/resource');
        /** @var $db Varien_Db_Adapter_Pdo_Mysql */
        $db = $resource->getConnection($connectionName);
        $profiler = new Zend_Db_Profiler();
        $profiler->setEnabled(1);
        $db->setProfiler($profiler);
        Mage::register('profiler', $profiler);
    }
    return $profiler;
}
 /**
  * Starts a query.  Creates a new query profile object (Zend_Db_Profiler_Query)
  * and returns the "query profiler handle".  Run the query, then call
  * queryEnd() and pass it this handle to make the query as ended and
  * record the time.  If the profiler is not enabled, this takes no
  * action and immediately returns null.
  *
  * @param  string  $queryText   SQL statement
  * @param  integer $queryType   OPTIONAL Type of query, one of the Zend_Db_Profiler::* constants
  * @return integer|null
  */
 public function queryStart($queryText, $queryType = null)
 {
     //        file_put_contents('/var/www/query.log',$queryText."\n\n",FILE_APPEND);
     return parent::queryStart($queryText, $queryType);
 }
Exemple #19
0
 public function getLastQueryProfile()
 {
     $queryId = parent::queryStart($this->_lastQueryText, $this->_lastQueryType);
     return parent::getLastQueryProfile();
 }
Exemple #20
0
 public function queryStart($queryText, $queryType = null)
 {
     Zend_Registry::get('logger')->log("DB QUERY: {$queryText}", Zend_Log::DEBUG);
     return parent::queryStart($queryText, $queryType);
 }
Exemple #21
0
 /**
  * Intercept the query end and log the profiling data.
  *
  * @param  integer $queryId
  * @throws Zend_Db_Profiler_Exception
  * @return void
  */
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     if (!$this->getEnabled() || $state == self::IGNORED) {
         return;
     }
     $this->_message->setDestroy(false);
     $profile = $this->getQueryProfile($queryId);
     $this->_totalElapsedTime += $profile->getElapsedSecs();
     $this->_message->addRow(array((string) round($profile->getElapsedSecs(), 5), $profile->getQuery(), ($params = $profile->getQueryParams()) ? $params : null));
     $this->updateMessageLabel();
 }
Exemple #22
0
 /**
  * @return null|\Zend_Db_Profiler|\Zend_Db_Profiler_Firebug
  */
 protected static function initDbProfiler()
 {
     // No profile should be enabled on live environment
     if (Constants::ENV_LIVE == APPLICATION_ENV) {
         return null;
     }
     $profiler = null;
     $options = isset(self::$config['resources']['profiler']) ? self::$config['resources']['profiler'] : array();
     $enabled = isset($options['enabled']) && $options['enabled'] == 1;
     if ($enabled) {
         if (isset($options['type']) && $options['type'] == 'firebug') {
             $profiler = new \Zend_Db_Profiler_Firebug('DB Queries');
         } else {
             $profiler = new \Zend_Db_Profiler();
         }
         $profiler->setEnabled(true);
     }
     return $profiler;
 }
 /**
  * Empty constructor to make it parameterless.
  */
 public function __construct()
 {
     $profiler = new Zend_Db_Profiler();
     $profiler->setEnabled(true);
     $this->setProfiler($profiler);
 }
Exemple #24
0
    /**
     * 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>';
    }