3 * Simple profiler base class
11 require_once(dirname(__FILE__
).'/Profiling.php');
13 class ProfilerSimple
extends Profiler
{
14 function ProfilerSimple() {
15 global $wgRequestTime,$wgRUstart;
16 if (!empty($wgRequestTime) && !empty($wgRUstart)) {
17 $this->mWorkStack
[] = array( '-total', 0, $this->getTime($wgRequestTime),$this->getCpuTime($wgRUstart));
19 $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
20 $elapsedreal = $this->getTime() - $this->getTime($wgRequestTime);
22 $entry =& $this->mCollated
["-setup"];
23 $entry['cpu'] +
= $elapsedcpu;
24 $entry['cpu_sq'] +
= $elapsedcpu*$elapsedcpu;
25 $entry['real'] +
= $elapsedreal;
26 $entry['real_sq'] +
= $elapsedreal*$elapsedreal;
31 function profileIn($functionname) {
32 global $wgDebugFunctionEntry;
33 if ($wgDebugFunctionEntry) {
34 $this->debug(str_repeat(' ', count($this->mWorkStack
)).'Entering '.$functionname."\n");
36 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), $this->getTime(), $this->getCpuTime());
39 function profileOut($functionname) {
40 $memory = memory_get_usage();
42 global $wgDebugFunctionEntry;
44 if ($wgDebugFunctionEntry) {
45 $this->debug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
48 list($ofname,$ocount,$ortime,$octime) = array_pop($this->mWorkStack
);
51 $this->debug("Profiling error: $functionname\n");
53 if ($functionname == 'close') {
54 $message = "Profile section ended by close(): {$ofname}";
55 $functionname = $ofname;
56 $this->debug( "$message\n" );
58 elseif ($ofname != $functionname) {
59 $message = "Profiling error: in({$ofname}), out($functionname)";
60 $this->debug( "$message\n" );
62 $entry =& $this->mCollated
[$functionname];
64 $elapsedcpu = $this->getCpuTime() - $octime;
65 $elapsedreal = $this->getTime() - $ortime;
67 $entry['cpu'] +
= $elapsedcpu;
68 $entry['cpu_sq'] +
= $elapsedcpu*$elapsedcpu;
69 $entry['real'] +
= $elapsedreal;
70 $entry['real_sq'] +
= $elapsedreal*$elapsedreal;
76 function getFunctionReport() {
77 /* Implement in output subclasses */
80 function getCpuTime($ru=null) {
83 return ($ru['ru_utime.tv_sec']+
$ru['ru_stime.tv_sec']+
($ru['ru_utime.tv_usec']+
$ru['ru_stime.tv_usec'])*1e-6);
86 function getTime($time=null) {
89 list($a,$b)=explode(" ",$time);
90 return (float)($a+
$b);
93 function debug( $s ) {
94 if (function_exists( 'wfDebug' ) ) {