Merge "Show Log toolbox link for anon users, fix toolbox on DeletedContribs"
[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 = "Beginning trace: \n";
14 var $memory = 0;
15
16 function profileIn( $functionname ) {
17 parent::profileIn( $functionname );
18 $this->trace .= " " . sprintf("%6.1f",$this->memoryDiff()) .
19 str_repeat( " ", count($this->mWorkStack)) . " > " . $functionname . "\n";
20 }
21
22 function profileOut($functionname) {
23 global $wgDebugFunctionEntry;
24
25 if ( $wgDebugFunctionEntry ) {
26 $this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n");
27 }
28
29 list( $ofname, /* $ocount */ , $ortime ) = array_pop( $this->mWorkStack );
30
31 if ( !$ofname ) {
32 $this->trace .= "Profiling error: $functionname\n";
33 } else {
34 if ( $functionname == 'close' ) {
35 $message = "Profile section ended by close(): {$ofname}";
36 $functionname = $ofname;
37 $this->trace .= $message . "\n";
38 }
39 elseif ( $ofname != $functionname ) {
40 $this->trace .= "Profiling error: in({$ofname}), out($functionname)";
41 }
42 $elapsedreal = $this->getTime() - $ortime;
43 $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
44 str_repeat(" ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
45 }
46 }
47
48 function memoryDiff() {
49 $diff = memory_get_usage() - $this->memory;
50 $this->memory = memory_get_usage();
51 return $diff / 1024;
52 }
53
54 function logData() {
55 print "<!-- \n {$this->trace} \n -->";
56 }
57 }