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 23 matching lines...) Expand all Loading... |
34 mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT; | 34 mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT; |
35 thread_basic_info_data_t thread_info_data; | 35 thread_basic_info_data_t thread_info_data; |
36 kern_return_t kr = thread_info( | 36 kern_return_t kr = thread_info( |
37 pthread_mach_thread_np(pthread_self()), | 37 pthread_mach_thread_np(pthread_self()), |
38 THREAD_BASIC_INFO, | 38 THREAD_BASIC_INFO, |
39 reinterpret_cast<thread_info_t>(&thread_info_data), | 39 reinterpret_cast<thread_info_t>(&thread_info_data), |
40 &thread_info_count); | 40 &thread_info_count); |
41 CHECK(kr == KERN_SUCCESS); | 41 CHECK(kr == KERN_SUCCESS); |
42 | 42 |
43 v8::base::CheckedNumeric<int64_t> absolute_micros( | 43 v8::base::CheckedNumeric<int64_t> absolute_micros( |
44 thread_info_data.user_time.seconds); | 44 thread_info_data.user_time.seconds + |
| 45 thread_info_data.system_time.seconds); |
45 absolute_micros *= v8::base::Time::kMicrosecondsPerSecond; | 46 absolute_micros *= v8::base::Time::kMicrosecondsPerSecond; |
46 absolute_micros += thread_info_data.user_time.microseconds; | 47 absolute_micros += (thread_info_data.user_time.microseconds + |
| 48 thread_info_data.system_time.microseconds); |
47 return absolute_micros.ValueOrDie(); | 49 return absolute_micros.ValueOrDie(); |
48 } | 50 } |
49 #elif V8_OS_POSIX | 51 #elif V8_OS_POSIX |
50 // Helper function to get results from clock_gettime() and convert to a | 52 // Helper function to get results from clock_gettime() and convert to a |
51 // microsecond timebase. Minimum requirement is MONOTONIC_CLOCK to be supported | 53 // microsecond timebase. Minimum requirement is MONOTONIC_CLOCK to be supported |
52 // on the system. FreeBSD 6 has CLOCK_MONOTONIC but defines | 54 // on the system. FreeBSD 6 has CLOCK_MONOTONIC but defines |
53 // _POSIX_MONOTONIC_CLOCK to -1. | 55 // _POSIX_MONOTONIC_CLOCK to -1. |
54 inline int64_t ClockNow(clockid_t clk_id) { | 56 inline int64_t ClockNow(clockid_t clk_id) { |
55 #if (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ | 57 #if (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ |
56 defined(V8_OS_BSD) || defined(V8_OS_ANDROID) | 58 defined(V8_OS_BSD) || defined(V8_OS_ANDROID) |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 defined(V8_OS_ANDROID) | 624 defined(V8_OS_ANDROID) |
623 return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID)); | 625 return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID)); |
624 #else | 626 #else |
625 UNREACHABLE(); | 627 UNREACHABLE(); |
626 return ThreadTicks(); | 628 return ThreadTicks(); |
627 #endif | 629 #endif |
628 } | 630 } |
629 | 631 |
630 } // namespace base | 632 } // namespace base |
631 } // namespace v8 | 633 } // namespace v8 |
OLD | NEW |