Merge pull request #111 from runcommand/15-profile-after

Support for profiling `wp_loaded:after`
This commit is contained in:
Daniel Bachhuber 2016-10-26 07:04:35 -07:00 committed by GitHub
commit 59fa8a43ca
2 changed files with 34 additions and 0 deletions

View file

@ -137,3 +137,24 @@ Feature: Profile a specific hook
"""
wp-content/mu-plugins/awesome-file.php
"""
Scenario: Profile the :after hooks
Given a WP install
When I run `wp profile hook wp_loaded:after`
Then STDOUT should contain:
"""
do_action()
"""
When I run `wp profile hook wp:after`
Then STDOUT should contain:
"""
do_action_ref_array()
"""
When I run `wp profile hook wp_footer:after`
Then STDOUT should contain:
"""
do_action()
"""

View file

@ -105,6 +105,10 @@ class Profiler {
WP_CLI::add_hook( 'after_wp_config_load', array( $this, 'wp_tick_profile_begin' ) );
}
WP_CLI::add_wp_hook( $end_hook, array( $this, 'wp_tick_profile_end' ), -9999 );
} else if ( 'hook' === $this->type
&& ':after' === substr( $this->focus, -6, 6 ) ) {
$start_hook = substr( $this->focus, 0, -6 );
WP_CLI::add_wp_hook( $start_hook, array( $this, 'wp_tick_profile_begin' ), 9999 );
} else {
WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) );
}
@ -387,6 +391,9 @@ class Profiler {
$this->loggers[ $this->running_hook ]->stop();
$this->running_hook = null;
}
if ( 'hook' === $this->type && 'wp_loaded:after' === $this->focus ) {
$this->wp_tick_profile_end();
}
if ( 'stage' === $this->type && ! $this->focus ) {
$logger->stop();
$this->loggers[] = $logger;
@ -406,6 +413,9 @@ class Profiler {
$this->loggers[ $this->running_hook ]->stop();
$this->running_hook = null;
}
if ( 'hook' === $this->type && 'wp:after' === $this->focus ) {
$this->wp_tick_profile_end();
}
if ( 'stage' === $this->type && ! $this->focus ) {
$logger->stop();
$this->loggers[] = $logger;
@ -434,6 +444,9 @@ class Profiler {
$this->loggers[ $this->running_hook ]->stop();
$this->running_hook = null;
}
if ( 'hook' === $this->type && 'wp_footer:after' === $this->focus ) {
$this->wp_tick_profile_end();
}
if ( 'stage' === $this->type && ! $this->focus ) {
$logger->stop();
$this->loggers[] = $logger;