r61582 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61581‎ | r61582 | r61583 >
Date:17:21, 27 January 2010
Author:nikerabbit
Status:resolved
Tags:
Comment:
New configuration variables $wgDebugTimestamps and $wgDebugPrintHttpHeaders for controlling debug output.

I find these useful, maybe someone else will too.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -1222,6 +1222,16 @@
12231223 $wgShowDebug = false;
12241224
12251225 /**
 1226+ * Prefix debug messages with relative timestamp. Very-poor man's profiler.
 1227+ */
 1228+$wgDebugTimestamps = false;
 1229+
 1230+/**
 1231+ * Print HTTP headers for every request in the debug information.
 1232+ */
 1233+$wgDebugPrintHttpHeaders = true;
 1234+
 1235+/**
12261236 * Show the contents of $wgHooks in Special:Version
12271237 */
12281238 $wgSpecialVersionShowHooks = false;
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -343,6 +343,7 @@
344344 static $recursion = 0;
345345
346346 static $cache = array(); // Cache of unoutputted messages
 347+ $text = wfDebugTimer() . $text;
347348
348349 # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
349350 if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
@@ -377,6 +378,21 @@
378379 }
379380 }
380381
 382+function wfDebugTimer() {
 383+ global $wgDebugTimestamps;
 384+ if ( !$wgDebugTimestamps ) return '';
 385+ static $start = null;
 386+
 387+ if ( $start === null ) {
 388+ $start = microtime( true );
 389+ $prefix = "\n$start";
 390+ } else {
 391+ $prefix = sprintf( "%6.4f", microtime( true ) - $start );
 392+ }
 393+
 394+ return $prefix . ' ';
 395+}
 396+
381397 /**
382398 * Send a line giving PHP memory usage.
383399 * @param $exact Bool: print exact values instead of kilobytes (default: false)
Index: trunk/phase3/includes/Setup.php
@@ -180,24 +180,28 @@
181181 # Useful debug output
182182 if ( $wgCommandLineMode ) {
183183 wfDebug( "\n\nStart command line script $self\n" );
184 -} elseif ( function_exists( 'getallheaders' ) ) {
185 - wfDebug( "\n\nStart request\n" );
 184+} else {
 185+ wfDebug( "Start request\n\n" );
186186 wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
187 - $headers = getallheaders();
188 - foreach ($headers as $name => $value) {
189 - wfDebug( "$name: $value\n" );
190 - }
191 - wfDebug( "\n" );
192 -} elseif( isset( $_SERVER['REQUEST_URI'] ) ) {
193 - wfDebug( "\n\nStart request\n" );
194 - wfDebug( $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . "\n" );
195 - foreach ( $_SERVER as $name => $value ) {
196 - if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
 187+ $header_out = "HTTP HEADERS:\n";
 188+
 189+ if ( function_exists( 'getallheaders' ) ) {
 190+ $headers = getallheaders();
 191+ foreach ( $headers as $name => $value ) {
 192+ $header_out .= "$name: $value\n";
 193+ }
 194+ } else {
 195+ $headers = $_SERVER;
 196+ foreach ( $headers as $name => $value ) {
 197+ if ( substr( $name, 0, 5 ) !== 'HTTP_' ) continue;
197198 $name = substr( $name, 5 );
198 - wfDebug( "$name: $value\n" );
 199+ $header_out .= "$name: $value\n";
199200 }
200201 }
201 - wfDebug( "\n" );
 202+
 203+ if ( $wgDebugPrintHttpHeaders ) {
 204+ wfDebug( "$header_out\n" );
 205+ }
202206 }
203207
204208 if( $wgRCFilterByAge ) {
@@ -255,9 +259,9 @@
256260 $messageMemc =& wfGetMessageCacheStorage();
257261 $parserMemc =& wfGetParserCacheStorage();
258262
259 -wfDebug( 'Main cache: ' . get_class( $wgMemc ) .
260 - "\nMessage cache: " . get_class( $messageMemc ) .
261 - "\nParser cache: " . get_class( $parserMemc ) . "\n" );
 263+wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
 264+ get_class( $messageMemc ) . '[message] ' .
 265+ get_class( $parserMemc ) . "[parser]\n" );
262266
263267 wfProfileOut( $fname.'-memcached' );
264268
Index: trunk/phase3/RELEASE-NOTES
@@ -96,6 +96,8 @@
9797 longer advertised by default (but it still works).
9898 * Added $wgMemCachedTimeout to configure connection timeouts for communicating
9999 with a memcached server
 100+* New configuration variables $wgDebugTimestamps and $wgDebugPrintHttpHeaders
 101+ for controlling debug output.
100102
101103 === New features in 1.16 ===
102104

Follow-up revisions

RevisionCommit summaryAuthorDate
r61653Fix for r61582: if $wgDebugPrintHttpHeaders is false, don't construct the hea...tstarling04:29, 29 January 2010

Status & tagging log