class SystemClock
@internal OpenTelemetry
Hierarchy
- class \OpenTelemetry\API\Common\Time\SystemClock implements \OpenTelemetry\API\Common\Time\ClockInterface
Expanded class hierarchy of SystemClock
File
-
vendor/
open-telemetry/ api/ Common/ Time/ SystemClock.php, line 13
Namespace
OpenTelemetry\API\Common\TimeView source
final class SystemClock implements ClockInterface {
private static int $referenceTime = 0;
public function __construct() {
self::init();
}
public static function create() : self {
return new self();
}
/** @inheritDoc */
public function now() : int {
return self::$referenceTime + hrtime(true);
}
private static function init() : void {
if (self::$referenceTime > 0) {
return;
}
self::$referenceTime = self::calculateReferenceTime(microtime(true), hrtime(true));
}
/**
* Calculates the reference time which is later used to calculate the current wall clock time in nanoseconds by adding the current uptime.
*/
private static function calculateReferenceTime(float $wallClockMicroTime, int $upTime) : int {
return (int) ($wallClockMicroTime * ClockInterface::NANOS_PER_SECOND) - $upTime;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ClockInterface::NANOS_PER_MICROSECOND | public | constant | ||
ClockInterface::NANOS_PER_MILLISECOND | public | constant | ||
ClockInterface::NANOS_PER_SECOND | public | constant | ||
SystemClock::$referenceTime | private static | property | ||
SystemClock::calculateReferenceTime | private static | function | Calculates the reference time which is later used to calculate the current wall clock time in nanoseconds by adding the current uptime. | |
SystemClock::create | public static | function | ||
SystemClock::init | private static | function | ||
SystemClock::now | public | function | @inheritDoc | Overrides ClockInterface::now |
SystemClock::__construct | public | function |