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

Side by Side Diff: runtime/vm/os_android.cc

Issue 1563473002: Refactor monotonic clock interface and use raw tick values in stopwatch (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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.h ('k') | runtime/vm/os_linux.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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <android/log.h> // NOLINT 10 #include <android/log.h> // NOLINT
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // gettimeofday has microsecond resolution. 172 // gettimeofday has microsecond resolution.
173 struct timeval tv; 173 struct timeval tv;
174 if (gettimeofday(&tv, NULL) < 0) { 174 if (gettimeofday(&tv, NULL) < 0) {
175 UNREACHABLE(); 175 UNREACHABLE();
176 return 0; 176 return 0;
177 } 177 }
178 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; 178 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
179 } 179 }
180 180
181 181
182 int64_t OS::GetCurrentMonotonicMicros() { 182 int64_t OS::GetCurrentMonotonicTicks() {
183 struct timespec ts; 183 struct timespec ts;
184 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { 184 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
185 UNREACHABLE(); 185 UNREACHABLE();
186 return 0; 186 return 0;
187 } 187 }
188 // Convert to microseconds. 188 // Convert to nanoseconds.
189 int64_t result = ts.tv_sec; 189 int64_t result = ts.tv_sec;
190 result *= kMicrosecondsPerSecond; 190 result *= kNanosecondsPerSecond;
191 result += (ts.tv_nsec / kNanosecondsPerMicrosecond); 191 result += ts.tv_nsec;
192 return result; 192 return result;
193 } 193 }
194 194
195 195
196 int64_t OS::GetCurrentMonotonicFrequency() {
197 return kNanosecondsPerSecond;
198 }
199
200
201 int64_t OS::GetCurrentMonotonicMicros() {
202 int64_t ticks = GetCurrentMonotonicTicks();
203 ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond);
204 return ticks / kNanosecondsPerMicrosecond;
205 }
206
207
196 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { 208 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) {
197 const int kMinimumAlignment = 16; 209 const int kMinimumAlignment = 16;
198 ASSERT(Utils::IsPowerOfTwo(alignment)); 210 ASSERT(Utils::IsPowerOfTwo(alignment));
199 ASSERT(alignment >= kMinimumAlignment); 211 ASSERT(alignment >= kMinimumAlignment);
200 void* p = memalign(alignment, size); 212 void* p = memalign(alignment, size);
201 if (p == NULL) { 213 if (p == NULL) {
202 UNREACHABLE(); 214 UNREACHABLE();
203 } 215 }
204 return p; 216 return p;
205 } 217 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 468 }
457 469
458 470
459 void OS::Exit(int code) { 471 void OS::Exit(int code) {
460 exit(code); 472 exit(code);
461 } 473 }
462 474
463 } // namespace dart 475 } // namespace dart
464 476
465 #endif // defined(TARGET_OS_ANDROID) 477 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/vm/os.h ('k') | runtime/vm/os_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698