Merge "Remove unused $wgDebugDBTransactions"
[lhc/web/wiklou.git] / includes / profiler / ProfilerSimpleText.php
1 <?php
2 /**
3 * @file
4 * @ingroup Profiler
5 */
6
7 /**
8 * The least sophisticated profiler output class possible, view your source! :)
9 *
10 * Put the following 2 lines in StartProfiler.php:
11 *
12 * $wgProfiler['class'] = 'ProfilerSimpleText';
13 * $wgProfiler['visible'] = true;
14 *
15 * @ingroup Profiler
16 */
17 class ProfilerSimpleText extends ProfilerSimple {
18 public $visible = false; /* Show as <PRE> or <!-- ? */
19 static private $out;
20
21 public function __construct( $profileConfig ) {
22 if ( isset( $profileConfig['visible'] ) && $profileConfig['visible'] ) {
23 $this->visible = true;
24 }
25 parent::__construct( $profileConfig );
26 }
27
28 public function logData() {
29 if ( $this->mTemplated ) {
30 $this->close();
31 $totalReal = isset( $this->mCollated['-total'] )
32 ? $this->mCollated['-total']['real']
33 : 0; // profiling mismatch error?
34 uasort( $this->mCollated, array('self','sort') );
35 array_walk( $this->mCollated, array('self','format'), $totalReal );
36 if ( $this->visible ) {
37 print '<pre>'.self::$out.'</pre>';
38 } else {
39 print "<!--\n".self::$out."\n-->\n";
40 }
41 }
42 }
43
44 static function sort( $a, $b ) {
45 return $a['real'] < $b['real']; /* sort descending by time elapsed */
46 }
47
48 static function format( $item, $key, $totalReal ) {
49 $perc = $totalReal ? $item['real']/$totalReal*100 : 0;
50 self::$out .= sprintf( "%6.2f%% %3.6f %6d - %s\n",
51 $perc, $item['real'], $item['count'], $key );
52 }
53 }