| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/base/platform/time.h" | 5 #include "src/base/platform/time.h" |
| 6 | 6 |
| 7 #if V8_OS_POSIX | 7 #if V8_OS_POSIX |
| 8 #include <fcntl.h> // for O_RDONLY | 8 #include <fcntl.h> // for O_RDONLY |
| 9 #include <sys/time.h> | 9 #include <sys/time.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 static struct mach_timebase_info info; | 541 static struct mach_timebase_info info; |
| 542 if (info.denom == 0) { | 542 if (info.denom == 0) { |
| 543 kern_return_t result = mach_timebase_info(&info); | 543 kern_return_t result = mach_timebase_info(&info); |
| 544 DCHECK_EQ(KERN_SUCCESS, result); | 544 DCHECK_EQ(KERN_SUCCESS, result); |
| 545 USE(result); | 545 USE(result); |
| 546 } | 546 } |
| 547 ticks = (mach_absolute_time() / Time::kNanosecondsPerMicrosecond * | 547 ticks = (mach_absolute_time() / Time::kNanosecondsPerMicrosecond * |
| 548 info.numer / info.denom); | 548 info.numer / info.denom); |
| 549 #elif V8_OS_SOLARIS | 549 #elif V8_OS_SOLARIS |
| 550 ticks = (gethrtime() / Time::kNanosecondsPerMicrosecond); | 550 ticks = (gethrtime() / Time::kNanosecondsPerMicrosecond); |
| 551 #elif V8_LIBRT_NOT_AVAILABLE | |
| 552 // TODO(bmeurer): This is a temporary hack to support cross-compiling | |
| 553 // Chrome for Android in AOSP. Remove this once AOSP is fixed, also | |
| 554 // cleanup the tools/gyp/v8.gyp file. | |
| 555 struct timeval tv; | |
| 556 int result = gettimeofday(&tv, NULL); | |
| 557 DCHECK_EQ(0, result); | |
| 558 USE(result); | |
| 559 ticks = (tv.tv_sec * Time::kMicrosecondsPerSecond + tv.tv_usec); | |
| 560 #elif V8_OS_POSIX | 551 #elif V8_OS_POSIX |
| 561 struct timespec ts; | 552 struct timespec ts; |
| 562 int result = clock_gettime(CLOCK_MONOTONIC, &ts); | 553 int result = clock_gettime(CLOCK_MONOTONIC, &ts); |
| 563 DCHECK_EQ(0, result); | 554 DCHECK_EQ(0, result); |
| 564 USE(result); | 555 USE(result); |
| 565 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + | 556 ticks = (ts.tv_sec * Time::kMicrosecondsPerSecond + |
| 566 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); | 557 ts.tv_nsec / Time::kNanosecondsPerMicrosecond); |
| 567 #endif // V8_OS_MACOSX | 558 #endif // V8_OS_MACOSX |
| 568 // Make sure we never return 0 here. | 559 // Make sure we never return 0 here. |
| 569 return TimeTicks(ticks + 1); | 560 return TimeTicks(ticks + 1); |
| 570 } | 561 } |
| 571 | 562 |
| 572 | 563 |
| 573 // static | 564 // static |
| 574 bool TimeTicks::IsHighResolutionClockWorking() { | 565 bool TimeTicks::IsHighResolutionClockWorking() { |
| 575 return true; | 566 return true; |
| 576 } | 567 } |
| 577 | 568 |
| 578 | 569 |
| 579 #if V8_OS_LINUX && !V8_LIBRT_NOT_AVAILABLE | 570 #if V8_OS_LINUX |
| 580 | 571 |
| 581 class KernelTimestampClock { | 572 class KernelTimestampClock { |
| 582 public: | 573 public: |
| 583 KernelTimestampClock() : clock_fd_(-1), clock_id_(kClockInvalid) { | 574 KernelTimestampClock() : clock_fd_(-1), clock_id_(kClockInvalid) { |
| 584 clock_fd_ = open(kTraceClockDevice, O_RDONLY); | 575 clock_fd_ = open(kTraceClockDevice, O_RDONLY); |
| 585 if (clock_fd_ == -1) { | 576 if (clock_fd_ == -1) { |
| 586 return; | 577 return; |
| 587 } | 578 } |
| 588 clock_id_ = get_clockid(clock_fd_); | 579 clock_id_ = get_clockid(clock_fd_); |
| 589 } | 580 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 #else | 616 #else |
| 626 | 617 |
| 627 class KernelTimestampClock { | 618 class KernelTimestampClock { |
| 628 public: | 619 public: |
| 629 KernelTimestampClock() {} | 620 KernelTimestampClock() {} |
| 630 | 621 |
| 631 int64_t Now() { return 0; } | 622 int64_t Now() { return 0; } |
| 632 bool Available() { return false; } | 623 bool Available() { return false; } |
| 633 }; | 624 }; |
| 634 | 625 |
| 635 #endif // V8_OS_LINUX && !V8_LIBRT_NOT_AVAILABLE | 626 #endif // V8_OS_LINUX |
| 636 | 627 |
| 637 static LazyStaticInstance<KernelTimestampClock, | 628 static LazyStaticInstance<KernelTimestampClock, |
| 638 DefaultConstructTrait<KernelTimestampClock>, | 629 DefaultConstructTrait<KernelTimestampClock>, |
| 639 ThreadSafeInitOnceTrait>::type kernel_tick_clock = | 630 ThreadSafeInitOnceTrait>::type kernel_tick_clock = |
| 640 LAZY_STATIC_INSTANCE_INITIALIZER; | 631 LAZY_STATIC_INSTANCE_INITIALIZER; |
| 641 | 632 |
| 642 | 633 |
| 643 // static | 634 // static |
| 644 TimeTicks TimeTicks::KernelTimestampNow() { | 635 TimeTicks TimeTicks::KernelTimestampNow() { |
| 645 return TimeTicks(kernel_tick_clock.Pointer()->Now()); | 636 return TimeTicks(kernel_tick_clock.Pointer()->Now()); |
| 646 } | 637 } |
| 647 | 638 |
| 648 | 639 |
| 649 // static | 640 // static |
| 650 bool TimeTicks::KernelTimestampAvailable() { | 641 bool TimeTicks::KernelTimestampAvailable() { |
| 651 return kernel_tick_clock.Pointer()->Available(); | 642 return kernel_tick_clock.Pointer()->Available(); |
| 652 } | 643 } |
| 653 | 644 |
| 654 #endif // V8_OS_WIN | 645 #endif // V8_OS_WIN |
| 655 | 646 |
| 656 } } // namespace v8::base | 647 } } // namespace v8::base |
| OLD | NEW |