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 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 Duration()15Duration::Duration() : ms_(0) {} Duration(int32_t duration)16Duration::Duration(int32_t duration) : ms_(duration) {} 17 operator +=(const Duration & other)18Duration& Duration::operator+=(const Duration& other) { 19 ms_ += other.ms_; 20 return *this; 21 } 22 operator +(const Duration & other) const23Duration Duration::operator+(const Duration& other) const { 24 return Duration(ms_ + other.ms_); 25 } 26 operator ==(const Duration & other) const27bool Duration::operator==(const Duration& other) const { 28 return ms_ == other.ms_; 29 } 30 operator !=(const Duration & other) const31bool Duration::operator!=(const Duration& other) const { 32 return ms_ != other.ms_; 33 } 34 operator >(const Duration & other) const35bool Duration::operator>(const Duration& other) const { 36 return ms_ > other.ms_; 37 } 38 39 // static FromMilliseconds(int ms)40Duration Duration::FromMilliseconds(int ms) { return Duration(ms); } 41 InMilliseconds() const42int32_t Duration::InMilliseconds() const { 43 return ms_; 44 } 45 46 //------------------------------------------------------------------------------ 47 TrackedTime()48TrackedTime::TrackedTime() : ms_(0) {} TrackedTime(int32_t ms)49TrackedTime::TrackedTime(int32_t ms) : ms_(ms) {} TrackedTime(const base::TimeTicks & time)50TrackedTime::TrackedTime(const base::TimeTicks& time) 51 : ms_(static_cast<int32_t>((time - base::TimeTicks()).InMilliseconds())) {} 52 53 // static Now()54TrackedTime TrackedTime::Now() { 55 return TrackedTime(base::TimeTicks::Now()); 56 } 57 operator -(const TrackedTime & other) const58Duration TrackedTime::operator-(const TrackedTime& other) const { 59 return Duration(ms_ - other.ms_); 60 } 61 operator +(const Duration & other) const62TrackedTime TrackedTime::operator+(const Duration& other) const { 63 return TrackedTime(ms_ + other.ms_); 64 } 65 is_null() const66bool TrackedTime::is_null() const { return ms_ == 0; } 67 68 } // namespace tracked_objects 69