9 * @todo document methods (?)
12 class ProfilerSimpleTrace
extends ProfilerSimple
{
16 function addInitialStack() {
17 $initialTime = $this->getInitialTime();
18 $initialCpu = $this->getInitialTime( 'cpu' );
19 if ( $initialTime !== null && $initialCpu !== null ) {
20 $this->mWorkStack
[] = array( '-total', 0, $initialTime, $initialCpu );
22 $this->trace
.= "Beginning trace: \n";
25 function profileIn($functionname) {
26 $this->mWorkStack
[] = array( $functionname, count( $this->mWorkStack
), $this->getTime(), $this->getTime( 'cpu' ) );
27 $this->trace
.= " " . sprintf("%6.1f",$this->memoryDiff()) .
28 str_repeat( " ", count($this->mWorkStack
)) . " > " . $functionname . "\n";
31 function profileOut($functionname) {
32 global $wgDebugFunctionEntry;
34 if ( $wgDebugFunctionEntry ) {
35 $this->debug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
38 list( $ofname, /* $ocount */ , $ortime ) = array_pop( $this->mWorkStack
);
41 $this->trace
.= "Profiling error: $functionname\n";
43 if ( $functionname == 'close' ) {
44 $message = "Profile section ended by close(): {$ofname}";
45 $functionname = $ofname;
46 $this->trace
.= $message . "\n";
48 elseif ( $ofname != $functionname ) {
49 $this->trace
.= "Profiling error: in({$ofname}), out($functionname)";
51 $elapsedreal = $this->getTime() - $ortime;
52 $this->trace
.= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
53 str_repeat(" ", count( $this->mWorkStack
) +
1 ) . " < " . $functionname . "\n";
57 function memoryDiff() {
58 $diff = memory_get_usage() - $this->memory
;
59 $this->memory
= memory_get_usage();
64 print "<!-- \n {$this->trace} \n -->";