MediaWiki  REL1_19
ProfilerSimpleTrace.php
Go to the documentation of this file.
00001 <?php
00012 class ProfilerSimpleTrace extends ProfilerSimple {
00013         var $trace = "";
00014         var $memory = 0;
00015 
00016         function __construct( $params ) {
00017                 global $wgRequestTime, $wgRUstart;
00018                 parent::__construct( $params );
00019                 if ( !empty( $wgRequestTime ) && !empty( $wgRUstart ) ) {
00020                         $this->mWorkStack[] = array( '-total', 0, $wgRequestTime, $this->getCpuTime( $wgRUstart ) );
00021                 }
00022                 $this->trace .= "Beginning trace: \n";
00023         }
00024 
00025         function profileIn($functionname) {
00026                 $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), microtime(true), $this->getCpuTime());
00027                 $this->trace .= "         " . sprintf("%6.1f",$this->memoryDiff()) .
00028                                 str_repeat( " ", count($this->mWorkStack)) . " > " . $functionname . "\n";
00029         }
00030 
00031         function profileOut($functionname) {
00032                 global $wgDebugFunctionEntry;
00033 
00034                 if ( $wgDebugFunctionEntry ) {
00035                         $this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n");
00036                 }
00037 
00038                 list( $ofname, /* $ocount */ , $ortime ) = array_pop( $this->mWorkStack );
00039 
00040                 if ( !$ofname ) {
00041                         $this->trace .= "Profiling error: $functionname\n";
00042                 } else {
00043                         if ( $functionname == 'close' ) {
00044                                 $message = "Profile section ended by close(): {$ofname}";
00045                                 $functionname = $ofname;
00046                                 $this->trace .= $message . "\n";
00047                         }
00048                         elseif ( $ofname != $functionname ) {
00049                                 $this->trace .= "Profiling error: in({$ofname}), out($functionname)";
00050                         }
00051                         $elapsedreal = microtime( true ) - $ortime;
00052                         $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
00053                                         str_repeat(" ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
00054                 }
00055         }
00056         
00057         function memoryDiff() {
00058                 $diff = memory_get_usage() - $this->memory;
00059                 $this->memory = memory_get_usage();
00060                 return $diff / 1024;
00061         }
00062 
00063         function logData() {
00064                 print "<!-- \n {$this->trace} \n -->";
00065         }
00066 }