mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:38:51 +08:00
Merge pull request #24 from runcommand/fix-hook-time
Fix calculated hook time
This commit is contained in:
commit
5e84ef9022
1 changed files with 15 additions and 5 deletions
|
@ -13,6 +13,7 @@ class Logger {
|
||||||
private $start_time = null;
|
private $start_time = null;
|
||||||
private $query_offset = null;
|
private $query_offset = null;
|
||||||
private $hook_start_time = null;
|
private $hook_start_time = null;
|
||||||
|
private $hook_depth = 0;
|
||||||
|
|
||||||
public static $active_loggers = array();
|
public static $active_loggers = array();
|
||||||
|
|
||||||
|
@ -59,18 +60,27 @@ class Logger {
|
||||||
* Start this logger's hook timer
|
* Start this logger's hook timer
|
||||||
*/
|
*/
|
||||||
public function start_hook_timer() {
|
public function start_hook_timer() {
|
||||||
|
// 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_count++;
|
||||||
$this->hook_start_time = microtime( true );
|
$this->hook_start_time = microtime( true );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop this logger's hook timer
|
* Stop this logger's hook timer
|
||||||
*/
|
*/
|
||||||
public function stop_hook_timer() {
|
public function stop_hook_timer() {
|
||||||
|
if ( $this->hook_depth ) {
|
||||||
|
$this->hook_depth--;
|
||||||
|
} else {
|
||||||
if ( ! is_null( $this->hook_start_time ) ) {
|
if ( ! is_null( $this->hook_start_time ) ) {
|
||||||
$this->hook_time += microtime( true ) - $this->hook_start_time;
|
$this->hook_time += microtime( true ) - $this->hook_start_time;
|
||||||
}
|
}
|
||||||
$this->hook_start_time = null;
|
$this->hook_start_time = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue