*/ private static $records = []; public static function clearRecords() : void{ foreach(self::$records as $record){ $record->handler->destroyCycles(); } self::$records = []; } /** * @return self[] * @phpstan-return array */ public static function getAll() : array{ return self::$records; } public static function tick(bool $measure = true) : void{ if($measure){ foreach(self::$records as $record){ if($record->curTickTotal > 50000000){ $record->violations += (int) round($record->curTickTotal / 50000000); } $record->curTickTotal = 0; $record->curCount = 0; } }else{ foreach(self::$records as $record){ $record->totalTime -= $record->curTickTotal; $record->count -= $record->curCount; $record->curTickTotal = 0; $record->curCount = 0; } } } /** @var TimingsHandler */ private $handler; /** @var int */ private $count = 0; /** @var int */ private $curCount = 0; /** @var int */ private $start = 0; /** @var int */ private $totalTime = 0; /** @var int */ private $curTickTotal = 0; /** @var int */ private $violations = 0; public function __construct(TimingsHandler $handler){ self::$records[spl_object_id($this)] = $this; //I'm not the biggest fan of this cycle, but it seems to be the most effective way to avoid leaking anything. $this->handler = $handler; } public function getName() : string{ return $this->handler->getName(); } public function getCount() : int{ return $this->count; } public function getCurCount() : int{ return $this->curCount; } public function getStart() : float{ return $this->start; } public function getTotalTime() : float{ return $this->totalTime; } public function getCurTickTotal() : float{ return $this->curTickTotal; } public function getViolations() : int{ return $this->violations; } public function startTiming(int $now) : void{ $this->start = $now; } public function stopTiming(int $now) : void{ if($this->start == 0){ return; } $diff = $now - $this->start; $this->totalTime += $diff; $this->curTickTotal += $diff; ++$this->curCount; ++$this->count; $this->start = 0; } }