MediaWiki
REL1_24
|
00001 <?php 00034 class ProfilerSimpleText extends ProfilerStandard { 00035 public $visible = false; /* Show as <PRE> or <!-- ? */ 00036 static private $out; 00037 00038 public function __construct( $profileConfig ) { 00039 if ( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) { 00040 $this->visible = true; 00041 } 00042 parent::__construct( $profileConfig ); 00043 } 00044 00045 protected function collateOnly() { 00046 return true; 00047 } 00048 00049 public function logData() { 00050 if ( $this->mTemplated ) { 00051 $this->close(); 00052 $totalReal = isset( $this->mCollated['-total'] ) 00053 ? $this->mCollated['-total']['real'] 00054 : 0; // profiling mismatch error? 00055 uasort( $this->mCollated, array( 'self', 'sort' ) ); 00056 array_walk( $this->mCollated, array( 'self', 'format' ), $totalReal ); 00057 if ( PHP_SAPI === 'cli' ) { 00058 print "<!--\n" . self::$out . "\n-->\n"; 00059 } elseif ( $this->getContentType() === 'text/html' ) { 00060 if ( $this->visible ) { 00061 print '<pre>' . self::$out . '</pre>'; 00062 } else { 00063 print "<!--\n" . self::$out . "\n-->\n"; 00064 } 00065 } elseif ( $this->getContentType() === 'text/javascript' ) { 00066 print "\n/*\n" . self::$out . "*/\n"; 00067 } elseif ( $this->getContentType() === 'text/css' ) { 00068 print "\n/*\n" . self::$out . "*/\n"; 00069 } 00070 } 00071 } 00072 00073 static function sort( $a, $b ) { 00074 return $a['real'] < $b['real']; /* sort descending by time elapsed */ 00075 } 00076 00077 static function format( $item, $key, $totalReal ) { 00078 $perc = $totalReal ? $item['real'] / $totalReal * 100 : 0; 00079 self::$out .= sprintf( "%6.2f%% %3.6f %6d - %s\n", 00080 $perc, $item['real'], $item['count'], $key ); 00081 } 00082 }