Skip to content

Commit

Permalink
Merge "Use clock_gettime to get thread time on Mac" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Khokhlov authored and Gerrit Code Review committed Sep 29, 2023
2 parents e879b2e + a093f9a commit 5773ad9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/perfetto/base/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ inline TimeNanos GetBootTimeNs() {
return GetWallTimeNs();
}

// Before MacOS 10.12 clock_gettime() was not implemented.
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101200
inline TimeNanos GetThreadCPUTimeNs() {
mach_port_t this_thread = mach_thread_self();
mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
Expand All @@ -102,6 +104,13 @@ inline TimeNanos GetThreadCPUTimeNs() {
info.system_time.seconds * 1000000000LL +
info.system_time.microseconds * 1000LL);
}
#else
inline TimeNanos GetThreadCPUTimeNs() {
struct timespec ts = {};
PERFETTO_CHECK(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) == 0);
return FromPosixTimespec(ts);
}
#endif

#elif PERFETTO_BUILDFLAG(PERFETTO_OS_WASM)

Expand Down

0 comments on commit 5773ad9

Please sign in to comment.