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

Side by Side 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, 2 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/os_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // gettimeofday has microsecond resolution. 75 // gettimeofday has microsecond resolution.
76 struct timeval tv; 76 struct timeval tv;
77 if (gettimeofday(&tv, NULL) < 0) { 77 if (gettimeofday(&tv, NULL) < 0) {
78 UNREACHABLE(); 78 UNREACHABLE();
79 return 0; 79 return 0;
80 } 80 }
81 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; 81 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
82 } 82 }
83 83
84 84
85 int64_t OS::GetCurrentTraceMicros() {
86 #if defined(TARGET_OS_IOS)
87 // On iOS mach_absolute_time stops while the device is sleeping. Instead use
88 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock
89 // changes. KERN_BOOTTIME will be updated by the system whenever the system
90 // clock change.
91 struct timeval boottime;
92 int mib[2] = {CTL_KERN, KERN_BOOTTIME};
93 size_t size = sizeof(boottime);
94 int kr = sysctl(mib, arraysize(mib), &boottime, &size, NULL, 0);
95 ASSERT(KERN_SUCCESS == kr);
96 int64_t now = GetCurrentTimeMicros();
97 int64_t origin = boottime.tv_sec * kMicrosecondsPerSecond;
98 origin += boottime.tv_usec;
99 return now - origin;
100 #else
101 static mach_timebase_info_data_t timebase_info;
102 if (timebase_info.denom == 0) {
103 // Zero-initialization of statics guarantees that denom will be 0 before
104 // calling mach_timebase_info. mach_timebase_info will never set denom to
105 // 0 as that would be invalid, so the zero-check can be used to determine
106 // whether mach_timebase_info has already been called. This is
107 // recommended by Apple's QA1398.
108 kern_return_t kr = mach_timebase_info(&timebase_info);
109 ASSERT(KERN_SUCCESS == kr);
110 }
111
112 // timebase_info converts absolute time tick units into nanoseconds. Convert
113 // to microseconds.
114 int64_t result = mach_absolute_time() / kNanosecondsPerMicrosecond;
115 result *= timebase_info.numer;
116 result /= timebase_info.denom;
117 return result;
118 #endif // defined(TARGET_OS_IOS)
119 }
120
121
85 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { 122 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) {
86 const int kMinimumAlignment = 16; 123 const int kMinimumAlignment = 16;
87 ASSERT(Utils::IsPowerOfTwo(alignment)); 124 ASSERT(Utils::IsPowerOfTwo(alignment));
88 ASSERT(alignment >= kMinimumAlignment); 125 ASSERT(alignment >= kMinimumAlignment);
89 // Temporary workaround until xcode is upgraded. 126 // Temporary workaround until xcode is upgraded.
90 // Mac guarantees malloc returns a 16 byte aligned memory chunk. 127 // Mac guarantees malloc returns a 16 byte aligned memory chunk.
91 // Currently we only allocate with 16-bye alignment. 128 // Currently we only allocate with 16-bye alignment.
92 ASSERT(alignment == 16); 129 ASSERT(alignment == 16);
93 // TODO(johnmccutchan): Remove hack and switch to posix_memalign. 130 // TODO(johnmccutchan): Remove hack and switch to posix_memalign.
94 return malloc(size); 131 return malloc(size);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 335 }
299 336
300 337
301 void OS::Exit(int code) { 338 void OS::Exit(int code) {
302 exit(code); 339 exit(code);
303 } 340 }
304 341
305 } // namespace dart 342 } // namespace dart
306 343
307 #endif // defined(TARGET_OS_MACOS) 344 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« 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