From: Aaron Schulz Date: Tue, 24 Feb 2009 09:50:22 +0000 (+0000) Subject: * Fixed $wgProfileToDatabase/$wgProfileCallTree interaction (later disabled the former) X-Git-Tag: 1.31.0-rc.0~42706 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=3bdaba94c6c075c609f7e70ecf1ce31263e1370e;p=lhc%2Fweb%2Fwiklou.git * Fixed $wgProfileToDatabase/$wgProfileCallTree interaction (later disabled the former) * Made $wgProfileLimit actually work (bug 17485) --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 61c7657020..2677b9393c 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -350,12 +350,14 @@ function wfErrorLog( $text, $file ) { */ function wfLogProfilingData() { global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest; - global $wgProfiler, $wgUser; - if ( !isset( $wgProfiler ) ) - return; - + global $wgProfiler, $wgProfileLimit, $wgUser; + # Profiling must actually be enabled... + if( !isset( $wgProfiler ) ) return; + # Get total page request time $now = wfTime(); $elapsed = $now - $wgRequestTime; + # Only show pages that longer than $wgProfileLimit time (default is 0) + if( $elapsed <= $wgProfileLimit ) return; $prof = wfGetProfilingOutput( $wgRequestTime, $elapsed ); $forward = ''; if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) diff --git a/includes/Profiler.php b/includes/Profiler.php index da0ce3b40e..80a6a68a55 100644 --- a/includes/Profiler.php +++ b/includes/Profiler.php @@ -145,7 +145,12 @@ class Profiler { } $this->close(); - if( $wgProfileCallTree ){ + if( $wgProfileCallTree ) { + global $wgProfileToDatabase; + # XXX: We must call $this->getFunctionReport() to log to the DB + if( $wgProfileToDatabase ) { + $this->getFunctionReport(); + } return $this->getCallTree(); } else { return $this->getFunctionReport(); @@ -202,16 +207,13 @@ class Profiler { /** * Callback to get a formatted line for the call tree */ - function getCallTreeLine($entry) { + function getCallTreeLine( $entry ) { list( $fname, $level, $start, /* $x */, $end) = $entry; $delta = $end - $start; $space = str_repeat(' ', $level); - # The ugly double sprintf is to work around a PHP bug, # which has been fixed in recent releases. - return sprintf( "%10s %s %s\n", - trim( sprintf( "%7.3f", $delta * 1000.0 ) ), - $space, $fname ); + return sprintf( "%10s %s %s\n", trim( sprintf( "%7.3f", $delta * 1000.0 ) ), $space, $fname ); } function getTime() { @@ -316,8 +318,8 @@ class Profiler { $percent = $total ? 100. * $elapsed / $total : 0; $memory = $this->mMemory[$fname]; $prof .= sprintf($format, substr($fname, 0, $nameWidth), $calls, (float) ($elapsed * 1000), (float) ($elapsed * 1000) / $calls, $percent, $memory, ($this->mMin[$fname] * 1000.0), ($this->mMax[$fname] * 1000.0), $this->mOverhead[$fname]); - - if( $wgProfileToDatabase ){ + # Log to the DB + if( $wgProfileToDatabase ) { self::logToDB($fname, (float) ($elapsed * 1000), $calls, (float) ($memory) ); } }