Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 "base/time/time.h" | 5 #include "base/time/time.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CFDate.h> | 7 #include <CoreFoundation/CFDate.h> |
| 8 #include <CoreFoundation/CFTimeZone.h> | 8 #include <CoreFoundation/CFTimeZone.h> |
| 9 #include <mach/mach_init.h> | |
|
Robert Sesek
2013/11/05 18:32:07
Include mach/mach.h instead. It will also include
fmeawad
2013/11/05 19:34:25
Done.
| |
| 10 #include <mach/mach_port.h> | |
| 9 #include <mach/mach_time.h> | 11 #include <mach/mach_time.h> |
| 12 #include <mach/thread_act.h> | |
| 13 | |
|
Robert Sesek
2013/11/05 18:32:07
nit: remove this blank line
fmeawad
2013/11/05 19:34:25
Done.
| |
| 10 #include <sys/sysctl.h> | 14 #include <sys/sysctl.h> |
| 11 #include <sys/time.h> | 15 #include <sys/time.h> |
| 12 #include <sys/types.h> | 16 #include <sys/types.h> |
| 13 #include <time.h> | 17 #include <time.h> |
| 14 | 18 |
| 15 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 16 #include "base/logging.h" | 20 #include "base/logging.h" |
| 17 #include "base/mac/scoped_cftyperef.h" | 21 #include "base/mac/scoped_cftyperef.h" |
| 18 | 22 |
| 19 namespace { | 23 namespace { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 mach_absolute_time() / base::Time::kNanosecondsPerMicrosecond * | 61 mach_absolute_time() / base::Time::kNanosecondsPerMicrosecond * |
| 58 timebase_info.numer / timebase_info.denom; | 62 timebase_info.numer / timebase_info.denom; |
| 59 | 63 |
| 60 // Don't bother with the rollover handling that the Windows version does. | 64 // Don't bother with the rollover handling that the Windows version does. |
| 61 // With numer and denom = 1 (the expected case), the 64-bit absolute time | 65 // With numer and denom = 1 (the expected case), the 64-bit absolute time |
| 62 // reported in nanoseconds is enough to last nearly 585 years. | 66 // reported in nanoseconds is enough to last nearly 585 years. |
| 63 return absolute_micro; | 67 return absolute_micro; |
| 64 #endif // defined(OS_IOS) | 68 #endif // defined(OS_IOS) |
| 65 } | 69 } |
| 66 | 70 |
| 71 uint64_t ComputeThreadTicks() { | |
| 72 #if defined(OS_IOS) | |
| 73 NOTREACHED(); | |
|
Robert Sesek
2013/11/05 18:32:07
NOTREACHED() or NOTIMPLEMENTED()? Can this be impl
fmeawad
2013/11/05 19:34:25
It can be implemented, but it should not be reache
fmeawad
2013/11/05 21:59:49
Done.
| |
| 74 return 0; | |
| 75 #else | |
| 76 mach_port_t thread; | |
|
Robert Sesek
2013/11/05 18:32:07
Why break up declaration from initialization?
fmeawad
2013/11/05 19:34:25
Done.
| |
| 77 mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT; | |
| 78 thread_basic_info_data_t thread_info_data; | |
| 79 | |
| 80 thread = mach_thread_self(); | |
|
Robert Sesek
2013/11/05 18:32:07
This is leaked. Store this in a ScopedMachPort.
fmeawad
2013/11/05 19:34:25
Done.
| |
| 81 if (thread == MACH_PORT_NULL) | |
| 82 return 0; | |
| 83 | |
| 84 kern_return_t kr; | |
|
Robert Sesek
2013/11/05 18:32:07
Same. No need to break up declaration from initial
fmeawad
2013/11/05 19:34:25
Done.
| |
| 85 | |
| 86 kr = thread_info(thread, | |
| 87 THREAD_BASIC_INFO, | |
| 88 reinterpret_cast<thread_info_t>(&thread_info_data), | |
| 89 &thread_info_count); | |
| 90 | |
| 91 if (kr != KERN_SUCCESS) { | |
| 92 return 0; | |
|
Robert Sesek
2013/11/05 18:32:07
No logging or DCHECKing for failure?
fmeawad
2013/11/05 19:34:25
Done.
| |
| 93 } | |
| 94 | |
| 95 return (thread_info_data.user_time.seconds * | |
| 96 base::Time::kMicrosecondsPerSecond) + | |
| 97 thread_info_data.user_time.microseconds; | |
|
Robert Sesek
2013/11/05 18:32:07
nit: align this to underneath the (
fmeawad
2013/11/05 19:34:25
Done.
| |
| 98 #endif // defined(OS_IOS) | |
| 99 } | |
| 100 | |
| 67 } // namespace | 101 } // namespace |
| 68 | 102 |
| 69 namespace base { | 103 namespace base { |
| 70 | 104 |
| 71 // The Time routines in this file use Mach and CoreFoundation APIs, since the | 105 // The Time routines in this file use Mach and CoreFoundation APIs, since the |
| 72 // POSIX definition of time_t in Mac OS X wraps around after 2038--and | 106 // POSIX definition of time_t in Mac OS X wraps around after 2038--and |
| 73 // there are already cookie expiration dates, etc., past that time out in | 107 // there are already cookie expiration dates, etc., past that time out in |
| 74 // the field. Using CFDate prevents that problem, and using mach_absolute_time | 108 // the field. Using CFDate prevents that problem, and using mach_absolute_time |
| 75 // for TimeTicks gives us nice high-resolution interval timing. | 109 // for TimeTicks gives us nice high-resolution interval timing. |
| 76 | 110 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 return Now(); | 223 return Now(); |
| 190 } | 224 } |
| 191 | 225 |
| 192 // static | 226 // static |
| 193 bool TimeTicks::IsHighResNowFastAndReliable() { | 227 bool TimeTicks::IsHighResNowFastAndReliable() { |
| 194 return true; | 228 return true; |
| 195 } | 229 } |
| 196 | 230 |
| 197 // static | 231 // static |
| 198 TimeTicks TimeTicks::ThreadNow() { | 232 TimeTicks TimeTicks::ThreadNow() { |
| 199 NOTREACHED(); | 233 return TimeTicks(ComputeThreadTicks()); |
| 200 return TimeTicks(); | |
| 201 } | 234 } |
| 202 | 235 |
| 203 // static | 236 // static |
| 204 TimeTicks TimeTicks::NowFromSystemTraceTime() { | 237 TimeTicks TimeTicks::NowFromSystemTraceTime() { |
| 205 return HighResNow(); | 238 return HighResNow(); |
| 206 } | 239 } |
| 207 | 240 |
| 208 } // namespace base | 241 } // namespace base |
| OLD | NEW |