Added feature to log sums from profiling data to the DB
authorMr. E23 <e23@users.mediawiki.org>
Tue, 18 Nov 2003 23:52:09 +0000 (23:52 +0000)
committerMr. E23 <e23@users.mediawiki.org>
Tue, 18 Nov 2003 23:52:09 +0000 (23:52 +0000)
includes/DefaultSettings.php
includes/Profiling.php

index 99a60f9..6636730 100644 (file)
@@ -130,6 +130,7 @@ $wgUseTeX = false;
 $wgProfiling = false; # Enable for more detailed by-function times in debug log
 $wgProfileLimit = 0.0; # Only record profiling info for pages that took longer than this
 $wgProfileOnly = false; # Don't put non-profiling info into log file
+$wgProfileToDatabase = false; # Log sums from profiling into "profiling" table in db.
 $wgProfileSampleRate = 1; # Only profile every n requests when profiling is turned on
 $wgDebugProfiling = false; # Detects non-matching wfProfileIn/wfProfileOut calls
 $wgDebugFunctionEntry = 0; # Output debug message on every wfProfileIn/wfProfileOut
index 20e1939..058557a 100755 (executable)
@@ -47,7 +47,8 @@ class Profiler
 
        function profileOut( $functionname) 
        {
-               global $wgDebugProfiling, $wgDebugFunctionEntry;
+               global $wgDebugProfiling, $wgDebugFunctionEntry, $wgProfileToDatabase;
+
                if ( $wgDebugFunctionEntry && function_exists( "wfDebug" ) ) {
                        wfDebug( "Exiting $functionname\n" );
                }
@@ -126,6 +127,10 @@ class Profiler
                        $percent = $total ? 100. * $elapsed / $total : 0;
                        $prof .= sprintf( $format, $fname, $calls, (float)($elapsed * 1000), 
                                (float)($elapsed * 1000) / $calls, $percent );
+
+                       if( $wgProfileToDatabase ) {
+                               logToDB( $fname, (float)($elapsed * 1000), $calls );
+                       }
                }
                $prof .= "\nTotal: $total\n\n";
 
@@ -133,6 +138,29 @@ class Profiler
        }
 }
 
+/* private */ function logToDB($name, $timeSum, $eventCount) 
+{
+        $name = wfStrencode( $name );
+       $sql = "UPDATE profiling ".
+         "SET pf_count=pf_count+{$eventCount}, ".
+         "pf_time=pf_time + {$timeSum} ".
+         "WHERE pf_name='{$name}'";
+       wfQuery($sql , DB_WRITE);
+
+       $rc = wfAffectedRows(); 
+       if( $rc == 0) {
+                $sql = "INSERT IGNORE INTO profiling (pf_name,pf_count,pf_time) ".
+                  "VALUES ('{$name}', {$eventCount}, {$timeSum}) ";
+                wfQuery($sql , DB_WRITE);
+                $rc = wfAffectedRows();    
+       }
+       // When we upgrade to mysql 4.1, the insert+update
+       // can be merged into just a insert with this construct added:
+       //     "ON DUPLICATE KEY UPDATE ".
+       //     "pf_count=pf_count + VALUES(pf_count), ".
+       //     "pf_time=pf_time + VALUES(pf_time)"; 
+}
+
 $wgProfiler = new Profiler();
 $wgProfiler->profileIn( "-total" );