Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ProfilerOutputDump
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 canUse
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 log
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\Profiler\Output;
8
9use MediaWiki\Profiler\ProfilerXhprof;
10
11/**
12 * Dump profiler data in a ".xhprof" file.
13 *
14 * @ingroup Profiler
15 * @since 1.25
16 */
17class ProfilerOutputDump extends ProfilerOutput {
18    /** @var string */
19    protected $suffix = ".xhprof";
20
21    /**
22     * Can this output type be used?
23     *
24     * @return bool
25     */
26    public function canUse() {
27        if ( empty( $this->params['outputDir'] ) ) {
28            return false;
29        }
30        return true;
31    }
32
33    public function log( array $stats ) {
34        if ( !$this->collector instanceof ProfilerXhprof ) {
35            $this->logger->error( 'ProfilerOutputDump must be used with ProfilerXhprof' );
36            return;
37        }
38        $data = $this->collector->getRawData();
39        $filename = sprintf( "%s/%s.%s%s",
40            $this->params['outputDir'],
41            uniqid(),
42            $this->collector->getProfileID(),
43            $this->suffix );
44        file_put_contents( $filename, serialize( $data ) );
45    }
46}
47
48/** @deprecated class alias since 1.46 */
49class_alias( ProfilerOutputDump::class, 'ProfilerOutputDump' );