mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Merge pull request #85 from runcommand/11-shutdown
Support profiling the `shutdown` hook
This commit is contained in:
commit
cefdfed53f
2 changed files with 25 additions and 0 deletions
|
@ -27,3 +27,21 @@ Feature: Profile a specific hook
|
|||
"""
|
||||
<meta name="generator"
|
||||
"""
|
||||
|
||||
Scenario: Profile the shutdown hook
|
||||
Given a WP install
|
||||
And a wp-content/mu-plugins/shutdown.php file:
|
||||
"""
|
||||
<?php
|
||||
function runcommand_shutdown_hook() {
|
||||
wp_cache_get( 'foo' );
|
||||
}
|
||||
add_action( 'shutdown', 'runcommand_shutdown_hook' );
|
||||
"""
|
||||
|
||||
When I run `wp profile hook shutdown --fields=callback,cache_hits,cache_misses`
|
||||
Then STDOUT should be a table containing rows:
|
||||
| callback | cache_hits | cache_misses |
|
||||
| runcommand_shutdown_hook() | 0 | 1 |
|
||||
| wp_ob_end_flush_all() | 0 | 0 |
|
||||
| total | 0 | 1 |
|
||||
|
|
|
@ -120,6 +120,13 @@ class Command {
|
|||
$this->focus_hook = $args[0];
|
||||
$this->run_profiler();
|
||||
|
||||
// 'shutdown' won't actually fire until script completion
|
||||
// but we can mock it
|
||||
if ( 'shutdown' === $this->focus_hook ) {
|
||||
do_action( 'shutdown' );
|
||||
remove_all_actions( 'shutdown' );
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'callback',
|
||||
'time',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue