From: Niklas Laxström Date: Wed, 27 Jan 2010 17:21:18 +0000 (+0000) Subject: New configuration variables $wgDebugTimestamps and $wgDebugPrintHttpHeaders for contr... X-Git-Tag: 1.31.0-rc.0~38079 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=b1e2b87b95785202af1ca2caf2083acb66d61e79;p=lhc%2Fweb%2Fwiklou.git New configuration variables $wgDebugTimestamps and $wgDebugPrintHttpHeaders for controlling debug output. I find these useful, maybe someone else will too. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3230382630..7d674d7985 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -96,6 +96,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN longer advertised by default (but it still works). * Added $wgMemCachedTimeout to configure connection timeouts for communicating with a memcached server +* New configuration variables $wgDebugTimestamps and $wgDebugPrintHttpHeaders + for controlling debug output. === New features in 1.16 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index e801009eb4..56d60d4823 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1221,6 +1221,16 @@ $wgDebugLogGroups = array(); */ $wgShowDebug = false; +/** + * Prefix debug messages with relative timestamp. Very-poor man's profiler. + */ +$wgDebugTimestamps = false; + +/** + * Print HTTP headers for every request in the debug information. + */ +$wgDebugPrintHttpHeaders = true; + /** * Show the contents of $wgHooks in Special:Version */ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index de8e6d9812..5fa6abff1b 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -343,6 +343,7 @@ function wfDebug( $text, $logonly = false ) { static $recursion = 0; static $cache = array(); // Cache of unoutputted messages + $text = wfDebugTimer() . $text; # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) { @@ -377,6 +378,21 @@ function wfDebug( $text, $logonly = false ) { } } +function wfDebugTimer() { + global $wgDebugTimestamps; + if ( !$wgDebugTimestamps ) return ''; + static $start = null; + + if ( $start === null ) { + $start = microtime( true ); + $prefix = "\n$start"; + } else { + $prefix = sprintf( "%6.4f", microtime( true ) - $start ); + } + + return $prefix . ' '; +} + /** * Send a line giving PHP memory usage. * @param $exact Bool: print exact values instead of kilobytes (default: false) diff --git a/includes/Setup.php b/includes/Setup.php index 6f310c7c60..564226667e 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -180,24 +180,28 @@ $wgRequest = new WebRequest; # Useful debug output if ( $wgCommandLineMode ) { wfDebug( "\n\nStart command line script $self\n" ); -} elseif ( function_exists( 'getallheaders' ) ) { - wfDebug( "\n\nStart request\n" ); - wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" ); - $headers = getallheaders(); - foreach ($headers as $name => $value) { - wfDebug( "$name: $value\n" ); - } - wfDebug( "\n" ); -} elseif( isset( $_SERVER['REQUEST_URI'] ) ) { - wfDebug( "\n\nStart request\n" ); +} else { + wfDebug( "Start request\n\n" ); wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" ); - foreach ( $_SERVER as $name => $value ) { - if ( substr( $name, 0, 5 ) == 'HTTP_' ) { + $header_out = "HTTP HEADERS:\n"; + + if ( function_exists( 'getallheaders' ) ) { + $headers = getallheaders(); + foreach ( $headers as $name => $value ) { + $header_out .= "$name: $value\n"; + } + } else { + $headers = $_SERVER; + foreach ( $headers as $name => $value ) { + if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue; $name = substr( $name, 5 ); - wfDebug( "$name: $value\n" ); + $header_out .= "$name: $value\n"; } } - wfDebug( "\n" ); + + if ( $wgDebugPrintHttpHeaders ) { + wfDebug( "$header_out\n" ); + } } if( $wgRCFilterByAge ) { @@ -255,9 +259,9 @@ $wgMemc =& wfGetMainCache(); $messageMemc =& wfGetMessageCacheStorage(); $parserMemc =& wfGetParserCacheStorage(); -wfDebug( 'Main cache: ' . get_class( $wgMemc ) . - "\nMessage cache: " . get_class( $messageMemc ) . - "\nParser cache: " . get_class( $parserMemc ) . "\n" ); +wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' . + get_class( $messageMemc ) . '[message] ' . + get_class( $parserMemc ) . "[parser]\n" ); wfProfileOut( $fname.'-memcached' );