3 * Simple profiler base class
11 class ProfilerSimple
extends Profiler
{
12 function ProfilerSimple() {
13 global $wgRequestTime,$wgRUstart;
14 if (!empty($wgRequestTime) && !empty($wgRUstart)) {
15 $this->mWorkStack
[] = array( '-total', 0, $this->getTime($wgRequestTime),$this->getCpuTime($wgRUstart));
17 $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
18 $elapsedreal = $this->getTime() - $this->getTime($wgRequestTime);
20 $entry =& $this->mCollated
["-setup"];
21 $entry['cpu'] +
= $elapsedcpu;
22 $entry['cpu_sq'] +
= $elapsedcpu*$elapsedcpu;
23 $entry['real'] +
= $elapsedreal;
24 $entry['real_sq'] +
= $elapsedreal*$elapsedreal;
29 function profileIn($functionname) {
30 global $wgDebugFunctionEntry;
31 if ($wgDebugFunctionEntry && function_exists('wfDebug')) {
32 wfDebug(str_repeat(' ', count($this->mWorkStack
)).'Entering '.$functionname."\n");
34 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), $this->getTime(), $this->getCpuTime());
37 function profileOut($functionname) {
38 $memory = memory_get_usage();
40 global $wgDebugFunctionEntry;
42 if ($wgDebugFunctionEntry && function_exists('wfDebug')) {
43 wfDebug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
46 list($ofname,$ocount,$ortime,$octime) = array_pop($this->mWorkStack
);
49 wfDebug("Profiling error: $functionname\n");
51 if ($functionname == 'close') {
52 $message = "Profile section ended by close(): {$ofname}";
53 $functionname = $ofname;
54 wfDebug( "$message\n" );
56 elseif ($ofname != $functionname) {
57 $message = "Profiling error: in({$ofname}), out($functionname)";
58 wfDebug( "$message\n" );
60 $entry =& $this->mCollated
[$functionname];
62 $elapsedcpu = $this->getCpuTime() - $octime;
63 $elapsedreal = $this->getTime() - $ortime;
65 $entry['cpu'] +
= $elapsedcpu;
66 $entry['cpu_sq'] +
= $elapsedcpu*$elapsedcpu;
67 $entry['real'] +
= $elapsedreal;
68 $entry['real_sq'] +
= $elapsedreal*$elapsedreal;
74 function getFunctionReport() {
75 /* Implement in output subclasses */
78 function getCpuTime($ru=null) {
81 return ($ru['ru_utime.tv_sec']+
$ru['ru_stime.tv_sec']+
($ru['ru_utime.tv_usec']+
$ru['ru_stime.tv_usec'])*1e-6);
84 function getTime($time=null) {
87 list($a,$b)=explode(" ",$time);
88 return (float)($a+
$b);