]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/profiler/output/ProfilerOutputStats.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / profiler / output / ProfilerOutputStats.php
1 <?php
2 /**
3  * ProfilerOutput class that flushes profiling data to the profiling
4  * context's stats buffer.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  * http://www.gnu.org/copyleft/gpl.html
20  *
21  * @file
22  * @ingroup Profiler
23  */
24 use MediaWiki\MediaWikiServices;
25
26 /**
27  * ProfilerOutput class that flushes profiling data to the profiling
28  * context's stats buffer.
29  *
30  * @ingroup Profiler
31  * @since 1.25
32  */
33 class ProfilerOutputStats extends ProfilerOutput {
34
35         /**
36          * Flush profiling data to the current profiling context's stats buffer.
37          *
38          * @param array $stats
39          */
40         public function log( array $stats ) {
41                 $prefix = isset( $this->params['prefix'] ) ? $this->params['prefix'] : '';
42                 $contextStats = MediaWikiServices::getInstance()->getStatsdDataFactory();
43
44                 foreach ( $stats as $stat ) {
45                         $key = "{$prefix}.{$stat['name']}";
46
47                         // Convert fractional seconds to whole milliseconds
48                         $cpu = round( $stat['cpu'] * 1000 );
49                         $real = round( $stat['real'] * 1000 );
50
51                         $contextStats->increment( "{$key}.calls" );
52                         $contextStats->timing( "{$key}.cpu", $cpu );
53                         $contextStats->timing( "{$key}.real", $real );
54                 }
55         }
56 }