Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: runtime/vm/os_macos.cc

Issue 1367973004: Make timeline use the same clock source as mojo's tracing infrastructure (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/os_macos.cc
diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc
index ce4003e79af2b198bccc8fced9f2ee25ffdeb23f..9821221c4257255608fd52bb64175d74e900275c 100644
--- a/runtime/vm/os_macos.cc
+++ b/runtime/vm/os_macos.cc
@@ -82,6 +82,43 @@ int64_t OS::GetCurrentTimeMicros() {
}
+int64_t OS::GetCurrentTraceMicros() {
+#if defined(TARGET_OS_IOS)
+ // On iOS mach_absolute_time stops while the device is sleeping. Instead use
+ // now - KERN_BOOTTIME to get a time difference that is not impacted by clock
+ // changes. KERN_BOOTTIME will be updated by the system whenever the system
+ // clock change.
+ struct timeval boottime;
+ int mib[2] = {CTL_KERN, KERN_BOOTTIME};
+ size_t size = sizeof(boottime);
+ int kr = sysctl(mib, arraysize(mib), &boottime, &size, NULL, 0);
+ ASSERT(KERN_SUCCESS == kr);
+ int64_t now = GetCurrentTimeMicros();
+ int64_t origin = boottime.tv_sec * kMicrosecondsPerSecond;
+ origin += boottime.tv_usec;
+ return now - origin;
+#else
+ static mach_timebase_info_data_t timebase_info;
+ if (timebase_info.denom == 0) {
+ // Zero-initialization of statics guarantees that denom will be 0 before
+ // calling mach_timebase_info. mach_timebase_info will never set denom to
+ // 0 as that would be invalid, so the zero-check can be used to determine
+ // whether mach_timebase_info has already been called. This is
+ // recommended by Apple's QA1398.
+ kern_return_t kr = mach_timebase_info(&timebase_info);
+ ASSERT(KERN_SUCCESS == kr);
+ }
+
+ // timebase_info converts absolute time tick units into nanoseconds. Convert
+ // to microseconds.
+ int64_t result = mach_absolute_time() / kNanosecondsPerMicrosecond;
+ result *= timebase_info.numer;
+ result /= timebase_info.denom;
+ return result;
+#endif // defined(TARGET_OS_IOS)
+}
+
+
void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) {
const int kMinimumAlignment = 16;
ASSERT(Utils::IsPowerOfTwo(alignment));
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698