9 * @todo document methods (?)
12 class ProfilerSimpleTrace
extends ProfilerSimple
{
16 function addInitialStack() {
17 global $wgRequestTime, $wgRUstart;
18 if ( !empty( $wgRequestTime ) && !empty( $wgRUstart ) ) {
19 $this->mWorkStack
[] = array( '-total', 0, $wgRequestTime, $this->getCpuTime( $wgRUstart ) );
21 $this->trace
.= "Beginning trace: \n";
24 function profileIn($functionname) {
25 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), microtime(true), $this->getCpuTime());
26 $this->trace
.= " " . sprintf("%6.1f",$this->memoryDiff()) .
27 str_repeat( " ", count($this->mWorkStack
)) . " > " . $functionname . "\n";
30 function profileOut($functionname) {
31 global $wgDebugFunctionEntry;
33 if ( $wgDebugFunctionEntry ) {
34 $this->debug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
37 list( $ofname, /* $ocount */ , $ortime ) = array_pop( $this->mWorkStack
);
40 $this->trace
.= "Profiling error: $functionname\n";
42 if ( $functionname == 'close' ) {
43 $message = "Profile section ended by close(): {$ofname}";
44 $functionname = $ofname;
45 $this->trace
.= $message . "\n";
47 elseif ( $ofname != $functionname ) {
48 $this->trace
.= "Profiling error: in({$ofname}), out($functionname)";
50 $elapsedreal = microtime( true ) - $ortime;
51 $this->trace
.= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
52 str_repeat(" ", count( $this->mWorkStack
) +
1 ) . " < " . $functionname . "\n";
56 function memoryDiff() {
57 $diff = memory_get_usage() - $this->memory
;
58 $this->memory
= memory_get_usage();
63 print "<!-- \n {$this->trace} \n -->";