Switched hook profiling to use scopedProfileIn
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 4 Dec 2014 00:51:22 +0000 (16:51 -0800)
committerBryanDavis <bdavis@wikimedia.org>
Thu, 4 Dec 2014 19:32:38 +0000 (19:32 +0000)
* Also made scopedProfileOut handle the case where the callback
  was null (e.g. when there are no frame methods for xhprof).

Change-Id: Ife242bda8e046990d0d8ac27d628975b7b4a14d7

includes/Hooks.php
includes/profiler/ProfilerStub.php
includes/profiler/ProfilerXhprof.php

index 668c3d9..44f78a5 100644 (file)
@@ -134,7 +134,9 @@ class Hooks {
         * @throws FatalError
         */
        public static function run( $event, array $args = array(), $deprecatedVersion = null ) {
-               wfProfileIn( 'hook: ' . $event );
+               $profiler = Profiler::instance();
+               $eventPS = $profiler->scopedProfileIn( 'hook: ' . $event );
+
                foreach ( self::getHandlers( $event ) as $hook ) {
                        // Turn non-array values into an array. (Can't use casting because of objects.)
                        if ( !is_array( $hook ) ) {
@@ -193,8 +195,8 @@ class Hooks {
                        $badhookmsg = null;
                        $hook_args = array_merge( $hook, $args );
 
-                       // Profile first in case the Profiler causes errors.
-                       wfProfileIn( $func );
+                       // Profile first in case the Profiler causes errors
+                       $funcPS = $profiler->scopedProfileIn( $func );
                        set_error_handler( 'Hooks::hookErrorHandler' );
 
                        // mark hook as deprecated, if deprecation version is specified
@@ -210,8 +212,9 @@ class Hooks {
                                restore_error_handler();
                                throw $e;
                        }
+
                        restore_error_handler();
-                       wfProfileOut( $func );
+                       $profiler->scopedProfileOut( $funcPS );
 
                        // Process the return value.
                        if ( is_string( $retval ) ) {
@@ -224,13 +227,11 @@ class Hooks {
                                        "Hook $func has invalid call signature; " . $badhookmsg
                                );
                        } elseif ( $retval === false ) {
-                               wfProfileOut( 'hook: ' . $event );
                                // False was returned. Stop processing, but no error.
                                return false;
                        }
                }
 
-               wfProfileOut( 'hook: ' . $event );
                return true;
        }
 
index b400601..2db06e4 100644 (file)
@@ -34,7 +34,9 @@ class ProfilerStub extends Profiler {
        }
 
        public function scopedProfileIn( $section ) {
-               return null;
+               return new ScopedCallback( function() {
+                       // no-op
+               } );
        }
 
        public function getFunctionStats() {
index 808c5cd..d91b429 100644 (file)
@@ -131,7 +131,9 @@ class ProfilerXhprof extends Profiler {
                        } );
                }
 
-               return null;
+               return new ScopedCallback( function() {
+                       // no-op
+               } );
        }
 
        /**