* @since 1.26
*/
public function logDataPageOutputOnly() {
+ if ( !$this->allowOutput ) {
+ return;
+ }
+
$outputs = [];
foreach ( $this->getOutputs() as $output ) {
if ( $output->logsToOutput() ) {
* @param bool $t
*/
public function setTemplated( $t ) {
- // wfDeprecated( __METHOD__, '1.34' );
+ wfDeprecated( __METHOD__, '1.34' );
$this->allowOutput = ( $t === true );
}
* @return bool
*/
public function getTemplated() {
- // wfDeprecated( __METHOD__, '1.34' );
+ wfDeprecated( __METHOD__, '1.34' );
return $this->getAllowOutput();
}
*/
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() {
}
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";
}
}
}