Пример #1
0
 /**
  * Get formatted statistics message
  *
  * @param string $type Type of query
  * @param string $sql
  * @param array $bind
  * @param \Zend_Db_Statement_Pdo|null $result
  * @return string
  * @throws \Zend_Db_Statement_Exception
  */
 public function getStats($type, $sql, $bind = [], $result = null)
 {
     $message = '## ' . getmypid() . ' ## ';
     $nl = "\n";
     $time = sprintf('%.4f', microtime(true) - $this->timer);
     if (!$this->logAllQueries && $time < $this->logQueryTime) {
         return '';
     }
     switch ($type) {
         case self::TYPE_CONNECT:
             $message .= 'CONNECT' . $nl;
             break;
         case self::TYPE_TRANSACTION:
             $message .= 'TRANSACTION ' . $sql . $nl;
             break;
         case self::TYPE_QUERY:
             $message .= 'QUERY' . $nl;
             $message .= 'SQL: ' . $sql . $nl;
             if ($bind) {
                 $message .= 'BIND: ' . var_export($bind, true) . $nl;
             }
             if ($result instanceof \Zend_Db_Statement_Pdo) {
                 $message .= 'AFF: ' . $result->rowCount() . $nl;
             }
             break;
     }
     $message .= 'TIME: ' . $time . $nl;
     if ($this->logCallStack) {
         $message .= 'TRACE: ' . Debug::backtrace(true, false) . $nl;
     }
     $message .= $nl;
     return $message;
 }
Пример #2
0
 /**
  *
  * {@inheritdoc}
  */
 public function logStats($type, $sql, $bind = [], $result = null)
 {
     $log = [];
     //Change approach to "around" and then break return string into MySQL columns
     //  as right now we cannot get time of query execution
     //Problem remains how to pass the YES/NO on time and full backtrace
     // maybe its best to simply record all and then remove it from __destruct
     // as in __destruct we have access to helper
     // trace log and all log simply kill the database size, thus we need them as config
     self::$counter++;
     \Magento\Framework\Profiler::start('foggyline_sentinel_logStats_' . self::$counter);
     $log['type'] = $type;
     $log['time'] = sprintf('%.4f', microtime(true) - $this->timer);
     $log['sql'] = $sql;
     $log['bind'] = var_export($bind, true);
     if ($result instanceof \Zend_Db_Statement_Pdo) {
         $log['row_count'] = $result->rowCount();
     }
     /**
      * When backtrace is assigned, it consumes roughly:
      *  - 0.3 seconds on homepage,
      *  - 0.5 seconds on admin product page
      *
      * Problem here is that we cannot control Debug::backtrace via Magento admin config, so we have to leave it
      * either running or comment it out. If we leave it running, we can add some minor tome to overhead but we
      * can then use $this->helper->getQueryLogCallStack(); to either save it in database or not.
      *
      * Backtrace adds enormous amount of data to database. We are talking MB of data just in 3-4 page requests.
      * Thus it is highly important be very careful with full log stack (backtrace) loging to dataabse.
      */
     $log['backtrace'] = \Magento\Framework\Debug::backtrace(true, false);
     $this->queryLogs[] = $log;
     \Magento\Framework\Profiler::stop('foggyline_sentinel_logStats_' . self::$counter);
 }
Пример #3
0
 /**
  * Logging debug information
  *
  * @param int $type
  * @param string $sql
  * @param array $bind
  * @param \Zend_Db_Statement_Pdo $result
  * @return $this
  */
 protected function _debugStat($type, $sql, $bind = array(), $result = null)
 {
     if (!$this->_debug) {
         return $this;
     }
     $code = '## ' . getmypid() . ' ## ';
     $nl = "\n";
     $time = sprintf('%.4f', microtime(true) - $this->_debugTimer);
     if (!$this->_logAllQueries && $time < $this->_logQueryTime) {
         return $this;
     }
     switch ($type) {
         case self::DEBUG_CONNECT:
             $code .= 'CONNECT' . $nl;
             break;
         case self::DEBUG_TRANSACTION:
             $code .= 'TRANSACTION ' . $sql . $nl;
             break;
         case self::DEBUG_QUERY:
             $code .= 'QUERY' . $nl;
             $code .= 'SQL: ' . $sql . $nl;
             if ($bind) {
                 $code .= 'BIND: ' . var_export($bind, true) . $nl;
             }
             if ($result instanceof \Zend_Db_Statement_Pdo) {
                 $code .= 'AFF: ' . $result->rowCount() . $nl;
             }
             break;
     }
     $code .= 'TIME: ' . $time . $nl;
     if ($this->_logCallStack) {
         $code .= 'TRACE: ' . Debug::backtrace(true, false) . $nl;
     }
     $code .= $nl;
     $this->_debugWriteToFile($code);
     return $this;
 }