9 * @todo document methods (?)
12 class ProfilerSimpleTrace
extends ProfilerSimple
{
16 function __construct( $params ) {
17 global $wgRequestTime, $wgRUstart;
18 parent
::__construct( $params );
19 if ( !empty( $wgRequestTime ) && !empty( $wgRUstart ) ) {
20 $this->mWorkStack
[] = array( '-total', 0, $wgRequestTime, $this->getCpuTime( $wgRUstart ) );
22 $this->trace
.= "Beginning trace: \n";
25 function profileIn($functionname) {
26 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), microtime(true), $this->getCpuTime());
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 = microtime( true ) - $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 -->";