Timings: record peak tick time and active ticks

this information is useful for determining the sizes of lag spikes, and giving more accurate average times.
This commit is contained in:
Dylan K. Taylor 2023-04-06 15:05:40 +01:00
parent 734adec90d
commit bf84caa02c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 19 additions and 5 deletions

View File

@ -58,7 +58,9 @@ class TimingsHandler{
"Violations: " . $timings->getViolations(),
"RecordId: " . $timings->getId(),
"ParentRecordId: " . ($timings->getParentId() ?? "none"),
"TimerId: " . $timings->getTimerId()
"TimerId: " . $timings->getTimerId(),
"Ticks: " . $timings->getTicksActive(),
"Peak: " . $timings->getPeakTime(),
]);
}
$result = [];

View File

@ -59,11 +59,17 @@ final class TimingsRecord{
public static function tick(bool $measure = true) : void{
if($measure){
foreach(self::$records as $record){
if($record->curTickTotal > Server::TARGET_NANOSECONDS_PER_TICK){
$record->violations += (int) floor($record->curTickTotal / Server::TARGET_NANOSECONDS_PER_TICK);
if($record->curCount > 0){
if($record->curTickTotal > Server::TARGET_NANOSECONDS_PER_TICK){
$record->violations += (int) floor($record->curTickTotal / Server::TARGET_NANOSECONDS_PER_TICK);
}
if($record->curTickTotal > $record->peakTime){
$record->peakTime = $record->curTickTotal;
}
$record->curTickTotal = 0;
$record->curCount = 0;
$record->ticksActive++;
}
$record->curTickTotal = 0;
$record->curCount = 0;
}
}else{
foreach(self::$records as $record){
@ -82,6 +88,8 @@ final class TimingsRecord{
private int $totalTime = 0;
private int $curTickTotal = 0;
private int $violations = 0;
private int $ticksActive = 0;
private int $peakTime = 0;
public function __construct(
//I'm not the biggest fan of this cycle, but it seems to be the most effective way to avoid leaking anything.
@ -113,6 +121,10 @@ final class TimingsRecord{
public function getViolations() : int{ return $this->violations; }
public function getTicksActive() : int{ return $this->ticksActive; }
public function getPeakTime() : float{ return $this->peakTime; }
public function startTiming(int $now) : void{
$this->start = $now;
self::$currentRecord = $this;