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 ) );
27 $this->trace
.= "Beginning trace: \n";
30 function profileIn($functionname) {
31 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
), microtime(true), $this->getCpuTime());
32 $this->trace
.= " " . sprintf("%6.1f",$this->memoryDiff()) .
33 str_repeat( " ", count($this->mWorkStack
)) . " > " . $functionname . "\n";
36 function profileOut($functionname) {
37 global $wgDebugFunctionEntry;
39 if ( $wgDebugFunctionEntry ) {
40 $this->debug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
43 list( $ofname, /* $ocount */ , $ortime, $octime ) = array_pop( $this->mWorkStack
);
46 $this->trace
.= "Profiling error: $functionname\n";
48 if ( $functionname == 'close' ) {
49 $message = "Profile section ended by close(): {$ofname}";
50 $functionname = $ofname;
51 $this->trace
.= $message . "\n";
53 elseif ( $ofname != $functionname ) {
54 $this->trace
.= "Profiling error: in({$ofname}), out($functionname)";
56 $elapsedreal = microtime( true ) - $ortime;
57 $this->trace
.= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
58 str_repeat(" ", count( $this->mWorkStack
) +
1 ) . " < " . $functionname . "\n";
62 function memoryDiff() {
63 $diff = memory_get_usage() - $this->memory
;
64 $this->memory
= memory_get_usage();
68 function getOutput() {
69 print "<!-- \n {$this->trace} \n -->";