Merge "Fix support for TestSwarm on SpecialJavaScriptTest/qunit"
[lhc/web/wiklou.git] / includes / profiler / ProfilerSimpleTrace.php
1 <?php
2 /**
3 * @file
4 * @ingroup Profiler
5 */
6
7 /**
8 * Execution trace
9 * @todo document methods (?)
10 * @ingroup Profiler
11 */
12 class ProfilerSimpleTrace extends ProfilerSimple {
13 var $trace = "";
14 var $memory = 0;
15
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 );
21 }
22 $this->trace .= "Beginning trace: \n";
23 }
24
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";
29 }
30
31 function profileOut($functionname) {
32 global $wgDebugFunctionEntry;
33
34 if ( $wgDebugFunctionEntry ) {
35 $this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n");
36 }
37
38 list( $ofname, /* $ocount */ , $ortime ) = array_pop( $this->mWorkStack );
39
40 if ( !$ofname ) {
41 $this->trace .= "Profiling error: $functionname\n";
42 } else {
43 if ( $functionname == 'close' ) {
44 $message = "Profile section ended by close(): {$ofname}";
45 $functionname = $ofname;
46 $this->trace .= $message . "\n";
47 }
48 elseif ( $ofname != $functionname ) {
49 $this->trace .= "Profiling error: in({$ofname}), out($functionname)";
50 }
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";
54 }
55 }
56
57 function memoryDiff() {
58 $diff = memory_get_usage() - $this->memory;
59 $this->memory = memory_get_usage();
60 return $diff / 1024;
61 }
62
63 function logData() {
64 print "<!-- \n {$this->trace} \n -->";
65 }
66 }