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

Breadcrumb

  1. Drupal Core 11.1.x

SystemClock.php

Namespace

OpenTelemetry\API\Common\Time

File

vendor/open-telemetry/api/Common/Time/SystemClock.php

View source
<?php

declare (strict_types=1);
namespace OpenTelemetry\API\Common\Time;

use function hrtime;
use function microtime;

/**
 * @internal OpenTelemetry
 */
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;
    }

}

Classes

Title Deprecated Summary
SystemClock @internal OpenTelemetry

API Navigation

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