MediaWiki  REL1_19
ProfilerSimpleText.php
Go to the documentation of this file.
00001 <?php
00017 class ProfilerSimpleText extends ProfilerSimple {
00018         public $visible = false; /* Show as <PRE> or <!-- ? */
00019         static private $out;
00020 
00021         public function __construct( $profileConfig ) {
00022                 if ( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) {
00023                         $this->visible = true;
00024                 }
00025                 parent::__construct( $profileConfig );
00026         }
00027 
00028         public function logData() {
00029                 if ( $this->mTemplated ) {
00030                         $this->close();
00031                         $totalReal = isset( $this->mCollated['-total'] )
00032                                 ? $this->mCollated['-total']['real']
00033                                 : 0; // profiling mismatch error?
00034                         uasort( $this->mCollated, array('self','sort') );
00035                         array_walk( $this->mCollated, array('self','format'), $totalReal );
00036                         if ( $this->visible ) {
00037                                 print '<pre>'.self::$out.'</pre>';
00038                         } else {
00039                                 print "<!--\n".self::$out."\n-->\n";
00040                         }
00041                 }
00042         }
00043 
00044         static function sort( $a, $b ) {
00045                 return $a['real'] < $b['real']; /* sort descending by time elapsed */
00046         }
00047 
00048         static function format( $item, $key, $totalReal ) {
00049                 $perc = $totalReal ? $item['real']/$totalReal*100 : 0;
00050                 self::$out .= sprintf( "%6.2f%% %3.6f %6d - %s\n",
00051                         $perc, $item['real'], $item['count'], $key );
00052         }
00053 }