Merge pull request #85 from runcommand/11-shutdown

Support profiling the `shutdown` hook
This commit is contained in:
Daniel Bachhuber 2016-10-04 14:24:11 -07:00 committed by GitHub
commit cefdfed53f
2 changed files with 25 additions and 0 deletions

View file

@ -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 |

View file

@ -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',