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 // Time represents an absolute point in coordinated universal time (UTC), | 5 // Time represents an absolute point in coordinated universal time (UTC), |
6 // internally represented as microseconds (s/1,000,000) since the Windows epoch | 6 // internally represented as microseconds (s/1,000,000) since the Windows epoch |
7 // (1601-01-01 00:00:00 UTC) (See http://crbug.com/14734). System-dependent | 7 // (1601-01-01 00:00:00 UTC) (See http://crbug.com/14734). System-dependent |
8 // clock interface routines are defined in time_PLATFORM.cc. | 8 // clock interface routines are defined in time_PLATFORM.cc. |
9 // | 9 // |
10 // TimeDelta represents a duration of time, internally represented in | 10 // TimeDelta represents a duration of time, internally represented in |
11 // microseconds. | 11 // microseconds. |
12 // | 12 // |
13 // TimeTicks represents an abstract time that is most of the time incrementing | 13 // TimeTicks represents an abstract time that is most of the time incrementing |
14 // for use in measuring time durations. It is internally represented in | 14 // for use in measuring time durations. It is internally represented in |
15 // microseconds. It can not be converted to a human-readable time, but is | 15 // microseconds. It can not be converted to a human-readable time, but is |
16 // guaranteed not to decrease (if the user changes the computer clock, | 16 // guaranteed not to decrease (if the user changes the computer clock, |
17 // Time::Now() may actually decrease or jump). But note that TimeTicks may | 17 // Time::Now() may actually decrease or jump). But note that TimeTicks may |
18 // "stand still", for example if the computer suspended. | 18 // "stand still", for example if the computer suspended. |
19 // | 19 // |
20 // These classes are represented as only a 64-bit value, so they can be | 20 // These classes are represented as only a 64-bit value, so they can be |
21 // efficiently passed by value. | 21 // efficiently passed by value. |
| 22 // |
| 23 // Definitions of operator<< are provided to make these types work with |
| 24 // DCHECK_EQ() and other log macros. For human-readable formatting, see |
| 25 // "base/i18n/time_formatting.h". |
22 | 26 |
23 #ifndef BASE_TIME_TIME_H_ | 27 #ifndef BASE_TIME_TIME_H_ |
24 #define BASE_TIME_TIME_H_ | 28 #define BASE_TIME_TIME_H_ |
25 | 29 |
26 #include <time.h> | 30 #include <time.h> |
27 | 31 |
| 32 #include <iosfwd> |
| 33 |
28 #include "base/base_export.h" | 34 #include "base/base_export.h" |
29 #include "base/basictypes.h" | 35 #include "base/basictypes.h" |
30 #include "build/build_config.h" | 36 #include "build/build_config.h" |
31 | 37 |
32 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
33 #include <CoreFoundation/CoreFoundation.h> | 39 #include <CoreFoundation/CoreFoundation.h> |
34 // Avoid Mac system header macro leak. | 40 // Avoid Mac system header macro leak. |
35 #undef TYPE_BOOL | 41 #undef TYPE_BOOL |
36 #endif | 42 #endif |
37 | 43 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 205 } |
200 | 206 |
201 // Delta in microseconds. | 207 // Delta in microseconds. |
202 int64 delta_; | 208 int64 delta_; |
203 }; | 209 }; |
204 | 210 |
205 inline TimeDelta operator*(int64 a, TimeDelta td) { | 211 inline TimeDelta operator*(int64 a, TimeDelta td) { |
206 return TimeDelta(a * td.delta_); | 212 return TimeDelta(a * td.delta_); |
207 } | 213 } |
208 | 214 |
| 215 // For logging use only. |
| 216 BASE_EXPORT std::ostream& operator<<(std::ostream& os, TimeDelta time_delta); |
| 217 |
209 // Time ----------------------------------------------------------------------- | 218 // Time ----------------------------------------------------------------------- |
210 | 219 |
211 // Represents a wall clock time in UTC. | 220 // Represents a wall clock time in UTC. |
212 class BASE_EXPORT Time { | 221 class BASE_EXPORT Time { |
213 public: | 222 public: |
214 static const int64 kMillisecondsPerSecond = 1000; | 223 static const int64 kMillisecondsPerSecond = 1000; |
215 static const int64 kMicrosecondsPerMillisecond = 1000; | 224 static const int64 kMicrosecondsPerMillisecond = 1000; |
216 static const int64 kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * | 225 static const int64 kMicrosecondsPerSecond = kMicrosecondsPerMillisecond * |
217 kMillisecondsPerSecond; | 226 kMillisecondsPerSecond; |
218 static const int64 kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; | 227 static const int64 kMicrosecondsPerMinute = kMicrosecondsPerSecond * 60; |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 // Preserve max to prevent overflow. | 563 // Preserve max to prevent overflow. |
555 if (us == std::numeric_limits<int64>::max()) | 564 if (us == std::numeric_limits<int64>::max()) |
556 return Max(); | 565 return Max(); |
557 return TimeDelta(us); | 566 return TimeDelta(us); |
558 } | 567 } |
559 | 568 |
560 inline Time TimeDelta::operator+(Time t) const { | 569 inline Time TimeDelta::operator+(Time t) const { |
561 return Time(t.us_ + delta_); | 570 return Time(t.us_ + delta_); |
562 } | 571 } |
563 | 572 |
| 573 // For logging use only. |
| 574 BASE_EXPORT std::ostream& operator<<(std::ostream& os, Time time); |
| 575 |
564 // TimeTicks ------------------------------------------------------------------ | 576 // TimeTicks ------------------------------------------------------------------ |
565 | 577 |
566 class BASE_EXPORT TimeTicks { | 578 class BASE_EXPORT TimeTicks { |
567 public: | 579 public: |
568 // We define this even without OS_CHROMEOS for seccomp sandbox testing. | 580 // We define this even without OS_CHROMEOS for seccomp sandbox testing. |
569 #if defined(OS_LINUX) | 581 #if defined(OS_LINUX) |
570 // Force definition of the system trace clock; it is a chromeos-only api | 582 // Force definition of the system trace clock; it is a chromeos-only api |
571 // at the moment and surfacing it in the right place requires mucking | 583 // at the moment and surfacing it in the right place requires mucking |
572 // with glibc et al. | 584 // with glibc et al. |
573 static const clockid_t kClockSystemTrace = 11; | 585 static const clockid_t kClockSystemTrace = 11; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 #if defined(OS_WIN) | 728 #if defined(OS_WIN) |
717 typedef DWORD (*TickFunctionType)(void); | 729 typedef DWORD (*TickFunctionType)(void); |
718 static TickFunctionType SetMockTickFunction(TickFunctionType ticker); | 730 static TickFunctionType SetMockTickFunction(TickFunctionType ticker); |
719 #endif | 731 #endif |
720 }; | 732 }; |
721 | 733 |
722 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { | 734 inline TimeTicks TimeDelta::operator+(TimeTicks t) const { |
723 return TimeTicks(t.ticks_ + delta_); | 735 return TimeTicks(t.ticks_ + delta_); |
724 } | 736 } |
725 | 737 |
| 738 // For logging use only. |
| 739 BASE_EXPORT std::ostream& operator<<(std::ostream& os, TimeTicks time_ticks); |
| 740 |
726 } // namespace base | 741 } // namespace base |
727 | 742 |
728 #endif // BASE_TIME_TIME_H_ | 743 #endif // BASE_TIME_TIME_H_ |
OLD | NEW |