File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
1729struct InstrumentHooks {
@@ -72,9 +84,7 @@ void instrument_hooks_set_feature(uint64_t feature, bool enabled) {
7284
7385uint64_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
Original file line number Diff line number Diff line change 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
1022struct InstrumentHooks {
@@ -65,9 +77,7 @@ void instrument_hooks_set_feature(uint64_t feature, bool enabled) {
6577
6678uint64_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
You can’t perform that action at this time.
0 commit comments