New configuration variables $wgDebugTimestamps and $wgDebugPrintHttpHeaders for contr...
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Wed, 27 Jan 2010 17:21:18 +0000 (17:21 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Wed, 27 Jan 2010 17:21:18 +0000 (17:21 +0000)
I find these useful, maybe someone else will too.

RELEASE-NOTES
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/Setup.php

index 3230382..7d674d7 100644 (file)
@@ -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 ===
 
index e801009..56d60d4 100644 (file)
@@ -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
  */
index de8e6d9..5fa6abf 100644 (file)
@@ -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)
index 6f310c7..5642266 100644 (file)
@@ -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' );