[mac] mach_absolute_time() -> clock_gettime_nsec_np(CLOCK_UPTIME_RAW)

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:

c5a3293354/gen/clock_gettime.c (L118)

Change-Id: I1c7a08d821d1840b74fc5eaa0e9ceca2ade5bbfc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5085307
Commit-Queue: Ben Hamilton <benhamilton@google.com>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Ben Hamilton 2023-12-12 10:54:51 -07:00 committed by Crashpad LUCI CQ
parent 7049d966b5
commit 337b4f7971

View File

@ -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