From dcd639f9f90cb0665254e17de2fcc89f25dbb957 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 3 Dec 2014 16:51:22 -0800 Subject: [PATCH] Switched hook profiling to use scopedProfileIn * 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 | 13 +++++++------ includes/profiler/ProfilerStub.php | 4 +++- includes/profiler/ProfilerXhprof.php | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index 668c3d9ec1..44f78a5731 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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; } diff --git a/includes/profiler/ProfilerStub.php b/includes/profiler/ProfilerStub.php index b400601610..2db06e4abb 100644 --- a/includes/profiler/ProfilerStub.php +++ b/includes/profiler/ProfilerStub.php @@ -34,7 +34,9 @@ class ProfilerStub extends Profiler { } public function scopedProfileIn( $section ) { - return null; + return new ScopedCallback( function() { + // no-op + } ); } public function getFunctionStats() { diff --git a/includes/profiler/ProfilerXhprof.php b/includes/profiler/ProfilerXhprof.php index 808c5cd7c4..d91b42915f 100644 --- a/includes/profiler/ProfilerXhprof.php +++ b/includes/profiler/ProfilerXhprof.php @@ -131,7 +131,9 @@ class ProfilerXhprof extends Profiler { } ); } - return null; + return new ScopedCallback( function() { + // no-op + } ); } /** -- 2.20.1