Merge commit 'cef77907c6b21e1fb167bc3085d00a5b1e740813'

# Conflicts:
#	resources/vanilla
#	src/timings/TimingsHandler.php
This commit is contained in:
Dylan K. Taylor 2020-01-04 16:21:05 +00:00
commit d25e0c3d98

View File

@ -156,18 +156,28 @@ class TimingsHandler{
self::$HANDLERS[spl_object_id($this)] = $this; self::$HANDLERS[spl_object_id($this)] = $this;
} }
public function startTiming() : void{ public function startTiming() : void{
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() : void{ public function stopTiming() : void{
if(self::$enabled){ if(self::$enabled){
$this->internalStopTiming(microtime(true));
}
}
private function internalStopTiming(float $now) : void{
if($this->timingDepth === 0){ if($this->timingDepth === 0){
throw new \InvalidStateException("Cannot stop a timer that is not running"); throw new \InvalidStateException("Cannot stop a timer that is not running");
} }
@ -175,15 +185,14 @@ class TimingsHandler{
return; return;
} }
$diff = microtime(true) - $this->start; $diff = $now - $this->start;
$this->totalTime += $diff; $this->totalTime += $diff;
$this->curTickTotal += $diff; $this->curTickTotal += $diff;
++$this->curCount; ++$this->curCount;
++$this->count; ++$this->count;
$this->start = 0; $this->start = 0;
if($this->parent !== null){ if($this->parent !== null){
$this->parent->stopTiming(); $this->parent->internalStopTiming($now);
}
} }
} }