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 bdc442e..479e8a7 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 bf6e098..28d3116 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 c5c3376..3fa1f71 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 3a89bac..24184c5 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 e360adc..143923c 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 66eeb66..98af042 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 6a3e88f..af45aaa 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 c92c6bc..0580b87 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 3e265df..188caa2 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 feb9eb6..441e0ca 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]
 ?>