Skip to content

Commit

Permalink
[mac] mach_absolute_time() -> clock_gettime_nsec_np(CLOCK_UPTIME_RAW)
Browse files Browse the repository at this point in the history
https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time

> Prefer to use the equivalent clock_gettime_nsec_np(CLOCK_UPTIME_RAW) in nanoseconds.

The two are equivalent:

https://github.com/apple-oss-distributions/Libc/blob/c5a3293354e22262702a3add5b2dfc9bb0b93b85/gen/clock_gettime.c#L118

Change-Id: I1c7a08d821d1840b74fc5eaa0e9ceca2ade5bbfc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5085307
Commit-Queue: Ben Hamilton <[email protected]>
Reviewed-by: Justin Cohen <[email protected]>
Reviewed-by: Mark Mentovai <[email protected]>
  • Loading branch information
bhamiltoncx authored and Crashpad LUCI CQ committed Dec 12, 2023
1 parent 7049d96 commit 337b4f7
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions util/misc/clock_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,12 @@

#include "util/misc/clock.h"

#include <mach/mach_time.h>

#include "base/apple/mach_logging.h"

namespace {

mach_timebase_info_data_t* TimebaseInternal() {
mach_timebase_info_data_t* timebase_info = new mach_timebase_info_data_t;
kern_return_t kr = mach_timebase_info(timebase_info);
MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_timebase_info";
return timebase_info;
}

mach_timebase_info_data_t* Timebase() {
static mach_timebase_info_data_t* timebase_info = TimebaseInternal();
return timebase_info;
}

} // namespace
#include <time.h>

namespace crashpad {

uint64_t ClockMonotonicNanoseconds() {
uint64_t absolute_time = mach_absolute_time();
mach_timebase_info_data_t* timebase_info = Timebase();
return absolute_time * timebase_info->numer / timebase_info->denom;
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
}

} // namespace crashpad

0 comments on commit 337b4f7

Please sign in to comment.