MediaWiki REL1_34
Xhprof.php
Go to the documentation of this file.
1<?php
32class Xhprof {
36 protected static $enabled;
37
42 public static function isEnabled() {
43 return self::$enabled;
44 }
45
52 public static function enable( $flags = 0, $options = [] ) {
53 if ( self::isEnabled() ) {
54 throw new Exception( 'Profiling is already enabled.' );
55 }
56
57 $args = [ $flags ];
58 if ( $options ) {
59 $args[] = $options;
60 }
61
62 self::$enabled = true;
64 [
65 'xhprof_enable',
66 'tideways_enable',
67 'tideways_xhprof_enable'
68 ],
69 $args
70 );
71 }
72
78 public static function disable() {
79 if ( self::isEnabled() ) {
80 self::$enabled = false;
81 return self::callAny( [
82 'xhprof_disable',
83 'tideways_disable',
84 'tideways_xhprof_disable'
85 ] );
86 } else {
87 return null;
88 }
89 }
90
98 protected static function callAny( array $functions, array $args = [] ) {
99 foreach ( $functions as $func ) {
100 if ( function_exists( $func ) ) {
101 return $func( ...$args );
102 }
103 }
104
105 throw new Exception( "Neither xhprof nor tideways are installed" );
106 }
107}
if( $line===false) $args
Definition cdb.php:64
Convenience class for working with XHProf https://github.com/phacility/xhprof.
Definition Xhprof.php:32
static $enabled
Definition Xhprof.php:36
static enable( $flags=0, $options=[])
Start xhprof profiler.
Definition Xhprof.php:52
static disable()
Stop xhprof profiler.
Definition Xhprof.php:78
static callAny(array $functions, array $args=[])
Call the first available function from $functions.
Definition Xhprof.php:98
static isEnabled()
Start xhprof profiler.
Definition Xhprof.php:42