From 214b9a8d4064671ded2eae2b06c11ad0ee41a7eb Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Sat, 24 Dec 2005 13:41:05 +0000 Subject: [PATCH] * move $wgProfiler init to Setup.php * allow specifying different profiler types * add ProfilerSimple (that for now just builds in-memory profiling structure, may be extended to write it somewhere) --- includes/DefaultSettings.php | 2 ++ includes/ProfilerSimple.php | 70 ++++++++++++++++++++++++++++++++++++ includes/Profiling.php | 2 -- includes/Setup.php | 7 ++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100755 includes/ProfilerSimple.php diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index dcd9c5178f..e875cc46f2 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1053,6 +1053,8 @@ $wgProfileToDatabase = false; $wgProfileSampleRate = 1; /** If true, print a raw call tree instead of per-function report */ $wgProfileCallTree = false; +/** If not empty, specifies profiler type to load */ +$wgProfilerType = ''; /** Detects non-matching wfProfileIn/wfProfileOut calls */ $wgDebugProfiling = false; diff --git a/includes/ProfilerSimple.php b/includes/ProfilerSimple.php new file mode 100755 index 0000000000..5a7c8b9c6e --- /dev/null +++ b/includes/ProfilerSimple.php @@ -0,0 +1,70 @@ +mWorkStack)).'Entering '.$functionname."\n"); + } + $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), $this->getTime(), $this->getCpuTime()); + } + + function profileOut($functionname) { + $memory = memory_get_usage(); + + global $wgDebugFunctionEntry; + + if ($wgDebugFunctionEntry && function_exists('wfDebug')) { + wfDebug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n"); + } + + list($ofname,$ocount,$ortime,$octime) = array_pop($this->mWorkStack); + + if (!$ofname) { + wfDebug("Profiling error: $functionname\n"); + } else { + if ($functionname == 'close') { + $message = "Profile section ended by close(): {$ofname}"; + wfDebug( "$message\n" ); + } + elseif ($ofname != $functionname) { + $message = "Profiling error: in({$ofname}), out($functionname)"; + wfDebug( "$message\n" ); + } + $entry =& $this->mCollated[$functionname]; + + $elapsedcpu = $this->getCpuTime() - $octime; + $elapsedreal = $this->getTime() - $ortime; + + $entry['cpu'] += $elapsedcpu; + $entry['cpu_sq'] += $elapsedcpu*$elapsedcpu; + $entry['real'] += $elapsedreal; + $entry['real_sq'] += $elapsedreal*$elapsedreal; + $entry['count']++; + + } + } + + function getFunctionReport() { + /* Implement in output subclasses */ + } + + function getCpuTime() { + $ru=getrusage(); + return ($ru['ru_utime.tv_sec']+$ru['ru_stime.tv_sec']+($ru['ru_utime.tv_usec']+$ru['ru_stime.tv_usec'])*1e-6); + } + + function getTime() { + list($a,$b)=explode(" ",microtime()); + return (float)($a+$b); + } +} +?> diff --git a/includes/Profiling.php b/includes/Profiling.php index 6dc007cb48..92e15650a5 100755 --- a/includes/Profiling.php +++ b/includes/Profiling.php @@ -353,6 +353,4 @@ class Profiler { } -$wgProfiler = new Profiler(); - ?> diff --git a/includes/Setup.php b/includes/Setup.php index 881c5b846f..a77f8537fd 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -26,6 +26,13 @@ if( !isset( $wgProfiling ) ) if ( $wgProfiling and (0 == rand() % $wgProfileSampleRate ) ) { require_once( 'Profiling.php' ); + if ($wgProfilerType == "") { + $wgProfiler = new Profiler(); + } else { + $prclass="Profiler{$wgProfilerType}"; + require_once( $prclass.".php" ); + $wgProfiler = new $prclass(); + } } else { function wfProfileIn( $fn = '' ) { global $hackwhere, $wgDBname; -- 2.20.1