Avoid sending duplicate ProfilerOutputText comments/html
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 13 Mar 2019 17:27:38 +0000 (10:27 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 13 Mar 2019 17:27:38 +0000 (10:27 -0700)
Change-Id: I4130845cdb7208b8456740e5dbaf8bf96e175f49

includes/profiler/Profiler.php
includes/profiler/output/ProfilerOutput.php
includes/profiler/output/ProfilerOutputText.php

index 455130c..1f490f9 100644 (file)
@@ -212,7 +212,7 @@ abstract class Profiler {
        }
 
        /**
-        * Log the data to some store or even the page output
+        * Log the data to the backing store for all ProfilerOutput instances that have one
         *
         * @since 1.25
         */
@@ -225,27 +225,38 @@ abstract class Profiler {
                        return;
                }
 
-               $outputs = $this->getOutputs();
-               if ( !$outputs ) {
-                       return;
+               $outputs = [];
+               foreach ( $this->getOutputs() as $output ) {
+                       if ( !$output->logsToOutput() ) {
+                               $outputs[] = $output;
+                       }
                }
 
-               $stats = $this->getFunctionStats();
-               foreach ( $outputs as $output ) {
-                       $output->log( $stats );
+               if ( $outputs ) {
+                       $stats = $this->getFunctionStats();
+                       foreach ( $outputs as $output ) {
+                               $output->log( $stats );
+                       }
                }
        }
 
        /**
-        * Output current data to the page output if configured to do so
+        * Log the data to the script/request output for all ProfilerOutput instances that do so
         *
         * @throws MWException
         * @since 1.26
         */
        public function logDataPageOutputOnly() {
+               $outputs = [];
                foreach ( $this->getOutputs() as $output ) {
-                       if ( $output instanceof ProfilerOutputText ) {
-                               $stats = $this->getFunctionStats();
+                       if ( $output->logsToOutput() ) {
+                               $outputs[] = $output;
+                       }
+               }
+
+               if ( $outputs ) {
+                       $stats = $this->getFunctionStats();
+                       foreach ( $outputs as $output ) {
                                $output->log( $stats );
                        }
                }
index 20b0780..fe27c04 100644 (file)
@@ -47,6 +47,15 @@ abstract class ProfilerOutput {
                return true;
        }
 
+       /**
+        * Does log() just send the data to the request/script output?
+        * @return bool
+        * @since 1.33
+        */
+       public function logsToOutput() {
+               return false;
+       }
+
        /**
         * Log MediaWiki-style profiling data
         *
index e3184db..95b5ff9 100644 (file)
@@ -35,6 +35,11 @@ class ProfilerOutputText extends ProfilerOutput {
                parent::__construct( $collector, $params );
                $this->thresholdMs = $params['thresholdMs'] ?? 1.0;
        }
+
+       public function logsToOutput() {
+               return true;
+       }
+
        public function log( array $stats ) {
                if ( $this->collector->getTemplated() ) {
                        $out = '';