From: Tim Starling Date: Wed, 19 Nov 2003 00:48:40 +0000 (+0000) Subject: Moved logToDB to inside Profiler class X-Git-Tag: 1.1.0~139 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=adf48cbb91b2adbcd8c7c6e16f41de63b28d62a3;p=lhc%2Fweb%2Fwiklou.git Moved logToDB to inside Profiler class --- diff --git a/includes/Profiling.php b/includes/Profiling.php index 058557ad91..b25b66794e 100755 --- a/includes/Profiling.php +++ b/includes/Profiling.php @@ -123,44 +123,47 @@ class Profiler if ( $fname[0] != "-" ) { $elapsed -= $overhead * $calls; } - + $percent = $total ? 100. * $elapsed / $total : 0; $prof .= sprintf( $format, $fname, $calls, (float)($elapsed * 1000), - (float)($elapsed * 1000) / $calls, $percent ); + (float)($elapsed * 1000) / $calls, $percent ); if( $wgProfileToDatabase ) { - logToDB( $fname, (float)($elapsed * 1000), $calls ); + Profiler::logToDB( $fname, (float)($elapsed * 1000), $calls ); } } $prof .= "\nTotal: $total\n\n"; return $prof; } -} -/* 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(); + + /* static */ 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)"; } - // 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" );