Merge "Skin: Make skins aware of their registered skin name"
[lhc/web/wiklou.git] / includes / libs / Xhprof.php
index 9c1ec8e..e58d98f 100644 (file)
  * <https://github.com/phacility/xhprof>. XHProf can be installed as a PECL
  * package for use with PHP5 (Zend PHP) and is built-in to HHVM 3.3.0.
  *
+ * This also supports using the Tideways profiler
+ * <https://github.com/tideways/php-profiler-extension>, which additionally
+ * has support for PHP7.
+ *
  * @since 1.28
  */
 class Xhprof {
@@ -33,6 +37,7 @@ class Xhprof {
 
        /**
         * Start xhprof profiler
+        * @return bool
         */
        public static function isEnabled() {
                return self::$enabled;
@@ -40,13 +45,22 @@ class Xhprof {
 
        /**
         * Start xhprof profiler
+        * @param int $flags
+        * @param array $options
+        * @throws Exception
         */
        public static function enable( $flags = 0, $options = [] ) {
                if ( self::isEnabled() ) {
-                       throw new Exception( 'Xhprof profiling is already enabled.' );
+                       throw new Exception( 'Profiling is already enabled.' );
                }
                self::$enabled = true;
-               xhprof_enable( $flags, $options );
+               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" );
+               }
        }
 
        /**
@@ -57,7 +71,12 @@ class Xhprof {
        public static function disable() {
                if ( self::isEnabled() ) {
                        self::$enabled = false;
-                       return xhprof_disable();
+                       if ( function_exists( 'xhprof_disable' ) ) {
+                               return xhprof_disable();
+                       } else {
+                               // tideways
+                               return tideways_disable();
+                       }
                }
        }
 }