MediaWiki  REL1_20
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 ( $this->visible ) {
00054                                 print '<pre>'.self::$out.'</pre>';
00055                         } else {
00056                                 print "<!--\n".self::$out."\n-->\n";
00057                         }
00058                 }
00059         }
00060 
00061         static function sort( $a, $b ) {
00062                 return $a['real'] < $b['real']; /* sort descending by time elapsed */
00063         }
00064 
00065         static function format( $item, $key, $totalReal ) {
00066                 $perc = $totalReal ? $item['real']/$totalReal*100 : 0;
00067                 self::$out .= sprintf( "%6.2f%% %3.6f %6d - %s\n",
00068                         $perc, $item['real'], $item['count'], $key );
00069         }
00070 }