Merge pull request #72 from runcommand/log-after-last-hook

Ensure the last step to a stage is logged appropriately
This commit is contained in:
Daniel Bachhuber 2016-09-08 18:34:21 -07:00 committed by GitHub
commit 99f05943d0
3 changed files with 21 additions and 0 deletions

View file

@ -18,4 +18,5 @@ Feature: Profile the template render stage
| loop_end |
| |
| wp_footer |
| |
| total |

View file

@ -217,6 +217,10 @@ class Command {
$pseudo_hook = "before {$this->stage_hooks[$key+1]}";
$this->loggers[ $pseudo_hook ] = new Logger( 'hook', '' );
$this->loggers[ $pseudo_hook ]->start();
} else {
$pseudo_hook = 'wp_profile_last_hook';
$this->loggers[ $pseudo_hook ] = new Logger( 'hook', '' );
$this->loggers[ $pseudo_hook ]->start();
}
}
@ -267,6 +271,9 @@ class Command {
} catch( \Exception $e ) {
// pass through
}
if ( isset( $this->loggers['wp_profile_last_hook'] ) && $this->loggers['wp_profile_last_hook']->running() ) {
$this->loggers['wp_profile_last_hook']->stop();
}
if ( ! $this->focus_stage && ! $this->focus_hook ) {
$logger->stop();
$this->loggers[] = $logger;
@ -290,6 +297,9 @@ class Command {
} catch( \Exception $e ) {
// pass through
}
if ( isset( $this->loggers['wp_profile_last_hook'] ) && $this->loggers['wp_profile_last_hook']->running() ) {
$this->loggers['wp_profile_last_hook']->stop();
}
if ( ! $this->focus_stage && ! $this->focus_hook ) {
$logger->stop();
$this->loggers[] = $logger;
@ -322,6 +332,9 @@ class Command {
} catch( \Exception $e ) {
// pass through
}
if ( isset( $this->loggers['wp_profile_last_hook'] ) && $this->loggers['wp_profile_last_hook']->running() ) {
$this->loggers['wp_profile_last_hook']->stop();
}
ob_get_clean();
if ( ! $this->focus_stage && ! $this->focus_hook ) {
$logger->stop();

View file

@ -43,6 +43,13 @@ class Logger {
$this->cache_miss_offset = ! empty( $wp_object_cache->cache_misses ) ? $wp_object_cache->cache_misses : 0;
}
/**
* Whether or not the logger is running
*/
public function running() {
return ! is_null( $this->start_time );
}
/**
* Stop this logger
*/