1commit f00c7bccf7955b7dfbb4859fd9019e9eb3349f2d
2Author: Tobias Mayer <tobim@fastmail.fm>
3Date: Wed Feb 13 12:44:17 2019 +0100
4
5 Provide clock_gettime for xray on macos < 10.12
6
7diff --git a/lib/xray/xray_basic_logging.cc b/lib/xray/xray_basic_logging.cc
8index a46c151af..38aea6932 100644
9--- a/lib/xray/xray_basic_logging.cc
10+++ b/lib/xray/xray_basic_logging.cc
11@@ -36,6 +36,29 @@
12 #include "xray_tsc.h"
13 #include "xray_utils.h"
14
15+#if __MACH__
16+#include <mach/clock.h>
17+#include <mach/mach.h>
18+enum clockid_t {
19+ CLOCK_MONOTONIC = REALTIME_CLOCK,
20+ CLOCK_REALTIME = REALTIME_CLOCK
21+};
22+
23+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
24+ if (ts != NULL) {
25+ clock_serv_t cclock;
26+ mach_timespec_t mts;
27+ host_get_clock_service(mach_host_self(), clock_id, &cclock);
28+ clock_get_time(cclock, &mts);
29+ mach_port_deallocate(mach_task_self(), cclock);
30+ ts->tv_sec = mts.tv_sec;
31+ ts->tv_nsec = mts.tv_nsec;
32+ return 0;
33+ }
34+ return -1;
35+}
36+#endif
37+
38 namespace __xray {
39
40 SpinMutex LogMutex;
41diff --git a/lib/xray/xray_fdr_logging.cc b/lib/xray/xray_fdr_logging.cc
42index 4b308b27f..1d044c8fd 100644
43--- a/lib/xray/xray_fdr_logging.cc
44+++ b/lib/xray/xray_fdr_logging.cc
45@@ -38,6 +38,29 @@
46 #include "xray_tsc.h"
47 #include "xray_utils.h"
48
49+#if __MACH__
50+#include <mach/clock.h>
51+#include <mach/mach.h>
52+enum clockid_t {
53+ CLOCK_MONOTONIC = REALTIME_CLOCK,
54+ CLOCK_REALTIME = REALTIME_CLOCK
55+};
56+
57+int clock_gettime(clockid_t clock_id, struct timespec *ts) {
58+ if (ts != NULL) {
59+ clock_serv_t cclock;
60+ mach_timespec_t mts;
61+ host_get_clock_service(mach_host_self(), clock_id, &cclock);
62+ clock_get_time(cclock, &mts);
63+ mach_port_deallocate(mach_task_self(), cclock);
64+ ts->tv_sec = mts.tv_sec;
65+ ts->tv_nsec = mts.tv_nsec;
66+ return 0;
67+ }
68+ return -1;
69+}
70+#endif
71+
72 namespace __xray {
73
74 atomic_sint32_t LoggingStatus = {XRayLogInitStatus::XRAY_LOG_UNINITIALIZED};