X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FProfiler.php;h=80a6a68a5557a028bef120706d03795ceeb431a5;hb=c186ff5e916edd922c3a7484e9ba3d196e862877;hp=399c436a9ea576f5605a3e19ea702398eb8c02a4;hpb=4b453dbb5932737d2bad25d6a5e76ea4fef5be8b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Profiler.php b/includes/Profiler.php index 399c436a9e..80a6a68a55 100644 --- a/includes/Profiler.php +++ b/includes/Profiler.php @@ -1,7 +1,10 @@ debug( str_repeat( ' ', count( $this->mWorkStack ) ) . 'Entering ' . $functionname . "\n" ); } @@ -86,11 +89,11 @@ class Profiler { /** * Called by wfProfieOut() - * @param string $functionname + * @param $functionname string */ function profileOut($functionname) { - global $wgDebugFunctionEntry; - + global $wgDebugFunctionEntry, $wgProfiling; + if( !$wgProfiling ) return; $memory = memory_get_usage(); $time = $this->getTime(); @@ -142,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(); @@ -159,7 +167,7 @@ class Profiler { /** * Recursive function the format the current profiling array into a tree * - * @param array $stack profiling array + * @param $stack profiling array */ function remapCallTree( $stack ) { if( count( $stack ) < 2 ){ @@ -199,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() { @@ -313,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) ); } } @@ -344,16 +349,15 @@ class Profiler { /** * Log a function into the database. * - * @param string $name function name - * @param float $timeSum - * @param int $eventCount number of times that function was called + * @param $name string: function name + * @param $timeSum float + * @param $eventCount int: number of times that function was called */ static function logToDB( $name, $timeSum, $eventCount, $memorySum ){ # Do not log anything if database is readonly (bug 5375) if( wfReadOnly() ) { return; } - # Warning: $wguname is a live patch, it should be moved to Setup.php - global $wguname, $wgProfilePerHost; + global $wgProfilePerHost; $dbw = wfGetDB( DB_MASTER ); if( !is_object( $dbw ) ) @@ -363,7 +367,7 @@ class Profiler { $name = substr($name, 0, 255); if( $wgProfilePerHost ){ - $pfhost = $wguname['nodename']; + $pfhost = wfHostname(); } else { $pfhost = ''; } @@ -409,7 +413,7 @@ class Profiler { /** * Get function caller - * @param int $level + * @param $level int */ static function getCaller( $level ) { $backtrace = wfDebugBacktrace(); @@ -427,7 +431,7 @@ class Profiler { /** * Add an entry in the debug log file - * @param string $s string to output + * @param $s string to output */ function debug( $s ) { if( function_exists( 'wfDebug' ) ) {