Timings: fixed grandparent timers not working correctly, closes #3229

This commit is contained in:
Dylan K. Taylor 2020-01-04 13:23:04 +00:00
parent 06ec8b8397
commit cef77907c6

View File

@ -158,32 +158,42 @@ class TimingsHandler{
} }
public function startTiming(){ public function startTiming(){
if(self::$enabled and ++$this->timingDepth === 1){ if(self::$enabled){
$this->start = microtime(true); $this->internalStartTiming(microtime(true));
if($this->parent !== null and ++$this->parent->timingDepth === 1){ }
$this->parent->start = $this->start; }
private function internalStartTiming(float $now) : void{
if(++$this->timingDepth === 1){
$this->start = $now;
if($this->parent !== null){
$this->parent->internalStartTiming($now);
} }
} }
} }
public function stopTiming(){ public function stopTiming(){
if(self::$enabled){ if(self::$enabled){
if($this->timingDepth === 0){ $this->internalStopTiming(microtime(true));
throw new \InvalidStateException("Cannot stop a timer that is not running"); }
} }
if(--$this->timingDepth !== 0 or $this->start == 0){
return;
}
$diff = microtime(true) - $this->start; private function internalStopTiming(float $now) : void{
$this->totalTime += $diff; if($this->timingDepth === 0){
$this->curTickTotal += $diff; throw new \InvalidStateException("Cannot stop a timer that is not running");
++$this->curCount; }
++$this->count; if(--$this->timingDepth !== 0 or $this->start == 0){
$this->start = 0; return;
if($this->parent !== null){ }
$this->parent->stopTiming();
} $diff = $now - $this->start;
$this->totalTime += $diff;
$this->curTickTotal += $diff;
++$this->curCount;
++$this->count;
$this->start = 0;
if($this->parent !== null){
$this->parent->internalStopTiming($now);
} }
} }