MediaWiki  master
Xhprof.php
Go to the documentation of this file.
1 <?php
30 class Xhprof {
34  protected static $enabled;
35 
40  public static function isEnabled() {
41  return self::$enabled;
42  }
43 
50  public static function enable( $flags = 0, $options = [] ) {
51  if ( self::isEnabled() ) {
52  throw new Exception( 'Profiling is already enabled.' );
53  }
54 
55  $args = [ $flags ];
56  if ( $options ) {
57  $args[] = $options;
58  }
59 
61  [
62  'xhprof_enable',
63  'tideways_enable',
64  'tideways_xhprof_enable'
65  ],
66  $args
67  );
68  self::$enabled = true;
69  }
70 
76  public static function disable() {
77  if ( self::isEnabled() ) {
78  self::$enabled = false;
79  return self::callAny( [
80  'xhprof_disable',
81  'tideways_disable',
82  'tideways_xhprof_disable'
83  ] );
84  } else {
85  return null;
86  }
87  }
88 
96  protected static function callAny( array $functions, array $args = [] ) {
97  foreach ( $functions as $func ) {
98  if ( function_exists( $func ) ) {
99  return $func( ...$args );
100  }
101  }
102 
103  throw new Exception( "Neither xhprof nor tideways are installed" );
104  }
105 }
Xhprof
Convenience class for working with XHProf https://github.com/phacility/xhprof.
Definition: Xhprof.php:30
Xhprof\isEnabled
static isEnabled()
Start xhprof profiler.
Definition: Xhprof.php:40
Xhprof\enable
static enable( $flags=0, $options=[])
Start xhprof profiler.
Definition: Xhprof.php:50
Xhprof\disable
static disable()
Stop xhprof profiler.
Definition: Xhprof.php:76
$args
if( $line===false) $args
Definition: mcc.php:124
Xhprof\$enabled
static bool $enabled
Whether XHProf is currently running.
Definition: Xhprof.php:34
Xhprof\callAny
static callAny(array $functions, array $args=[])
Call the first available function from $functions.
Definition: Xhprof.php:96