mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-18 06:11:48 +08:00
Indicate callback count when profiling a stage
This commit is contained in:
parent
9a977569b1
commit
e403ef86e0
2 changed files with 25 additions and 2 deletions
|
@ -116,3 +116,11 @@ Feature: Profile the template render stage
|
||||||
"""
|
"""
|
||||||
Error: Invalid stage. Must be one of bootstrap, main_query, template, or use --all.
|
Error: Invalid stage. Must be one of bootstrap, main_query, template, or use --all.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Scenario: Identify callback_count for each hook
|
||||||
|
Given a WP install
|
||||||
|
|
||||||
|
When I run `wp profile stage bootstrap --fields=hook,callback_count`
|
||||||
|
Then STDOUT should be a table containing rows:
|
||||||
|
| hook | callback_count |
|
||||||
|
| plugins_loaded | 3 |
|
||||||
|
|
|
@ -63,6 +63,7 @@ class Command {
|
||||||
if ( $this->focus_stage ) {
|
if ( $this->focus_stage ) {
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'hook',
|
'hook',
|
||||||
|
'callback_count',
|
||||||
'time',
|
'time',
|
||||||
'query_time',
|
'query_time',
|
||||||
'query_count',
|
'query_count',
|
||||||
|
@ -271,7 +272,21 @@ class Command {
|
||||||
if ( isset( $this->loggers[ $pseudo_hook ] ) ) {
|
if ( isset( $this->loggers[ $pseudo_hook ] ) ) {
|
||||||
$this->loggers[ $pseudo_hook ]->stop();
|
$this->loggers[ $pseudo_hook ]->stop();
|
||||||
}
|
}
|
||||||
$this->loggers[ $current_filter ] = new Logger( array( 'hook' => $current_filter ) );
|
$callback_count = 0;
|
||||||
|
if ( isset( $wp_filter[ $current_filter ] ) && is_a( $wp_filter[ $current_filter ], 'WP_Hook' ) ) {
|
||||||
|
if ( is_array( $wp_filter[ $current_filter ]->callbacks ) ) {
|
||||||
|
foreach( $wp_filter[ $current_filter ]->callbacks as $priority => $callbacks ) {
|
||||||
|
$callback_count += count( $callbacks );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( isset( $wp_filter[ $current_filter ] ) && is_array( $wp_filter[ $current_filter ] ) ) {
|
||||||
|
foreach( $wp_filter[ $current_filter ] as $priority => $callbacks ) {
|
||||||
|
$callback_count += count( $callbacks );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->loggers[ $current_filter ] = new Logger( array( 'hook' => $current_filter, 'callback_count' => $callback_count ) );
|
||||||
$this->loggers[ $current_filter ]->start();
|
$this->loggers[ $current_filter ]->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,11 +367,11 @@ class Command {
|
||||||
$logger->stop_hook_timer();
|
$logger->stop_hook_timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$current_filter = current_filter();
|
||||||
if ( $this->focus_hook && $current_filter === $this->focus_hook ) {
|
if ( $this->focus_hook && $current_filter === $this->focus_hook ) {
|
||||||
$this->filter_depth = 0;
|
$this->filter_depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_filter = current_filter();
|
|
||||||
if ( in_array( $current_filter, $this->stage_hooks ) ) {
|
if ( in_array( $current_filter, $this->stage_hooks ) ) {
|
||||||
$this->loggers[ $current_filter ]->stop();
|
$this->loggers[ $current_filter ]->stop();
|
||||||
$key = array_search( $current_filter, $this->stage_hooks );
|
$key = array_search( $current_filter, $this->stage_hooks );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue