MediaWiki  REL1_22
ProfilerSimpleTrace.php
Go to the documentation of this file.
00001 <?php
00029 class ProfilerSimpleTrace extends ProfilerSimple {
00030     var $trace = "Beginning trace: \n";
00031     var $memory = 0;
00032 
00033     function profileIn( $functionname ) {
00034         parent::profileIn( $functionname );
00035         $this->trace .= "         " . sprintf( "%6.1f", $this->memoryDiff() ) .
00036                 str_repeat( " ", count( $this->mWorkStack ) ) . " > " . $functionname . "\n";
00037     }
00038 
00039     function profileOut( $functionname ) {
00040         global $wgDebugFunctionEntry;
00041 
00042         if ( $wgDebugFunctionEntry ) {
00043             $this->debug( str_repeat( ' ', count( $this->mWorkStack ) - 1 ) . 'Exiting ' . $functionname . "\n" );
00044         }
00045 
00046         list( $ofname, /* $ocount */, $ortime ) = array_pop( $this->mWorkStack );
00047 
00048         if ( !$ofname ) {
00049             $this->trace .= "Profiling error: $functionname\n";
00050         } else {
00051             if ( $functionname == 'close' ) {
00052                 $message = "Profile section ended by close(): {$ofname}";
00053                 $functionname = $ofname;
00054                 $this->trace .= $message . "\n";
00055             }
00056             elseif ( $ofname != $functionname ) {
00057                 $this->trace .= "Profiling error: in({$ofname}), out($functionname)";
00058             }
00059             $elapsedreal = $this->getTime() - $ortime;
00060             $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
00061                     str_repeat( " ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
00062 
00063             $this->updateTrxProfiling( $functionname, $elapsedreal );
00064         }
00065     }
00066 
00067     function memoryDiff() {
00068         $diff = memory_get_usage() - $this->memory;
00069         $this->memory = memory_get_usage();
00070         return $diff / 1024;
00071     }
00072 
00073     function logData() {
00074         if ( PHP_SAPI === 'cli' ) {
00075             print "<!-- \n {$this->trace} \n -->";
00076         } elseif ( $this->getContentType() === 'text/html' ) {
00077             print "<!-- \n {$this->trace} \n -->";
00078         } elseif ( $this->getContentType() === 'text/javascript' ) {
00079             print "\n/*\n {$this->trace}\n*/";
00080         } elseif ( $this->getContentType() === 'text/css' ) {
00081             print "\n/*\n {$this->trace}\n*/";
00082         }
00083     }
00084 }