Skip to content

Commit 7dddb20

Browse files
chore: add a minimal get_timestamp implementation to macos's stubs
This is a band-aid, the real long term solution is to actually have a part of the zig code transpiled to c and usable on macos rather than just stubs.
1 parent 72486c4 commit 7dddb20

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

dist/core.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010

1111
#include "core.h"
1212

13+
#if defined(__APPLE__)
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+
}
27+
#endif
28+
1329
struct InstrumentHooks {
1430
uint64_t _unused;
1531
};
@@ -66,7 +82,13 @@ void instrument_hooks_set_feature(uint64_t feature, bool enabled) {
6682
(void)enabled;
6783
}
6884

69-
uint64_t instrument_hooks_current_timestamp(void) { return 0; }
85+
uint64_t instrument_hooks_current_timestamp(void) {
86+
#if defined(__APPLE__)
87+
return mach_absolute_time() * get_timebase_numer() / get_timebase_denom();
88+
#else
89+
return 0;
90+
#endif
91+
}
7092

7193
uint8_t instrument_hooks_add_marker(InstrumentHooks *hooks, int32_t pid,
7294
uint8_t marker_type, uint64_t timestamp) {

scripts/stub.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33

44
#include "core.h"
55

6+
#if defined(__APPLE__)
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+
}
20+
#endif
21+
622
struct InstrumentHooks {
723
uint64_t _unused;
824
};
@@ -59,7 +75,13 @@ void instrument_hooks_set_feature(uint64_t feature, bool enabled) {
5975
(void)enabled;
6076
}
6177

62-
uint64_t instrument_hooks_current_timestamp(void) { return 0; }
78+
uint64_t instrument_hooks_current_timestamp(void) {
79+
#if defined(__APPLE__)
80+
return mach_absolute_time() * get_timebase_numer() / get_timebase_denom();
81+
#else
82+
return 0;
83+
#endif
84+
}
6385

6486
uint8_t instrument_hooks_add_marker(InstrumentHooks *hooks, int32_t pid,
6587
uint8_t marker_type, uint64_t timestamp) {

0 commit comments

Comments
 (0)