throw new Exception( 'Profiling is already enabled.' );
}
self::$enabled = true;
- if ( function_exists( 'xhprof_enable' ) ) {
- xhprof_enable( $flags, $options );
- } elseif ( function_exists( 'tideways_enable' ) ) {
- tideways_enable( $flags, $options );
- } else {
- throw new Exception( "Neither xhprof nor tideways are installed" );
- }
+ self::callAny(
+ [
+ 'xhprof_enable',
+ 'tideways_enable',
+ 'tideways_xhprof_enable'
+ ],
+ [ $flags, $options ]
+ );
}
/**
public static function disable() {
if ( self::isEnabled() ) {
self::$enabled = false;
- if ( function_exists( 'xhprof_disable' ) ) {
- return xhprof_disable();
- } else {
- // tideways
- return tideways_disable();
+ return self::callAny( [
+ 'xhprof_disable',
+ 'tideways_disable',
+ 'tideways_xhprof_disable'
+ ] );
+ }
+ }
+
+ /**
+ * Call the first available function from $functions.
+ * @param array $functions
+ * @param array $args
+ * @throws Exception
+ */
+ protected static function callAny( array $functions, array $args = [] ) {
+ foreach ( $functions as $func ) {
+ if ( function_exists( $func ) ) {
+ return $func( ...$args );
}
}
+
+ throw new Exception( "Neither xhprof nor tideways are installed" );
}
}