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

Side by Side Diff: base/time/time_mac.cc

Issue 278923002: Use the new ScopedMachVM class and the MACH_LOG family of logging macros (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase onto r269793 Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « base/threading/platform_thread_mac.mm ('k') | chrome/browser/mac/install_from_dmg.mm » ('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 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.h> 9 #include <mach/mach.h>
10 #include <mach/mach_time.h> 10 #include <mach/mach_time.h>
11 #include <sys/sysctl.h> 11 #include <sys/sysctl.h>
12 #include <sys/time.h> 12 #include <sys/time.h>
13 #include <sys/types.h> 13 #include <sys/types.h>
14 #include <time.h> 14 #include <time.h>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/mach_logging.h"
18 #include "base/mac/scoped_cftyperef.h" 19 #include "base/mac/scoped_cftyperef.h"
19 #include "base/mac/scoped_mach_port.h" 20 #include "base/mac/scoped_mach_port.h"
20 21
21 namespace { 22 namespace {
22 23
23 uint64_t ComputeCurrentTicks() { 24 uint64_t ComputeCurrentTicks() {
24 #if defined(OS_IOS) 25 #if defined(OS_IOS)
25 // On iOS mach_absolute_time stops while the device is sleeping. Instead use 26 // On iOS mach_absolute_time stops while the device is sleeping. Instead use
26 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock 27 // now - KERN_BOOTTIME to get a time difference that is not impacted by clock
27 // changes. KERN_BOOTTIME will be updated by the system whenever the system 28 // changes. KERN_BOOTTIME will be updated by the system whenever the system
(...skipping 11 matching lines...) Expand all
39 uint64_t absolute_micro; 40 uint64_t absolute_micro;
40 41
41 static mach_timebase_info_data_t timebase_info; 42 static mach_timebase_info_data_t timebase_info;
42 if (timebase_info.denom == 0) { 43 if (timebase_info.denom == 0) {
43 // Zero-initialization of statics guarantees that denom will be 0 before 44 // Zero-initialization of statics guarantees that denom will be 0 before
44 // calling mach_timebase_info. mach_timebase_info will never set denom to 45 // calling mach_timebase_info. mach_timebase_info will never set denom to
45 // 0 as that would be invalid, so the zero-check can be used to determine 46 // 0 as that would be invalid, so the zero-check can be used to determine
46 // whether mach_timebase_info has already been called. This is 47 // whether mach_timebase_info has already been called. This is
47 // recommended by Apple's QA1398. 48 // recommended by Apple's QA1398.
48 kern_return_t kr = mach_timebase_info(&timebase_info); 49 kern_return_t kr = mach_timebase_info(&timebase_info);
49 DCHECK_EQ(KERN_SUCCESS, kr); 50 MACH_DCHECK(kr == KERN_SUCCESS, kr) << "mach_timebase_info";
50 } 51 }
51 52
52 // mach_absolute_time is it when it comes to ticks on the Mac. Other calls 53 // mach_absolute_time is it when it comes to ticks on the Mac. Other calls
53 // with less precision (such as TickCount) just call through to 54 // with less precision (such as TickCount) just call through to
54 // mach_absolute_time. 55 // mach_absolute_time.
55 56
56 // timebase_info converts absolute time tick units into nanoseconds. Convert 57 // timebase_info converts absolute time tick units into nanoseconds. Convert
57 // to microseconds up front to stave off overflows. 58 // to microseconds up front to stave off overflows.
58 absolute_micro = 59 absolute_micro =
59 mach_absolute_time() / base::Time::kNanosecondsPerMicrosecond * 60 mach_absolute_time() / base::Time::kNanosecondsPerMicrosecond *
(...skipping 18 matching lines...) Expand all
78 if (thread == MACH_PORT_NULL) { 79 if (thread == MACH_PORT_NULL) {
79 DLOG(ERROR) << "Failed to get mach_thread_self()"; 80 DLOG(ERROR) << "Failed to get mach_thread_self()";
80 return 0; 81 return 0;
81 } 82 }
82 83
83 kern_return_t kr = thread_info( 84 kern_return_t kr = thread_info(
84 thread, 85 thread,
85 THREAD_BASIC_INFO, 86 THREAD_BASIC_INFO,
86 reinterpret_cast<thread_info_t>(&thread_info_data), 87 reinterpret_cast<thread_info_t>(&thread_info_data),
87 &thread_info_count); 88 &thread_info_count);
88 DCHECK_EQ(KERN_SUCCESS, kr); 89 MACH_DCHECK(kr == KERN_SUCCESS, kr) << "thread_info";
89 90
90 return (thread_info_data.user_time.seconds * 91 return (thread_info_data.user_time.seconds *
91 base::Time::kMicrosecondsPerSecond) + 92 base::Time::kMicrosecondsPerSecond) +
92 thread_info_data.user_time.microseconds; 93 thread_info_data.user_time.microseconds;
93 #endif // defined(OS_IOS) 94 #endif // defined(OS_IOS)
94 } 95 }
95 96
96 } // namespace 97 } // namespace
97 98
98 namespace base { 99 namespace base {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 TimeTicks TimeTicks::ThreadNow() { 232 TimeTicks TimeTicks::ThreadNow() {
232 return TimeTicks(ComputeThreadTicks()); 233 return TimeTicks(ComputeThreadTicks());
233 } 234 }
234 235
235 // static 236 // static
236 TimeTicks TimeTicks::NowFromSystemTraceTime() { 237 TimeTicks TimeTicks::NowFromSystemTraceTime() {
237 return HighResNow(); 238 return HighResNow();
238 } 239 }
239 240
240 } // namespace base 241 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_mac.mm ('k') | chrome/browser/mac/install_from_dmg.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698