Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProfilerOutputStats
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 log
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\Profiler\Output;
8
9use MediaWiki\MediaWikiServices;
10
11/**
12 * Flush profiling data to StatsD.
13 *
14 * @ingroup Profiler
15 * @since 1.25
16 */
17class ProfilerOutputStats extends ProfilerOutput {
18
19    /**
20     * Flush profiling data to the current profiling context's stats buffer.
21     *
22     * @param array[] $stats
23     */
24    public function log( array $stats ) {
25        $prefix = $this->params['prefix'] ?? '';
26        $statsFactory = MediaWikiServices::getInstance()->getStatsFactory();
27        $posCounter = $statsFactory->getCounter( 'ProfilerOutputStats_calls_total' );
28        $posCpuTimer = $statsFactory->getTiming( 'ProfilerOutputStats_cpu_seconds' );
29        $posRealTimer = $statsFactory->getTiming( 'ProfilerOutputStats_real_seconds' );
30
31        foreach ( $stats as $stat ) {
32            $key = $prefix ? "{$prefix}_{$stat['name']}" : "{$stat['name']}";
33
34            // Convert fractional seconds to whole milliseconds
35            $cpu = round( $stat['cpu'] * 1000 );
36            $real = round( $stat['real'] * 1000 );
37
38            $posCounter->setLabel( 'key', $key )->increment();
39            $posCpuTimer->setLabel( 'key', $key )->observe( $cpu );
40            $posRealTimer->setLabel( 'key', $key )->observe( $real );
41        }
42    }
43}
44
45/** @deprecated class alias since 1.46 */
46class_alias( ProfilerOutputStats::class, 'ProfilerOutputStats' );