[TASK] Optimize usage of debug_backtrace() 08/44808/3
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 19 Nov 2015 20:50:54 +0000 (21:50 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Mon, 30 Nov 2015 15:53:04 +0000 (16:53 +0100)
Save performance by only fetching what is needed.

Change-Id: I89710c2e7bcdb32e4b5864a629f259eedd176a2b
Resolves: #71707
Releases: master
Reviewed-on: https://review.typo3.org/44808
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Database/DatabaseConnection.php
typo3/sysext/core/Classes/Utility/DebugUtility.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/dbal/Classes/Database/DatabaseConnection.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

index 94977a2..5b3aabf 100644 (file)
@@ -8024,7 +8024,7 @@ class DataHandler
     protected function getOuterMostInstance()
     {
         if (!isset($this->outerMostInstance)) {
-            $stack = array_reverse(debug_backtrace());
+            $stack = array_reverse(debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS));
             foreach ($stack as $stackItem) {
                 if (isset($stackItem['object']) && $stackItem['object'] instanceof DataHandler) {
                     $this->outerMostInstance = $stackItem['object'];
index f74155d..830d010 100644 (file)
@@ -1859,19 +1859,13 @@ class DatabaseConnection
         if ($res !== false) {
             return true;
         }
-        $msg = 'Invalid database result detected';
-        $trace = debug_backtrace();
+        $trace = debug_backtrace(0);
         array_shift($trace);
-        $cnt = count($trace);
-        for ($i = 0; $i < $cnt; $i++) {
-            // Complete objects are too large for the log
-            if (isset($trace['object'])) {
-                unset($trace['object']);
-            }
-        }
-        $msg .= ': function TYPO3\\CMS\\Core\\Database\\DatabaseConnection->' . $trace[0]['function'] . ' called from file ' . substr($trace[0]['file'], (strlen(PATH_site) + 2)) . ' in line ' . $trace[0]['line'];
+        $msg = 'Invalid database result detected: function TYPO3\\CMS\\Core\\Database\\DatabaseConnection->'
+            . $trace[0]['function'] . ' called from file ' . substr($trace[0]['file'], (strlen(PATH_site) + 2))
+            . ' in line ' . $trace[0]['line'] . '.';
         GeneralUtility::sysLog(
-            $msg . '. Use a devLog extension to get more details.',
+            $msg . ' Use a devLog extension to get more details.',
             'core',
             GeneralUtility::SYSLOG_SEVERITY_ERROR
         );
@@ -1884,7 +1878,7 @@ class DatabaseConnection
             if ($this->debug_lastBuiltQuery) {
                 $debugLogData = array('SQL Query' => $this->debug_lastBuiltQuery) + $debugLogData;
             }
-            GeneralUtility::devLog($msg . '.', 'Core/t3lib_db', 3, $debugLogData);
+            GeneralUtility::devLog($msg, 'Core/t3lib_db', 3, $debugLogData);
         }
         return false;
     }
index 0580b71..980646d 100644 (file)
@@ -132,7 +132,7 @@ class DebugUtility
      */
     public static function debugTrail()
     {
-        $trail = debug_backtrace();
+        $trail = debug_backtrace(0);
         $trail = array_reverse($trail);
         array_pop($trail);
         $path = array();
index b1b8b64..0126032 100755 (executable)
@@ -5228,7 +5228,7 @@ Connection: close
         if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog']) {
             return;
         }
-        $trail = debug_backtrace();
+        $trail = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
         if ($trail[1]['type']) {
             $function = new \ReflectionMethod($trail[1]['class'], $trail[1]['function']);
         } else {
index 8f93a4d..0cc2a15 100644 (file)
@@ -3889,10 +3889,8 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection
                 }
             }
             if ($this->conf['debugOptions']['backtrace']) {
-                $backtrace = debug_backtrace();
-                unset($backtrace[0]);
-                // skip this very method :)
-                $data['backtrace'] = array_slice($backtrace, 0, $this->conf['debugOptions']['backtrace']);
+                $backtrace = debug_backtrace(0);
+                $data['backtrace'] = array_slice($backtrace, 1, $this->conf['debugOptions']['backtrace']);
             }
             switch ($function) {
                 case 'exec_INSERTquery':
index 8bfc1d2..b3057fc 100644 (file)
@@ -4376,7 +4376,7 @@ class TypoScriptFrontendController
         if ($reason !== '') {
             $warning = '$TSFE->set_no_cache() was triggered. Reason: ' . $reason . '.';
         } else {
-            $trace = debug_backtrace();
+            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
             // This is a hack to work around ___FILE___ resolving symbolic links
             $PATH_site_real = dirname(realpath(PATH_site . 'typo3')) . '/';
             $file = $trace[0]['file'];