OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/profiler/tracked_time.h" |
| 6 |
| 7 #include "build/build_config.h" |
| 8 |
| 9 #if defined(OS_WIN) |
| 10 #include <mmsystem.h> // Declare timeGetTime()... after including build_config. |
| 11 #endif |
| 12 |
| 13 namespace tracked_objects { |
| 14 |
| 15 #if defined(USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS) |
| 16 |
| 17 Duration::Duration() : ms_(0) {} |
| 18 Duration::Duration(int32 duration) : ms_(duration) {} |
| 19 |
| 20 Duration& Duration::operator+=(const Duration& other) { |
| 21 ms_ += other.ms_; |
| 22 return *this; |
| 23 } |
| 24 |
| 25 Duration Duration::operator+(const Duration& other) const { |
| 26 return Duration(ms_ + other.ms_); |
| 27 } |
| 28 |
| 29 bool Duration::operator==(const Duration& other) const { |
| 30 return ms_ == other.ms_; |
| 31 } |
| 32 |
| 33 bool Duration::operator!=(const Duration& other) const { |
| 34 return ms_ != other.ms_; |
| 35 } |
| 36 |
| 37 bool Duration::operator>(const Duration& other) const { |
| 38 return ms_ > other.ms_; |
| 39 } |
| 40 |
| 41 // static |
| 42 Duration Duration::FromMilliseconds(int ms) { return Duration(ms); } |
| 43 |
| 44 int32 Duration::InMilliseconds() const { return ms_; } |
| 45 |
| 46 //------------------------------------------------------------------------------ |
| 47 |
| 48 TrackedTime::TrackedTime() : ms_(0) {} |
| 49 TrackedTime::TrackedTime(int32 ms) : ms_(ms) {} |
| 50 TrackedTime::TrackedTime(const base::TimeTicks& time) |
| 51 : ms_((time - base::TimeTicks()).InMilliseconds()) { |
| 52 } |
| 53 |
| 54 // static |
| 55 TrackedTime TrackedTime::Now() { |
| 56 #if defined(OS_WIN) |
| 57 // Use lock-free accessor to 32 bit time. |
| 58 // Note that TimeTicks::Now() is built on this, so we have "compatible" |
| 59 // times when we down-convert a TimeTicks sample. |
| 60 // TODO(jar): Surface this interface via something in base/time.h. |
| 61 return TrackedTime(static_cast<int32>(timeGetTime())); |
| 62 #else |
| 63 // Posix has nice cheap 64 bit times, so we just down-convert it. |
| 64 return TrackedTime(base::TimeTicks::Now()); |
| 65 #endif // OS_WIN |
| 66 } |
| 67 |
| 68 Duration TrackedTime::operator-(const TrackedTime& other) const { |
| 69 return Duration(ms_ - other.ms_); |
| 70 } |
| 71 |
| 72 TrackedTime TrackedTime::operator+(const Duration& other) const { |
| 73 return TrackedTime(ms_ + other.ms_); |
| 74 } |
| 75 |
| 76 bool TrackedTime::is_null() const { return ms_ == 0; } |
| 77 |
| 78 #endif // USE_FAST_TIME_CLASS_FOR_DURATION_CALCULATIONS |
| 79 |
| 80 } // namespace tracked_objects |
OLD | NEW |