From 58ee03b13d32b96d86aaf905fdfa8ac14241a5cc Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 13 Mar 2019 10:27:38 -0700 Subject: [PATCH] Avoid sending duplicate ProfilerOutputText comments/html Change-Id: I4130845cdb7208b8456740e5dbaf8bf96e175f49 --- includes/profiler/Profiler.php | 31 +++++++++++++------ includes/profiler/output/ProfilerOutput.php | 9 ++++++ .../profiler/output/ProfilerOutputText.php | 5 +++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php index 455130cc05..1f490f93d1 100644 --- a/includes/profiler/Profiler.php +++ b/includes/profiler/Profiler.php @@ -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 ); } } diff --git a/includes/profiler/output/ProfilerOutput.php b/includes/profiler/output/ProfilerOutput.php index 20b07801b4..fe27c046e7 100644 --- a/includes/profiler/output/ProfilerOutput.php +++ b/includes/profiler/output/ProfilerOutput.php @@ -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 * diff --git a/includes/profiler/output/ProfilerOutputText.php b/includes/profiler/output/ProfilerOutputText.php index e3184dbf8a..95b5ff95bc 100644 --- a/includes/profiler/output/ProfilerOutputText.php +++ b/includes/profiler/output/ProfilerOutputText.php @@ -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 = ''; -- 2.20.1