From: Roland Häder Date: Tue, 8 Nov 2011 05:02:00 +0000 (+0000) Subject: Several debug things (e.g. for timing) added X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fc5010729854b1f9c9bc60249460d092ea6694b6;p=core.git Several debug things (e.g. for timing) added - 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 --- diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index bdc442ee..479e8a7a 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -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("%s: %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] diff --git a/inc/classes/main/debug/class_DebugConsoleOutput.php b/inc/classes/main/debug/class_DebugConsoleOutput.php index bf6e0980..28d31163 100644 --- a/inc/classes/main/debug/class_DebugConsoleOutput.php +++ b/inc/classes/main/debug/class_DebugConsoleOutput.php @@ -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)); } /** diff --git a/inc/classes/main/debug/class_DebugErrorLogOutput.php b/inc/classes/main/debug/class_DebugErrorLogOutput.php index c5c33767..3fa1f719 100644 --- a/inc/classes/main/debug/class_DebugErrorLogOutput.php +++ b/inc/classes/main/debug/class_DebugErrorLogOutput.php @@ -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 } /** diff --git a/inc/classes/main/factories/class_BaseFactory.php b/inc/classes/main/factories/class_BaseFactory.php index 3a89bac1..24184c56 100644 --- a/inc/classes/main/factories/class_BaseFactory.php +++ b/inc/classes/main/factories/class_BaseFactory.php @@ -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]++; } diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php index e360adc6..143923c6 100644 --- a/inc/classes/main/helper/class_BaseHelper.php +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -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 diff --git a/inc/classes/main/io/class_FileIoStream.php b/inc/classes/main/io/class_FileIoStream.php index 66eeb668..98af0428 100644 --- a/inc/classes/main/io/class_FileIoStream.php +++ b/inc/classes/main/io/class_FileIoStream.php @@ -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 diff --git a/inc/classes/main/output/class_ConsoleOutput.php b/inc/classes/main/output/class_ConsoleOutput.php index 6a3e88f7..af45aaad 100644 --- a/inc/classes/main/output/class_ConsoleOutput.php +++ b/inc/classes/main/output/class_ConsoleOutput.php @@ -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); } } diff --git a/inc/classes/main/rng/class_RandomNumberGenerator.php b/inc/classes/main/rng/class_RandomNumberGenerator.php index c92c6bcc..0580b87d 100644 --- a/inc/classes/main/rng/class_RandomNumberGenerator.php +++ b/inc/classes/main/rng/class_RandomNumberGenerator.php @@ -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'; diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index 3e265df6..188caa21 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -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('//', $compactedContent, $matches); diff --git a/inc/config.php b/inc/config.php index feb9eb68..441e0caf 100644 --- a/inc/config.php +++ b/inc/config.php @@ -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] ?>