Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
| 9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 | 12 |
| 13 namespace tracked_objects { | 13 namespace tracked_objects { |
| 14 | 14 |
| 15 typedef int DurationInt; | |
| 16 | |
| 17 //------------------------------------------------------------------------------ | 15 //------------------------------------------------------------------------------ |
| 18 | 16 |
| 19 #define USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS | |
|
Ilya Sherman
2012/03/21 21:47:49
I should mention: I'm not sure if this #define is
jar (doing other things)
2012/03/23 05:28:58
I don't see us going back... so this is fine to ki
| |
| 20 | |
| 21 #if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS) | |
| 22 | |
| 23 // 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 |
| 24 // 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 |
| 25 // 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 |
| 26 // 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 |
| 27 // 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). |
| 28 // 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, |
| 29 // 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 |
| 30 // 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). |
| 31 | 25 |
| 32 class BASE_EXPORT Duration { // Similar to base::TimeDelta. | 26 class BASE_EXPORT Duration { // Similar to base::TimeDelta. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); } | 59 static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); } |
| 66 | 60 |
| 67 private: | 61 private: |
| 68 friend class Duration; | 62 friend class Duration; |
| 69 explicit TrackedTime(int32 ms); | 63 explicit TrackedTime(int32 ms); |
| 70 | 64 |
| 71 // Internal duration is stored directly in milliseconds. | 65 // Internal duration is stored directly in milliseconds. |
| 72 uint32 ms_; | 66 uint32 ms_; |
| 73 }; | 67 }; |
| 74 | 68 |
| 75 #else | |
| 76 | |
| 77 // Just use full 64 bit time calculations, and the slower TimeTicks::Now(). | |
| 78 // This allows us (as an alternative) to test with larger ranges of times, and | |
| 79 // with a more thoroughly tested class. | |
| 80 | |
| 81 typedef base::TimeTicks TrackedTime; | |
| 82 typedef base::TimeDelta Duration; | |
| 83 | |
| 84 #endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS | |
| 85 | |
| 86 } // namespace tracked_objects | 69 } // namespace tracked_objects |
| 87 | 70 |
| 88 #endif // BASE_PROFILER_TRACKED_TIME_H_ | 71 #endif // BASE_PROFILER_TRACKED_TIME_H_ |
| OLD | NEW |