Merge pull request #99 from runcommand/15-name-intermediate

Put names to the intermediate stages
This commit is contained in:
Daniel Bachhuber 2016-10-09 09:24:49 -07:00 committed by GitHub
commit 569e107293
2 changed files with 98 additions and 95 deletions

View file

@ -15,98 +15,98 @@ Feature: Profile the template render stage
When I run `wp profile stage bootstrap --fields=hook`
Then STDOUT should be a table containing rows:
| hook |
| |
| muplugins_loaded |
| |
| plugins_loaded |
| |
| setup_theme |
| |
| after_setup_theme |
| |
| init |
| |
| wp_loaded |
| |
| total |
| hook |
| muplugins_loaded:before |
| muplugins_loaded |
| plugins_loaded:before |
| plugins_loaded |
| setup_theme:before |
| setup_theme |
| after_setup_theme:before |
| after_setup_theme |
| init:before |
| init |
| wp_loaded:before |
| wp_loaded |
| wp_loaded:after |
| total |
When I run `wp profile stage main_query --fields=hook`
Then STDOUT should be a table containing rows:
| hook |
| |
| parse_request |
| |
| send_headers |
| |
| pre_get_posts |
| |
| the_posts |
| |
| wp |
| |
| total |
| hook |
| parse_request:before |
| parse_request |
| send_headers:before |
| send_headers |
| pre_get_posts:before |
| pre_get_posts |
| the_posts:before |
| the_posts |
| wp:before |
| wp |
| wp:after |
| total |
When I run `wp profile stage template --fields=hook`
Then STDOUT should be a table containing rows:
| hook |
| |
| template_redirect |
| |
| template_include |
| |
| wp_head |
| |
| loop_start |
| |
| loop_end |
| |
| wp_footer |
| |
| total |
| hook |
| template_redirect:before |
| template_redirect |
| template_include:before |
| template_include |
| wp_head:before |
| wp_head |
| loop_start:before |
| loop_start |
| loop_end:before |
| loop_end |
| wp_footer:before |
| wp_footer |
| wp_footer:after |
| total |
Scenario: Use --all flag to profile all stages
Given a WP install
When I run `wp profile stage --all --fields=hook`
Then STDOUT should be a table containing rows:
| hook |
| |
| muplugins_loaded |
| |
| plugins_loaded |
| |
| setup_theme |
| |
| after_setup_theme |
| |
| init |
| |
| wp_loaded |
| |
| parse_request |
| |
| send_headers |
| |
| pre_get_posts |
| |
| the_posts |
| |
| wp |
| |
| template_redirect |
| |
| template_include |
| |
| wp_head |
| |
| loop_start |
| |
| loop_end |
| |
| wp_footer |
| |
| total |
| hook |
| muplugins_loaded:before |
| muplugins_loaded |
| plugins_loaded:before |
| plugins_loaded |
| setup_theme:before |
| setup_theme |
| after_setup_theme:before |
| after_setup_theme |
| init:before |
| init |
| wp_loaded:before |
| wp_loaded |
| parse_request:before |
| parse_request |
| send_headers:before |
| send_headers |
| pre_get_posts:before |
| pre_get_posts |
| the_posts:before |
| the_posts |
| wp:before |
| wp |
| template_redirect:before |
| template_redirect |
| template_include:before |
| template_include |
| wp_head:before |
| wp_head |
| loop_start:before |
| loop_start |
| loop_end:before |
| loop_end |
| wp_footer:before |
| wp_footer |
| wp_footer:after |
| total |
Scenario: Invalid stage specified
Given a WP install

View file

@ -35,6 +35,7 @@ class Profiler {
),
);
private $current_stage_hooks = array();
private $running_hook = null;
private $previous_filter = null;
private $previous_filter_callbacks = null;
private $filter_depth = 0;
@ -85,7 +86,7 @@ class Profiler {
$current_filter = current_filter();
if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks ) )
|| ( 'hook' === $this->type && ! $this->focus ) ) {
$pseudo_hook = "before {$current_filter}";
$pseudo_hook = "{$current_filter}:before";
if ( isset( $this->loggers[ $pseudo_hook ] ) ) {
$this->loggers[ $pseudo_hook ]->stop();
}
@ -168,14 +169,13 @@ class Profiler {
if ( 'stage' === $this->type ) {
$key = array_search( $current_filter, $this->current_stage_hooks );
if ( false !== $key && isset( $this->current_stage_hooks[ $key + 1 ] ) ) {
$pseudo_hook = "before {$this->current_stage_hooks[$key+1]}";
$this->loggers[ $pseudo_hook ] = new Logger( array( 'hook' => '' ) );
$this->loggers[ $pseudo_hook ]->start();
$pseudo_hook = "{$this->current_stage_hooks[$key+1]}:before";
} else {
$pseudo_hook = 'wp_profile_last_hook';
$this->loggers[ $pseudo_hook ] = new Logger( array( 'hook' => '' ) );
$this->loggers[ $pseudo_hook ]->start();
$pseudo_hook = "{$this->current_stage_hooks[$key]}:after";;
$this->running_hook = $pseudo_hook;
}
$this->loggers[ $pseudo_hook ] = new Logger( array( 'hook' => $pseudo_hook ) );
$this->loggers[ $pseudo_hook ]->start();
}
}
@ -226,8 +226,9 @@ class Profiler {
}
}
WP_CLI::get_runner()->load_wordpress();
if ( isset( $this->loggers['wp_profile_last_hook'] ) && $this->loggers['wp_profile_last_hook']->running() ) {
$this->loggers['wp_profile_last_hook']->stop();
if ( $this->running_hook ) {
$this->loggers[ $this->running_hook ]->stop();
$this->running_hook = null;
}
if ( 'stage' === $this->type && ! $this->focus ) {
$logger->stop();
@ -244,8 +245,9 @@ class Profiler {
}
}
wp();
if ( isset( $this->loggers['wp_profile_last_hook'] ) && $this->loggers['wp_profile_last_hook']->running() ) {
$this->loggers['wp_profile_last_hook']->stop();
if ( $this->running_hook ) {
$this->loggers[ $this->running_hook ]->stop();
$this->running_hook = null;
}
if ( 'stage' === $this->type && ! $this->focus ) {
$logger->stop();
@ -271,8 +273,9 @@ class Profiler {
ob_start();
require_once( ABSPATH . WPINC . '/template-loader.php' );
ob_get_clean();
if ( isset( $this->loggers['wp_profile_last_hook'] ) && $this->loggers['wp_profile_last_hook']->running() ) {
$this->loggers['wp_profile_last_hook']->stop();
if ( $this->running_hook ) {
$this->loggers[ $this->running_hook ]->stop();
$this->running_hook = null;
}
if ( 'stage' === $this->type && ! $this->focus ) {
$logger->stop();
@ -323,8 +326,8 @@ class Profiler {
*/
private function set_stage_hooks( $hooks ) {
$this->current_stage_hooks = $hooks;
$pseudo_hook = "before {$hooks[0]}";
$this->loggers[ $pseudo_hook ] = new Logger( array( 'hook' => '' ) );
$pseudo_hook = "{$hooks[0]}:before";
$this->loggers[ $pseudo_hook ] = new Logger( array( 'hook' => $pseudo_hook ) );
$this->loggers[ $pseudo_hook ]->start();
}