Coverage Report

Created: 2026-10-28 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/Zend/zend_hrtime.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Author: Niklas Keller <kelunik@php.net>                              |
12
   | Author: Anatol Belski <ab@php.net>                                   |
13
   +----------------------------------------------------------------------+
14
 */
15
16
#include "zend.h"
17
#include "zend_hrtime.h"
18
19
/* This file reuses code parts from the cross-platform timer library
20
  Public Domain - 2011 Mattias Jansson / Rampant Pixels */
21
22
#if ZEND_HRTIME_PLATFORM_POSIX
23
24
# include <unistd.h>
25
# include <time.h>
26
# include <string.h>
27
28
#elif ZEND_HRTIME_PLATFORM_WINDOWS
29
30
# define WIN32_LEAN_AND_MEAN
31
32
ZEND_API double zend_hrtime_timer_scale = .0;
33
34
#elif ZEND_HRTIME_PLATFORM_APPLE_MACH_ABSOLUTE
35
36
# include <mach/mach_time.h>
37
# include <string.h>
38
ZEND_API mach_timebase_info_data_t zend_hrtime_timerlib_info = {
39
  .numer = 0,
40
  .denom = 1,
41
};
42
43
#elif ZEND_HRTIME_PLATFORM_HPUX
44
45
# include <sys/time.h>
46
47
#elif ZEND_HRTIME_PLATFORM_AIX
48
49
# include <sys/time.h>
50
# include <sys/systemcfg.h>
51
52
#endif
53
54
void zend_startup_hrtime(void)
55
16
{
56
#if ZEND_HRTIME_PLATFORM_WINDOWS
57
58
  LARGE_INTEGER tf = {0};
59
  if (QueryPerformanceFrequency(&tf) || 0 != tf.QuadPart) {
60
    zend_hrtime_timer_scale = (double)ZEND_NANO_IN_SEC / (zend_hrtime_t)tf.QuadPart;
61
  }
62
63
#elif ZEND_HRTIME_PLATFORM_APPLE_MACH_ABSOLUTE
64
65
  mach_timebase_info(&zend_hrtime_timerlib_info);
66
67
#elif ZEND_HRTIME_PLATFORM_POSIX
68
69
16
  struct timespec ts;
70
71
16
  if (EXPECTED(0 == clock_gettime(CLOCK_MONOTONIC, &ts))) {
72
16
    return;
73
16
  }
74
75
  // zend_error mechanism is not initialized at that point
76
0
  fprintf(stderr, "No working CLOCK_MONOTONIC found, this should never happen\n");
77
0
  abort();
78
79
16
#endif
80
16
}