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 #ifndef BASE_PROFILER_TRACKED_TIME_H_ | 5 #ifndef BASE_PROFILER_TRACKED_TIME_H_ |
6 #define BASE_PROFILER_TRACKED_TIME_H_ | 6 #define BASE_PROFILER_TRACKED_TIME_H_ |
7 | 7 |
| 8 #include <stdint.h> |
8 | 9 |
9 #include "base/base_export.h" | 10 #include "base/base_export.h" |
10 #include "base/basictypes.h" | |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 | 12 |
13 namespace tracked_objects { | 13 namespace tracked_objects { |
14 | 14 |
15 //------------------------------------------------------------------------------ | 15 //------------------------------------------------------------------------------ |
16 | 16 |
17 // TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on | 17 // TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on |
18 // windows, a 64 bit timer is expensive to even obtain. We use a simple | 18 // windows, a 64 bit timer is expensive to even obtain. We use a simple |
19 // millisecond counter for most of our time values, as well as millisecond units | 19 // millisecond counter for most of our time values, as well as millisecond units |
20 // of duration between those values. This means we can only handle durations | 20 // of duration between those values. This means we can only handle durations |
21 // up to 49 days (range), or 24 days (non-negative time durations). | 21 // up to 49 days (range), or 24 days (non-negative time durations). |
22 // We only define enough methods to service the needs of the tracking classes, | 22 // We only define enough methods to service the needs of the tracking classes, |
23 // and our interfaces are modeled after what TimeTicks and TimeDelta use (so we | 23 // and our interfaces are modeled after what TimeTicks and TimeDelta use (so we |
24 // can swap them into place if we want to use the "real" classes). | 24 // can swap them into place if we want to use the "real" classes). |
25 | 25 |
26 class BASE_EXPORT Duration { // Similar to base::TimeDelta. | 26 class BASE_EXPORT Duration { // Similar to base::TimeDelta. |
27 public: | 27 public: |
28 Duration(); | 28 Duration(); |
29 | 29 |
30 Duration& operator+=(const Duration& other); | 30 Duration& operator+=(const Duration& other); |
31 Duration operator+(const Duration& other) const; | 31 Duration operator+(const Duration& other) const; |
32 | 32 |
33 bool operator==(const Duration& other) const; | 33 bool operator==(const Duration& other) const; |
34 bool operator!=(const Duration& other) const; | 34 bool operator!=(const Duration& other) const; |
35 bool operator>(const Duration& other) const; | 35 bool operator>(const Duration& other) const; |
36 | 36 |
37 static Duration FromMilliseconds(int ms); | 37 static Duration FromMilliseconds(int ms); |
38 | 38 |
39 int32 InMilliseconds() const; | 39 int32_t InMilliseconds() const; |
40 | 40 |
41 private: | 41 private: |
42 friend class TrackedTime; | 42 friend class TrackedTime; |
43 explicit Duration(int32 duration); | 43 explicit Duration(int32_t duration); |
44 | 44 |
45 // Internal time is stored directly in milliseconds. | 45 // Internal time is stored directly in milliseconds. |
46 int32 ms_; | 46 int32_t ms_; |
47 }; | 47 }; |
48 | 48 |
49 class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks. | 49 class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks. |
50 public: | 50 public: |
51 TrackedTime(); | 51 TrackedTime(); |
52 explicit TrackedTime(const base::TimeTicks& time); | 52 explicit TrackedTime(const base::TimeTicks& time); |
53 | 53 |
54 static TrackedTime Now(); | 54 static TrackedTime Now(); |
55 Duration operator-(const TrackedTime& other) const; | 55 Duration operator-(const TrackedTime& other) const; |
56 TrackedTime operator+(const Duration& other) const; | 56 TrackedTime operator+(const Duration& other) const; |
57 bool is_null() const; | 57 bool is_null() const; |
58 | 58 |
59 static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); } | 59 static TrackedTime FromMilliseconds(int32_t ms) { return TrackedTime(ms); } |
60 | 60 |
61 private: | 61 private: |
62 friend class Duration; | 62 friend class Duration; |
63 explicit TrackedTime(int32 ms); | 63 explicit TrackedTime(int32_t ms); |
64 | 64 |
65 // Internal duration is stored directly in milliseconds. | 65 // Internal duration is stored directly in milliseconds. |
66 uint32 ms_; | 66 uint32_t ms_; |
67 }; | 67 }; |
68 | 68 |
69 } // namespace tracked_objects | 69 } // namespace tracked_objects |
70 | 70 |
71 #endif // BASE_PROFILER_TRACKED_TIME_H_ | 71 #endif // BASE_PROFILER_TRACKED_TIME_H_ |
OLD | NEW |