wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / profiler / ProfilerSectionOnly.php
blob1f8d33b1927fb5d5b79dfb1775c3f531e6880e6f
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 /**
22 * Profiler that only tracks explicit profiling sections
24 * @code
25 * $wgProfiler['class'] = 'ProfilerSectionOnly';
26 * $wgProfiler['output'] = 'text';
27 * $wgProfiler['visible'] = true;
28 * @endcode
30 * @author Aaron Schulz
31 * @ingroup Profiler
32 * @since 1.25
34 class ProfilerSectionOnly extends Profiler {
35 /** @var SectionProfiler */
36 protected $sprofiler;
38 public function __construct( array $params = array() ) {
39 parent::__construct( $params );
40 $this->sprofiler = new SectionProfiler();
43 public function scopedProfileIn( $section ) {
44 return $this->sprofiler->scopedProfileIn( $section );
47 public function close() {
50 public function getFunctionStats() {
51 return $this->sprofiler->getFunctionStats();
54 public function getOutput() {
55 return $this->getFunctionReport();
58 /**
59 * Get a report of profiled functions sorted by inclusive wall clock time
60 * in descending order.
62 * Each line of the report includes this data:
63 * - Function name
64 * - Number of times function was called
65 * - Total wall clock time spent in function in microseconds
66 * - Minimum wall clock time spent in function in microseconds
67 * - Average wall clock time spent in function in microseconds
68 * - Maximum wall clock time spent in function in microseconds
69 * - Percentage of total wall clock time spent in function
70 * - Total delta of memory usage from start to end of function in bytes
72 * @return string
74 protected function getFunctionReport() {
75 $data = $this->getFunctionStats();
76 usort( $data, function( $a, $b ) {
77 if ( $a['real'] === $b['real'] ) {
78 return 0;
80 return ( $a['real'] > $b['real'] ) ? -1 : 1; // descending
81 } );
83 $width = 140;
84 $nameWidth = $width - 65;
85 $format = "%-{$nameWidth}s %6d %9d %9d %9d %9d %7.3f%% %9d";
86 $out = array();
87 $out[] = sprintf( "%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s",
88 'Name', 'Calls', 'Total', 'Min', 'Each', 'Max', '%', 'Mem'
90 foreach ( $data as $stats ) {
91 $out[] = sprintf( $format,
92 $stats['name'],
93 $stats['calls'],
94 $stats['real'] * 1000,
95 $stats['min_real'] * 1000,
96 $stats['real'] / $stats['calls'] * 1000,
97 $stats['max_real'] * 1000,
98 $stats['%real'],
99 $stats['memory']
102 return implode( "\n", $out );