X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/profiler/output/ProfilerOutputText.php diff --git a/includes/profiler/output/ProfilerOutputText.php b/includes/profiler/output/ProfilerOutputText.php new file mode 100644 index 00000000..dc24f181 --- /dev/null +++ b/includes/profiler/output/ProfilerOutputText.php @@ -0,0 +1,77 @@ +thresholdMs = isset( $params['thresholdMs'] ) + ? $params['thresholdMs'] + : 1.0; + } + public function log( array $stats ) { + if ( $this->collector->getTemplated() ) { + $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 $a['real'] < $b['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'] ); + } + ); + + $contentType = $this->collector->getContentType(); + if ( PHP_SAPI === 'cli' ) { + print "\n"; + } elseif ( $contentType === 'text/html' ) { + $visible = isset( $this->params['visible'] ) ? + $this->params['visible'] : false; + if ( $visible ) { + print "
{$out}
"; + } else { + print "\n"; + } + } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) { + print "\n/*\n{$out}*/\n"; + } + } + } +}