MediaWiki REL1_35
ProfilerOutputText.php
Go to the documentation of this file.
1<?php
31 private $thresholdMs;
32
34 private $visible;
35
36 public function __construct( Profiler $collector, array $params ) {
37 parent::__construct( $collector, $params );
38 $this->thresholdMs = $params['thresholdMs'] ?? 1.0;
39 $this->visible = $params['visible'] ?? false;
40 }
41
42 public function logsToOutput() {
43 return true;
44 }
45
46 public function log( array $stats ) {
47 $out = '';
48
49 // Filter out really tiny entries
50 $min = $this->thresholdMs;
51 $stats = array_filter( $stats, function ( $a ) use ( $min ) {
52 return $a['real'] > $min;
53 } );
54 // Sort descending by time elapsed
55 usort( $stats, function ( $a, $b ) {
56 return $b['real'] <=> $a['real'];
57 } );
58
59 array_walk( $stats,
60 function ( $item ) use ( &$out ) {
61 $out .= sprintf( "%6.2f%% %3.3f %6d - %s\n",
62 $item['%real'], $item['real'], $item['calls'], $item['name'] );
63 }
64 );
65
66 $contentType = $this->collector->getContentType();
67 if ( wfIsCLI() ) {
68 print "<!--\n{$out}\n-->\n";
69 } elseif ( $contentType === 'text/html' ) {
70 if ( $this->visible ) {
71 print "<pre>{$out}</pre>";
72 } else {
73 print "<!--\n{$out}\n-->\n";
74 }
75 } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) {
76 print "\n/*\n{$out}*/\n";
77 }
78 }
79}
wfIsCLI()
Check if we are running from the commandline.
Adds profiler output to the HTTP response.
bool $visible
Whether to use visible text or a comment (for HTML responses)
float $thresholdMs
Min real time display threshold.
log(array $stats)
Log MediaWiki-style profiling data.
logsToOutput()
May the log() try to write to standard output?
__construct(Profiler $collector, array $params)
Base class for profiling output.
array $params
Configuration of $wgProfiler.
Profiler base class that defines the interface and some shared functionality.
Definition Profiler.php:33
while(( $__line=Maintenance::readconsole()) !==false) print
Definition eval.php:64