Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / profiler / output / ProfilerOutputText.php
index 95b5ff9..ee06b59 100644 (file)
  */
 class ProfilerOutputText extends ProfilerOutput {
        /** @var float Min real time display threshold */
-       protected $thresholdMs;
+       private $thresholdMs;
+
+       /** @var bool Whether to use visible text or a comment (for HTML responses) */
+       private $visible;
 
        function __construct( Profiler $collector, array $params ) {
                parent::__construct( $collector, $params );
                $this->thresholdMs = $params['thresholdMs'] ?? 1.0;
+               $this->visible = $params['visible'] ?? false;
        }
 
        public function logsToOutput() {
@@ -41,39 +45,36 @@ class ProfilerOutputText extends ProfilerOutput {
        }
 
        public function log( array $stats ) {
-               if ( $this->collector->getTemplated() ) {
-                       $out = '';
+               $out = '';
 
-                       // Filter out really tiny entries
-                       $min = $this->thresholdMs;
-                       $stats = array_filter( $stats, function ( $a ) use ( $min ) {
-                               return $a['real'] > $min;
-                       } );
-                       // Sort descending by time elapsed
-                       usort( $stats, function ( $a, $b ) {
-                               return $b['real'] <=> $a['real'];
-                       } );
+               // Filter out really tiny entries
+               $min = $this->thresholdMs;
+               $stats = array_filter( $stats, function ( $a ) use ( $min ) {
+                       return $a['real'] > $min;
+               } );
+               // Sort descending by time elapsed
+               usort( $stats, function ( $a, $b ) {
+                       return $b['real'] <=> $a['real'];
+               } );
 
-                       array_walk( $stats,
-                               function ( $item ) use ( &$out ) {
-                                       $out .= sprintf( "%6.2f%% %3.3f %6d - %s\n",
-                                               $item['%real'], $item['real'], $item['calls'], $item['name'] );
-                               }
-                       );
+               array_walk( $stats,
+                       function ( $item ) use ( &$out ) {
+                               $out .= sprintf( "%6.2f%% %3.3f %6d - %s\n",
+                                       $item['%real'], $item['real'], $item['calls'], $item['name'] );
+                       }
+               );
 
-                       $contentType = $this->collector->getContentType();
-                       if ( wfIsCLI() ) {
+               $contentType = $this->collector->getContentType();
+               if ( wfIsCLI() ) {
+                       print "<!--\n{$out}\n-->\n";
+               } elseif ( $contentType === 'text/html' ) {
+                       if ( $this->visible ) {
+                               print "<pre>{$out}</pre>";
+                       } else {
                                print "<!--\n{$out}\n-->\n";
-                       } elseif ( $contentType === 'text/html' ) {
-                               $visible = $this->params['visible'] ?? false;
-                               if ( $visible ) {
-                                       print "<pre>{$out}</pre>";
-                               } else {
-                                       print "<!--\n{$out}\n-->\n";
-                               }
-                       } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) {
-                               print "\n/*\n{$out}*/\n";
                        }
+               } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) {
+                       print "\n/*\n{$out}*/\n";
                }
        }
 }