Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / libs / Xhprof.php
blob016c9b1574fa91042cbdcba9e81bade9ce1e072b
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 * Convenience class for working with XHProf
23 * <https://github.com/phacility/xhprof>. XHProf can be installed as a PECL
24 * package for use with PHP5 (Zend PHP) and is built-in to HHVM 3.3.0.
26 * This also supports using the Tideways profiler
27 * <https://github.com/tideways/php-profiler-extension>, which additionally
28 * has support for PHP7.
30 * @since 1.28
32 class Xhprof {
33 /**
34 * @var bool $enabled Whether XHProf is currently running.
36 protected static $enabled;
38 /**
39 * Start xhprof profiler
41 public static function isEnabled() {
42 return self::$enabled;
45 /**
46 * Start xhprof profiler
48 public static function enable( $flags = 0, $options = [] ) {
49 if ( self::isEnabled() ) {
50 throw new Exception( 'Profiling is already enabled.' );
52 self::$enabled = true;
53 if ( function_exists( 'xhprof_enable' ) ) {
54 xhprof_enable( $flags, $options );
55 } elseif ( function_exists( 'tideways_enable' ) ) {
56 tideways_enable( $flags, $options );
57 } else {
58 throw new Exception( "Neither xhprof nor tideways are installed" );
62 /**
63 * Stop xhprof profiler
65 * @return array|null xhprof data from the run, or null if xhprof was not running.
67 public static function disable() {
68 if ( self::isEnabled() ) {
69 self::$enabled = false;
70 if ( function_exists( 'xhprof_disable' ) ) {
71 return xhprof_disable();
72 } else {
73 // tideways
74 return tideways_disable();