index/src/Performance/TimingPoint.php

88 lines
1.9 KiB
PHP

<?php
// TimingPoint.php
// Created: 2022-02-16
// Updated: 2024-08-01
namespace Index\Performance;
/**
* Represents a timing point.
*/
class TimingPoint {
private int|float $timePoint;
private int|float $duration;
private string $name;
private string $comment;
/**
* @param int|float $timePoint Starting tick count.
* @param int|float $duration Duration ticks count.
* @param string $name Name of the timing point.
* @param string $comment Timing point comment.
*/
public function __construct(
int|float $timePoint,
int|float $duration,
string $name,
string $comment
) {
$this->timePoint = $timePoint;
$this->duration = $duration;
$this->name = $name;
$this->comment = $comment;
}
/**
* Gets the starting ticks count.
*
* @return int|float Starting ticks count.
*/
public function getTimePointTicks(): int|float {
return $this->timePoint;
}
/**
* Gets the duration ticks count.
*
* @return int|float Duration ticks count.
*/
public function getDurationTicks(): int|float {
return $this->duration;
}
/**
* Gets the duration time amount.
*
* @return float Duration time amount.
*/
public function getDurationTime(): float {
return $this->duration / PerformanceCounter::getFrequency();
}
/**
* Gets time point name.
*
* @return string Time point name.
*/
public function getName(): string {
return $this->name;
}
/**
* Checks whether time point has a comment.
*
* @return bool true if the time point has a comment.
*/
public function hasComment(): bool {
return $this->comment !== '';
}
/**
* Gets time point comment.
*
* @return string Time point comment.
*/
public function getComment(): string {
return $this->comment;
}
}