$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
function profileOut( $functionname)
{
- global $wgDebugProfiling, $wgDebugFunctionEntry;
+ global $wgDebugProfiling, $wgDebugFunctionEntry, $wgProfileToDatabase;
+
if ( $wgDebugFunctionEntry && function_exists( "wfDebug" ) ) {
wfDebug( "Exiting $functionname\n" );
}
$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";
}
}
+/* 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" );