MediaWiki  REL1_24
ProfilerSimpleTrace.php
Go to the documentation of this file.
00001 <?php
00029 class ProfilerSimpleTrace extends ProfilerStandard {
00030     protected $trace = "Beginning trace: \n";
00031     protected $memory = 0;
00032 
00033     protected function collateOnly() {
00034         return true;
00035     }
00036 
00037     public function profileIn( $functionname ) {
00038         parent::profileIn( $functionname );
00039 
00040         $this->trace .= "         " . sprintf( "%6.1f", $this->memoryDiff() ) .
00041             str_repeat( " ", count( $this->mWorkStack ) ) . " > " . $functionname . "\n";
00042     }
00043 
00044     public function profileOut( $functionname ) {
00045         $item = end( $this->mWorkStack );
00046 
00047         parent::profileOut( $functionname );
00048 
00049         if ( !$item ) {
00050             $this->trace .= "Profiling error: $functionname\n";
00051         } else {
00052             list( $ofname, /* $ocount */, $ortime ) = $item;
00053             if ( $functionname == 'close' ) {
00054                 $message = "Profile section ended by close(): {$ofname}";
00055                 $functionname = $ofname;
00056                 $this->trace .= $message . "\n";
00057             } elseif ( $ofname != $functionname ) {
00058                 $this->trace .= "Profiling error: in({$ofname}), out($functionname)";
00059             }
00060             $elapsedreal = $this->getTime() - $ortime;
00061             $this->trace .= sprintf( "%03.6f %6.1f", $elapsedreal, $this->memoryDiff() ) .
00062                 str_repeat( " ", count( $this->mWorkStack ) + 1 ) . " < " . $functionname . "\n";
00063         }
00064     }
00065 
00066     protected function memoryDiff() {
00067         $diff = memory_get_usage() - $this->memory;
00068         $this->memory = memory_get_usage();
00069         return $diff / 1024;
00070     }
00071 
00072     public function logData() {
00073         if ( $this->mTemplated ) {
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     }
00085 }