41 private static array $records = [];
43 private static ?
self $currentRecord =
null;
48 public static function reset() :
void{
49 foreach(self::$records as $record){
50 $record->handler->reset();
53 self::$currentRecord =
null;
60 public static function getAll() : array{ return self::$records; }
62 public static function tick(
bool $measure =
true) : void{
64 foreach(self::$records as $record){
65 if($record->curCount > 0){
66 if($record->curTickTotal > Server::TARGET_NANOSECONDS_PER_TICK){
67 $record->violations += (int) floor($record->curTickTotal / Server::TARGET_NANOSECONDS_PER_TICK);
69 $record->curTickTotal = 0;
70 $record->curCount = 0;
71 $record->ticksActive++;
75 foreach(self::$records as $record){
76 $record->totalTime -= $record->curTickTotal;
77 $record->count -= $record->curCount;
79 $record->curTickTotal = 0;
80 $record->curCount = 0;
85 private int $count = 0;
86 private int $curCount = 0;
87 private int $start = 0;
88 private int $totalTime = 0;
89 private int $curTickTotal = 0;
90 private int $violations = 0;
91 private int $ticksActive = 0;
92 private int $peakTime = 0;
94 public function __construct(
96 private TimingsHandler $handler,
97 private ?TimingsRecord $parentRecord
99 self::$records[spl_object_id($this)] = $this;
102 public function getId() : int{ return spl_object_id($this); }
104 public function getParentId() : ?int{ return $this->parentRecord?->getId(); }
106 public function getTimerId() : int{ return spl_object_id($this->handler); }
108 public function getName() : string{ return $this->handler->getName(); }
110 public function getGroup() : string{ return $this->handler->getGroup(); }
112 public function getCount() : int{ return $this->count; }
114 public function getCurCount() : int{ return $this->curCount; }
116 public function getStart() : float{ return $this->start; }
118 public function getTotalTime() : float{ return $this->totalTime; }
120 public function getCurTickTotal() : float{ return $this->curTickTotal; }
122 public function getViolations() : int{ return $this->violations; }
124 public function getTicksActive() : int{ return $this->ticksActive; }
126 public function getPeakTime() : int{ return $this->peakTime; }
128 public function startTiming(
int $now) : void{
130 self::$currentRecord = $this;
133 public function stopTiming(
int $now) : void{
134 if($this->start == 0){
137 if(self::$currentRecord !== $this){
138 if(self::$currentRecord ===
null){
143 throw new AssumptionFailedError(
"stopTiming() called on a non-current timer");
145 self::$currentRecord = $this->parentRecord;
146 $diff = $now - $this->start;
147 $this->totalTime += $diff;
148 $this->curTickTotal += $diff;
152 if($diff > $this->peakTime){
153 $this->peakTime = $diff;
157 public static function getCurrentRecord() : ?self{
158 return self::$currentRecord;