Skip to content

Commit 40e060d

Browse files
--wip-- [skip ci]
1 parent 0a9e975 commit 40e060d

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

dist/core.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@
1111
#include "core.h"
1212

1313
#if defined(__APPLE__)
14-
#include <time.h>
14+
#include <mach/mach_time.h>
15+
16+
static uint64_t get_timebase_numer(void) {
17+
mach_timebase_info_data_t info;
18+
mach_timebase_info(&info);
19+
return info.numer;
20+
}
21+
22+
static uint64_t get_timebase_denom(void) {
23+
mach_timebase_info_data_t info;
24+
mach_timebase_info(&info);
25+
return info.denom;
26+
}
1527
#endif
1628

1729
struct InstrumentHooks {
@@ -72,9 +84,7 @@ void instrument_hooks_set_feature(uint64_t feature, bool enabled) {
7284

7385
uint64_t instrument_hooks_current_timestamp(void) {
7486
#if defined(__APPLE__)
75-
struct timespec ts;
76-
clock_gettime(CLOCK_MONOTONIC, &ts);
77-
return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec;
87+
return mach_absolute_time() * get_timebase_numer() / get_timebase_denom();
7888
#else
7989
return 0;
8090
#endif

scripts/stub.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
#include "core.h"
55

66
#if defined(__APPLE__)
7-
#include <time.h>
7+
#include <mach/mach_time.h>
8+
9+
static uint64_t get_timebase_numer(void) {
10+
mach_timebase_info_data_t info;
11+
mach_timebase_info(&info);
12+
return info.numer;
13+
}
14+
15+
static uint64_t get_timebase_denom(void) {
16+
mach_timebase_info_data_t info;
17+
mach_timebase_info(&info);
18+
return info.denom;
19+
}
820
#endif
921

1022
struct InstrumentHooks {
@@ -65,9 +77,7 @@ void instrument_hooks_set_feature(uint64_t feature, bool enabled) {
6577

6678
uint64_t instrument_hooks_current_timestamp(void) {
6779
#if defined(__APPLE__)
68-
struct timespec ts;
69-
clock_gettime(CLOCK_MONOTONIC, &ts);
70-
return (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec;
80+
return mach_absolute_time() * get_timebase_numer() / get_timebase_denom();
7181
#else
7282
return 0;
7383
#endif

0 commit comments

Comments
 (0)