Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SystemClock.php

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\Time
View 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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal