DB error log
[lhc/web/wiklou.git] / includes / Profiling.php
index b25b667..ed58bf0 100755 (executable)
@@ -1,4 +1,4 @@
-<?
+<?php
 # This file is only included if profiling is enabled
 function wfProfileIn( $functionname )
 {
@@ -47,7 +47,7 @@ class Profiler
 
        function profileOut( $functionname) 
        {
-               global $wgDebugProfiling, $wgDebugFunctionEntry, $wgProfileToDatabase;
+               global $wgDebugProfiling, $wgDebugFunctionEntry;
 
                if ( $wgDebugFunctionEntry && function_exists( "wfDebug" ) ) {
                        wfDebug( "Exiting $functionname\n" );
@@ -82,6 +82,7 @@ class Profiler
                if( !count( $this->mStack ) ) {
                        return "No profiling output\n";
                }
+               $this->close();
                $width = 125;
                $format = "%-" . ($width - 28) . "s %6d %6.3f %6.3f %6.3f%%\n";
                $titleFormat = "%-" . ($width - 28) . "s %9s %9s %9s %9s\n";
@@ -108,11 +109,17 @@ class Profiler
                        $end = explode( " ", $entry[3]);
                        $end = (float)$end[0] + (float)$end[1];
                        $elapsed = $end - $start;
+                       
+                       if ( !array_key_exists( $fname, $this->mCollated ) ) {
+                               $this->mCollated[$fname] = 0;
+                               $this->mCalls[$fname] = 0;
+                       }
+
                        $this->mCollated[$fname] += $elapsed;
                        $this->mCalls[$fname] ++;
                }
 
-               $total = $this->mCollated["-total"];
+               $total = @$this->mCollated["-total"];
                $overhead = $this->mCollated["-overhead-internal"] / $profileCount;
                $this->mCalls["-overhead-total"] = $profileCount;
 
@@ -128,6 +135,7 @@ class Profiler
                        $prof .= sprintf( $format, $fname, $calls, (float)($elapsed * 1000), 
                                        (float)($elapsed * 1000) / $calls, $percent );
 
+                       global $wgProfileToDatabase;
                        if( $wgProfileToDatabase ) {
                                Profiler::logToDB( $fname, (float)($elapsed * 1000), $calls );
                        }
@@ -166,5 +174,4 @@ class Profiler
 
 $wgProfiler = new Profiler();
 $wgProfiler->profileIn( "-total" );
-
 ?>