]> git.mxchange.org Git - core.git/commitdiff
Several debug things (e.g. for timing) added
authorRoland Häder <roland@mxchange.org>
Tue, 8 Nov 2011 05:02:00 +0000 (05:02 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 8 Nov 2011 05:02:00 +0000 (05:02 +0000)
- Startup time (in miliseconds) is now being stored "genericly"
- getPrintableExecutionTime() added which will output the currently needed time
  in seconds to execute until that line
- Things like "\r", "\n" and "\t" replaced with chr(x) to (hopefully) speedup
  things

inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/debug/class_DebugConsoleOutput.php
inc/classes/main/debug/class_DebugErrorLogOutput.php
inc/classes/main/factories/class_BaseFactory.php
inc/classes/main/helper/class_BaseHelper.php
inc/classes/main/io/class_FileIoStream.php
inc/classes/main/output/class_ConsoleOutput.php
inc/classes/main/rng/class_RandomNumberGenerator.php
inc/classes/main/template/class_BaseTemplateEngine.php
inc/config.php

index bdc442eee3ad0b3ea47207a2eed6ff01bf56ea44..479e8a7a6e8b18fd8a4c80868fc1fc02ad491eda 100644 (file)
@@ -251,7 +251,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
        const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x040;
 
-       // Hexadecimal->Decimal translation array
+       /**
+        * Hexadecimal->Decimal translation array
+        */
        private static $hexdec = array(
                '0' => 0,
                '1' => 1,
@@ -271,7 +273,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                'f' => 15
        );
 
-       // Decimal->hexadecimal translation array
+       /**
+        * Decimal->hexadecimal translation array
+        */
        private static $dechex = array(
                 0 => '0',
                 1 => '1',
@@ -291,6 +295,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                15 => 'f'
        );
 
+       /**
+        * Startup time in miliseconds
+        */
+       private static $startupTime = 0;
+
        /**
         * Protected super constructor
         *
@@ -306,10 +315,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        // ... because registries doesn't need to be configured
                        $this->setConfigInstance(FrameworkConfiguration::getInstance());
                } // END - if
+
+               // Is the startup time set? (0 cannot be true anymore)
+               if (self::$startupTime == 0) {
+                       // Then set it
+                       self::$startupTime = microtime(true);
+               } // END - if
        }
 
        /**
-        * Destructor reached...
+        * Destructor for all classes
         *
         * @return      void
         */
@@ -891,9 +906,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        protected function replaceControlCharacters ($str) {
                // Replace them
                $str = str_replace(
-                       "\r", '[r]', str_replace(
-                       "\n", '[n]', str_replace(
-                       "\t", '[t]',
+                       chr(13), '[r]', str_replace(
+                       chr(10), '[n]', str_replace(
+                       chr(9) , '[t]',
                        $str
                )));
 
@@ -980,7 +995,14 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } else {
                        // Put directly out
                        if ($doPrint === true) {
-                               print($message);
+                               // Are debug times enabled?
+                               if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
+                                       // Output it first
+                                       print($this->getPrintableExecutionTime());
+                               } // END - if
+
+                               // Print message
+                               print($message . chr(10));
                        } else {
                                // DO NOT REWRITE THIS TO app_die() !!!
                                die($message);
@@ -1050,7 +1072,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } // END - if
 
                // Add line number to the code
-               foreach (explode("\n", $phpCode) as $lineNo => $code) {
+               foreach (explode(chr(10), $phpCode) as $lineNo => $code) {
                        // Add line numbers
                        $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
                                ($lineNo + 1),
@@ -1916,6 +1938,31 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
                return $cacheKey;
        }
+
+       /**
+        * Getter for startup time in miliseconds
+        *
+        * @return      $startupTime    Startup time in miliseconds
+        */
+       protected function getStartupTime () {
+               return self::$startupTime;
+       }
+
+       /**
+        * "Getter" for a printable currently execution time in nice braces
+        *
+        * @return      $executionTime  Current execution time in nice braces
+        */
+       protected function getPrintableExecutionTime () {
+               // Caculate the execution time
+               $executionTime = microtime(true) - $this->getStartupTime();
+
+               // Pack it in nice braces
+               $executionTime = sprintf('[ %01.4f ] ', $executionTime);
+
+               // And return it
+               return $executionTime;
+       }
 }
 
 // [EOF]
index bf6e0980063726a51221acc283bc0f3d45ce8b0c..28d31163251b3d61286d2bb3a9f8f5c591d01c66 100644 (file)
@@ -55,8 +55,14 @@ class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, Output
                // Prepare the output
                $output = trim(html_entity_decode(strip_tags(stripslashes($output))));
 
+               // Are debug times enabled?
+               if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
+                       // Output it first
+                       print($this->getPrintableExecutionTime());
+               } // END - if
+
                // And print it out...
-               printf("%s\n", $output);
+               printf('%s%s', $output, chr(10));
        }
 
        /**
index c5c337676a84e5a5667b462ae9ec863982a46066..3fa1f719d5c34cf2957bd488f4b51971f350b4ed 100644 (file)
@@ -53,15 +53,19 @@ class DebugErrorLogOutput extends BaseFrameworkSystem implements Debugger, Outpu
         */
        public final function outputStream ($output) {
                // Split multiple lines into and array to put them out line-by-line
-               $errorLines = explode("\n", $output);
+               $errorLines = explode(chr(10), $output);
+
+               // "Walk" through all lines
                foreach ($errorLines as $err) {
+                       // Trim any spaces, \n, \r etc. out
                        $err = trim($err);
+
                        // Log only none-empty lines
                        if (!empty($err)) {
                                // Log this line
                                error_log(html_entity_decode(strip_tags($err)), 0);
-                       }
-               }
+                       } // END - if
+               } // END - foreach
        }
 
        /**
index 3a89bac11fe335d4701061615be7fca82fff954d..24184c56e1199232db6724f9ad1e92d976c47d98 100644 (file)
@@ -59,7 +59,7 @@ class BaseFactory extends BaseFrameworkSystem {
                } // END - if
 
                // Count it up again
-               //* NOISY-DEBUG: */ print __METHOD__.': className=' .$className . "\n";
+               //* NOISY-DEBUG: */ print __METHOD__.': className=' .$className . chr(10);
                self::$objectCounters[$className]++;
        }
 
index e360adc6229f9a97f6e5a65a49f83b45bee6e986..143923c6b6303c5dcf646e2e0b2103864aa57945 100644 (file)
@@ -87,7 +87,7 @@ class BaseHelper extends BaseFrameworkSystem {
         * @return      void
         */
        protected final function addContent ($newContent) {
-               $this->content .= (string) trim($newContent) . "\n";
+               $this->content .= (string) trim($newContent) . chr(10);
        }
 
        /**
@@ -391,7 +391,7 @@ class BaseHelper extends BaseFrameworkSystem {
                // Is header content there?
                if (isset($this->groups['header'])) {
                        // Then add it
-                       $content .= $this->groups['header']['content'] . "\n";
+                       $content .= $this->groups['header']['content'] . chr(10);
                } // END - if
 
                // Initiate content
@@ -419,7 +419,7 @@ class BaseHelper extends BaseFrameworkSystem {
                // Is footer content there?
                if (isset($this->groups['footer'])) {
                        // Then add it
-                       $content .= $this->groups['footer']['content'] . "\n";
+                       $content .= $this->groups['footer']['content'] . chr(10);
                } // END - if
 
                // Return it
index 66eeb668c95eeb19b2438d17db9bdf875c74addf..98af0428497b72caa043638f1b383d200d14ff0b 100644 (file)
@@ -165,7 +165,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                $fileInstance->closeFile();
 
                // Convert it into an array
-               $inputBuffer = explode("\n", $inputBuffer);
+               $inputBuffer = explode(chr(10), $inputBuffer);
 
                // Now process the read lines and verify it's content
                foreach ($inputBuffer as $rawLine) {
@@ -209,7 +209,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                                $readData .= $data[0];
                        } else {
                                // Other raw lines than header/data tagged lines and re-add the new-line char
-                               $readData .= $rawLine . "\n";
+                               $readData .= $rawLine . chr(10);
                        }
                } // END - foreach
 
index 6a3e88f7b9c502df8394bebdf9a1308b79f5bbee..af45aaad14fe423ed83990ee7cd624d2a051fe85 100644 (file)
@@ -87,7 +87,7 @@ class ConsoleOutput extends BaseFrameworkSystem implements OutputStreamer {
         * @return      void
         */
        public final function output ($outStream = false) {
-               print trim($outStream) . "\n";
+               print trim($outStream) . chr(10);
        }
 }
 
index c92c6bccf0e12954488aa44e11d9e9d58243ba46..0580b87db376c9b974aac8e367d50addadd72908 100644 (file)
@@ -91,7 +91,7 @@ class RandomNumberGenerator extends BaseFrameworkSystem {
                $this->extraNumber = ($this->prime * $this->prime / pow(pi(), 2));
 
                // Seed mt_rand()
-               mt_srand((double) sqrt(microtime() * 100000000 * $this->extraNumber));
+               mt_srand((double) sqrt(microtime(true) * 100000000 * $this->extraNumber));
 
                // Set the server IP to cluster
                $serverIp = 'cluster';
index 3e265df6488b99b950e6043a911d4fbe19542753..188caa213d5443b0a6b8ca74899dfae5d1ca1855 100644 (file)
@@ -1510,7 +1510,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function compactContent ($uncompactedContent) {
                // First, remove all tab/new-line/revert characters
-               $compactedContent = str_replace("\t", '', str_replace("\n", '', str_replace("\r", '', $uncompactedContent)));
+               $compactedContent = str_replace(chr(9), '', str_replace(chr(10), '', str_replace(chr(13), '', $uncompactedContent)));
 
                // Then regex all comments like <!-- //--> away
                preg_match_all('/<!--[\w\W]*?(\/\/){0,1}-->/', $compactedContent, $matches);
index feb9eb684f3c598b3072344baa534ecfd7e202d2..441e0caf3043e3538fe73fa3030afd26791e4543 100644 (file)
@@ -326,5 +326,8 @@ $cfg->setConfigEntry('local_file_database_class', 'LocalFileDatabase');
 // CFG: COMPRESSOR-CHANNEL-CLASS
 $cfg->setConfigEntry('compressor_channel_class', 'CompressorChannel');
 
+// CFG: DEBUG-OUTPUT-TIMINGS
+$cfg->setConfigEntry('debug_output_timings', 'N');
+
 // [EOF]
 ?>