From ab9a00310f07d54fbbb155e909b3db9bf5ebc30d Mon Sep 17 00:00:00 2001 From: "Mr. E23" Date: Tue, 18 Nov 2003 23:52:09 +0000 Subject: [PATCH] Added feature to log sums from profiling data to the DB --- includes/DefaultSettings.php | 1 + includes/Profiling.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 99a60f9467..6636730900 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/Profiling.php b/includes/Profiling.php index 20e1939f43..058557ad91 100755 --- a/includes/Profiling.php +++ b/includes/Profiling.php @@ -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" ); -- 2.20.1