3 * Simple profiler base class
11 class ProfilerSimple
extends Profiler
{
12 function profileIn($functionname) {
13 global $wgDebugFunctionEntry;
14 if ($wgDebugFunctionEntry && function_exists('wfDebug')) {
15 wfDebug(str_repeat(' ', count($this->mWorkStack
)).'Entering '.$functionname."\n");
17 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), $this->getTime(), $this->getCpuTime());
20 function profileOut($functionname) {
21 $memory = memory_get_usage();
23 global $wgDebugFunctionEntry;
25 if ($wgDebugFunctionEntry && function_exists('wfDebug')) {
26 wfDebug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
29 list($ofname,$ocount,$ortime,$octime) = array_pop($this->mWorkStack
);
32 wfDebug("Profiling error: $functionname\n");
34 if ($functionname == 'close') {
35 $message = "Profile section ended by close(): {$ofname}";
36 wfDebug( "$message\n" );
38 elseif ($ofname != $functionname) {
39 $message = "Profiling error: in({$ofname}), out($functionname)";
40 wfDebug( "$message\n" );
42 $entry =& $this->mCollated
[$functionname];
44 $elapsedcpu = $this->getCpuTime() - $octime;
45 $elapsedreal = $this->getTime() - $ortime;
47 $entry['cpu'] +
= $elapsedcpu;
48 $entry['cpu_sq'] +
= $elapsedcpu*$elapsedcpu;
49 $entry['real'] +
= $elapsedreal;
50 $entry['real_sq'] +
= $elapsedreal*$elapsedreal;
56 function getFunctionReport() {
57 /* Implement in output subclasses */
60 function getCpuTime() {
62 return ($ru['ru_utime.tv_sec']+
$ru['ru_stime.tv_sec']+
($ru['ru_utime.tv_usec']+
$ru['ru_stime.tv_usec'])*1e-6);
66 list($a,$b)=explode(" ",microtime());
67 return (float)($a+
$b);