mach_time_mac.mm 908 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/power_metrics/mach_time_mac.h"
  5. #include "base/check.h"
  6. #include "base/mac/mach_logging.h"
  7. namespace power_metrics {
  8. uint64_t MachTimeToNs(uint64_t mach_time,
  9. const mach_timebase_info_data_t& mach_timebase) {
  10. if (mach_timebase.numer == mach_timebase.denom)
  11. return mach_time;
  12. CHECK(!__builtin_umulll_overflow(mach_time, mach_timebase.numer, &mach_time));
  13. return mach_time / mach_timebase.denom;
  14. }
  15. mach_timebase_info_data_t GetSystemMachTimeBase() {
  16. mach_timebase_info_data_t info;
  17. kern_return_t kr = mach_timebase_info(&info);
  18. MACH_DCHECK(kr == KERN_SUCCESS, kr) << "mach_timebase_info";
  19. DCHECK(info.numer);
  20. DCHECK(info.denom);
  21. return info;
  22. }
  23. } // namespace power_metrics