MediaWiki  REL1_22
ProfilerSimpleText.php
Go to the documentation of this file.
00001 <?php
00034 class ProfilerSimpleText extends ProfilerSimple {
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     public function logData() {
00046         if ( $this->mTemplated ) {
00047             $this->close();
00048             $totalReal = isset( $this->mCollated['-total'] )
00049                 ? $this->mCollated['-total']['real']
00050                 : 0; // profiling mismatch error?
00051             uasort( $this->mCollated, array( 'self', 'sort' ) );
00052             array_walk( $this->mCollated, array( 'self', 'format' ), $totalReal );
00053             if ( PHP_SAPI === 'cli' ) {
00054                 print "<!--\n" . self::$out . "\n-->\n";
00055             } elseif ( $this->getContentType() === 'text/html' ) {
00056                 if ( $this->visible ) {
00057                     print '<pre>' . self::$out . '</pre>';
00058                 } else {
00059                     print "<!--\n" . self::$out . "\n-->\n";
00060                 }
00061             } elseif ( $this->getContentType() === 'text/javascript' ) {
00062                 print "\n/*\n" . self::$out . "*/\n";
00063             } elseif ( $this->getContentType() === 'text/css' ) {
00064                 print "\n/*\n" . self::$out . "*/\n";
00065             }
00066         }
00067     }
00068 
00069     static function sort( $a, $b ) {
00070         return $a['real'] < $b['real']; /* sort descending by time elapsed */
00071     }
00072 
00073     static function format( $item, $key, $totalReal ) {
00074         $perc = $totalReal ? $item['real'] / $totalReal * 100 : 0;
00075         self::$out .= sprintf( "%6.2f%% %3.6f %6d - %s\n",
00076             $perc, $item['real'], $item['count'], $key );
00077     }
00078 }