michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_PROFILER_TRACKED_TIME_H_ michael@0: #define BASE_PROFILER_TRACKED_TIME_H_ michael@0: michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/basictypes.h" michael@0: #include "base/time/time.h" michael@0: michael@0: namespace tracked_objects { michael@0: michael@0: //------------------------------------------------------------------------------ michael@0: michael@0: // TimeTicks maintains a wasteful 64 bits of data (we need less than 32), and on michael@0: // windows, a 64 bit timer is expensive to even obtain. We use a simple michael@0: // millisecond counter for most of our time values, as well as millisecond units michael@0: // of duration between those values. This means we can only handle durations michael@0: // up to 49 days (range), or 24 days (non-negative time durations). michael@0: // We only define enough methods to service the needs of the tracking classes, michael@0: // and our interfaces are modeled after what TimeTicks and TimeDelta use (so we michael@0: // can swap them into place if we want to use the "real" classes). michael@0: michael@0: class BASE_EXPORT Duration { // Similar to base::TimeDelta. michael@0: public: michael@0: Duration(); michael@0: michael@0: Duration& operator+=(const Duration& other); michael@0: Duration operator+(const Duration& other) const; michael@0: michael@0: bool operator==(const Duration& other) const; michael@0: bool operator!=(const Duration& other) const; michael@0: bool operator>(const Duration& other) const; michael@0: michael@0: static Duration FromMilliseconds(int ms); michael@0: michael@0: int32 InMilliseconds() const; michael@0: michael@0: private: michael@0: friend class TrackedTime; michael@0: explicit Duration(int32 duration); michael@0: michael@0: // Internal time is stored directly in milliseconds. michael@0: int32 ms_; michael@0: }; michael@0: michael@0: class BASE_EXPORT TrackedTime { // Similar to base::TimeTicks. michael@0: public: michael@0: TrackedTime(); michael@0: explicit TrackedTime(const base::TimeTicks& time); michael@0: michael@0: static TrackedTime Now(); michael@0: Duration operator-(const TrackedTime& other) const; michael@0: TrackedTime operator+(const Duration& other) const; michael@0: bool is_null() const; michael@0: michael@0: static TrackedTime FromMilliseconds(int32 ms) { return TrackedTime(ms); } michael@0: michael@0: private: michael@0: friend class Duration; michael@0: explicit TrackedTime(int32 ms); michael@0: michael@0: // Internal duration is stored directly in milliseconds. michael@0: uint32 ms_; michael@0: }; michael@0: michael@0: } // namespace tracked_objects michael@0: michael@0: #endif // BASE_PROFILER_TRACKED_TIME_H_