]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/Profiler.php
MediaWiki 1.15.0
[autoinstallsdev/mediawiki.git] / includes / Profiler.php
index ffb489780e73bd69372f272596cd83e6da1255e8..80a6a68a5557a028bef120706d03795ceeb431a5 100644 (file)
@@ -78,8 +78,8 @@ class Profiler {
         * @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" );
                }
@@ -92,8 +92,8 @@ class Profiler {
         * @param $functionname string
         */
        function profileOut($functionname) {
-               global $wgDebugFunctionEntry;
-
+               global $wgDebugFunctionEntry, $wgProfiling;
+               if( !$wgProfiling ) return;
                $memory = memory_get_usage();
                $time = $this->getTime();
 
@@ -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) );
                        }
                }