INDEX use fixes
[lhc/web/wiklou.git] / includes / Profiler.php
index 399c436..80a6a68 100644 (file)
@@ -1,7 +1,10 @@
 <?php
 /**
+ * @defgroup Profiler Profiler
+ *
+ * @file
+ * @ingroup Profiler
  * This file is only included if profiling is enabled
- * @addtogroup Profiler
  */
 
 /** backward compatibility */
@@ -37,7 +40,7 @@ function wfGetProfilingOutput( $start, $elapsed ) {
 }
 
 /**
- * Closed opened profiling section
+ * Close opened profiling sections
  */
 function wfProfileClose() {
        global $wgProfiler;
@@ -52,8 +55,8 @@ if (!function_exists('memory_get_usage')) {
 }
 
 /**
+ * @ingroup Profiler
  * @todo document
- * @addtogroup Profiler
  */
 class Profiler {
        var $mStack = array (), $mWorkStack = array (), $mCollated = array ();
@@ -72,11 +75,11 @@ class Profiler {
 
        /**
         * Called by wfProfieIn()
-        * @param string $functionname
+        * @param $functionname string
         */
        function profileIn( $functionname ) {
-               global $wgDebugFunctionEntry;
-
+               global $wgDebugFunctionEntry, $wgProfiling;
+               if( !$wgProfiling ) return;
                if( $wgDebugFunctionEntry ){
                        $this->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' ) ) {