mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:38:51 +08:00
Merge pull request #111 from runcommand/15-profile-after
Support for profiling `wp_loaded:after`
This commit is contained in:
commit
55fa826271
2 changed files with 34 additions and 0 deletions
|
@ -137,3 +137,24 @@ Feature: Profile a specific hook
|
||||||
"""
|
"""
|
||||||
wp-content/mu-plugins/awesome-file.php
|
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()
|
||||||
|
"""
|
||||||
|
|
|
@ -105,6 +105,10 @@ class Profiler {
|
||||||
WP_CLI::add_hook( 'after_wp_config_load', array( $this, 'wp_tick_profile_begin' ) );
|
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 );
|
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 {
|
} else {
|
||||||
WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) );
|
WP_CLI::add_wp_hook( 'all', array( $this, 'wp_hook_begin' ) );
|
||||||
}
|
}
|
||||||
|
@ -387,6 +391,9 @@ class Profiler {
|
||||||
$this->loggers[ $this->running_hook ]->stop();
|
$this->loggers[ $this->running_hook ]->stop();
|
||||||
$this->running_hook = null;
|
$this->running_hook = null;
|
||||||
}
|
}
|
||||||
|
if ( 'hook' === $this->type && 'wp_loaded:after' === $this->focus ) {
|
||||||
|
$this->wp_tick_profile_end();
|
||||||
|
}
|
||||||
if ( 'stage' === $this->type && ! $this->focus ) {
|
if ( 'stage' === $this->type && ! $this->focus ) {
|
||||||
$logger->stop();
|
$logger->stop();
|
||||||
$this->loggers[] = $logger;
|
$this->loggers[] = $logger;
|
||||||
|
@ -406,6 +413,9 @@ class Profiler {
|
||||||
$this->loggers[ $this->running_hook ]->stop();
|
$this->loggers[ $this->running_hook ]->stop();
|
||||||
$this->running_hook = null;
|
$this->running_hook = null;
|
||||||
}
|
}
|
||||||
|
if ( 'hook' === $this->type && 'wp:after' === $this->focus ) {
|
||||||
|
$this->wp_tick_profile_end();
|
||||||
|
}
|
||||||
if ( 'stage' === $this->type && ! $this->focus ) {
|
if ( 'stage' === $this->type && ! $this->focus ) {
|
||||||
$logger->stop();
|
$logger->stop();
|
||||||
$this->loggers[] = $logger;
|
$this->loggers[] = $logger;
|
||||||
|
@ -434,6 +444,9 @@ class Profiler {
|
||||||
$this->loggers[ $this->running_hook ]->stop();
|
$this->loggers[ $this->running_hook ]->stop();
|
||||||
$this->running_hook = null;
|
$this->running_hook = null;
|
||||||
}
|
}
|
||||||
|
if ( 'hook' === $this->type && 'wp_footer:after' === $this->focus ) {
|
||||||
|
$this->wp_tick_profile_end();
|
||||||
|
}
|
||||||
if ( 'stage' === $this->type && ! $this->focus ) {
|
if ( 'stage' === $this->type && ! $this->focus ) {
|
||||||
$logger->stop();
|
$logger->stop();
|
||||||
$this->loggers[] = $logger;
|
$this->loggers[] = $logger;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue