From 6beb5a6873d774dbf1ab85e9f3930e4c774d2f80 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 26 Aug 2016 08:08:51 -0700 Subject: [PATCH] Fix calculated hook time The timer shouldn't be started and stopped as we go deeper into hooks --- inc/class-logger.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/inc/class-logger.php b/inc/class-logger.php index d35a46c..6c12f9c 100644 --- a/inc/class-logger.php +++ b/inc/class-logger.php @@ -13,6 +13,7 @@ class Logger { private $start_time = null; private $query_offset = null; private $hook_start_time = null; + private $hook_depth = 0; public static $active_loggers = array(); @@ -59,18 +60,27 @@ class Logger { * Start this logger's hook timer */ public function start_hook_timer() { - $this->hook_count++; - $this->hook_start_time = microtime( true ); + // Timer already running means a subhook has been called + if ( ! is_null( $this->hook_start_time ) ) { + $this->hook_depth++; + } else { + $this->hook_count++; + $this->hook_start_time = microtime( true ); + } } /** * Stop this logger's hook timer */ public function stop_hook_timer() { - if ( ! is_null( $this->hook_start_time ) ) { - $this->hook_time += microtime( true ) - $this->hook_start_time; + if ( $this->hook_depth ) { + $this->hook_depth--; + } else { + if ( ! is_null( $this->hook_start_time ) ) { + $this->hook_time += microtime( true ) - $this->hook_start_time; + } + $this->hook_start_time = null; } - $this->hook_start_time = null; } }