7 if ( !class_exists( 'ProfilerSimple' ) ) {
8 require_once(dirname(__FILE__
).'/ProfilerSimple.php');
13 * @todo document methods (?)
16 class ProfilerSimpleTrace
extends ProfilerSimple
{
17 var $mMinimumTime = 0;
18 var $mProfileID = false;
22 function __construct() {
23 global $wgRequestTime, $wgRUstart;
24 if (!empty($wgRequestTime) && !empty($wgRUstart)) {
25 $this->mWorkStack
[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
26 $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
27 $elapsedreal = microtime(true) - $wgRequestTime;
29 $this->trace
.= "Beginning trace: \n";
32 function profileIn($functionname) {
33 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), microtime(true), $this->getCpuTime());
34 $this->trace
.= " " . sprintf("%6.1f",$this->memoryDiff()) . str_repeat( " ", count($this->mWorkStack
)) . " > " . $functionname . "\n";
37 function profileOut($functionname) {
38 global $wgDebugFunctionEntry;
40 if ($wgDebugFunctionEntry) {
41 $this->debug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
44 list($ofname, /* $ocount */ ,$ortime,$octime) = array_pop($this->mWorkStack
);
47 $this->trace
.= "Profiling error: $functionname\n";
49 if ($functionname == 'close') {
50 $message = "Profile section ended by close(): {$ofname}";
51 $functionname = $ofname;
52 $this->trace
.= $message . "\n";
54 elseif ($ofname != $functionname) {
55 $this->trace
.= "Profiling error: in({$ofname}), out($functionname)";
57 $elapsedcpu = $this->getCpuTime() - $octime;
58 $elapsedreal = microtime(true) - $ortime;
59 $this->trace
.= sprintf("%03.6f %6.1f",$elapsedreal,$this->memoryDiff()) . str_repeat(" ",count($this->mWorkStack
)+
1) . " < " . $functionname . "\n";
63 function memoryDiff() {
64 $diff = memory_get_usage() - $this->memory
;
65 $this->memory
= memory_get_usage();
69 function getOutput() {
70 print "<!-- \n {$this->trace} \n -->";