Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1166)

Unified Diff: base/time/time.h

Issue 797893003: [Windows] One TimeTicks clock: efficient/reliable high-res, with low-res fallback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/time/time_mac.cc » ('j') | base/time/time_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.h
diff --git a/base/time/time.h b/base/time/time.h
index d61a351f18cc236ecaf22ff5dbe60274557c0b96..fa4d3b3f5884cb8935f113dc1e521f46563967b6 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -29,6 +29,7 @@
#include <time.h>
+#include <cstdlib>
#include <iosfwd>
#include "base/base_export.h"
@@ -100,6 +101,16 @@ class BASE_EXPORT TimeDelta {
return delta_;
}
+ // Returns true if this TimeDelta is negative.
+ bool is_negative() const {
brianderson 2015/01/07 00:53:43 This is not used and appears unrelated. If the int
miu 2015/01/07 05:22:45 Ah. Yes, it was used in an earlier iteration of t
+ return delta_ < 0;
+ }
+
+ // Returns the magnitude (absolute value) of this TimeDelta.
+ TimeDelta magnitude() const {
brianderson 2015/01/07 00:53:43 This is only used for testing. Do you plan to use
miu 2015/01/07 05:22:45 Yes. I've personally written a lot of code in src
+ return TimeDelta(std::abs(delta_));
+ }
+
// Returns true if the time delta is the maximum time delta.
bool is_max() const {
return delta_ == std::numeric_limits<int64>::max();
@@ -588,18 +599,26 @@ class BASE_EXPORT TimeTicks {
TimeTicks() : ticks_(0) {
}
- // Platform-dependent tick count representing "right now."
- // The resolution of this clock is ~1-15ms. Resolution varies depending
- // on hardware/operating system configuration.
+ // Platform-dependent tick count representing "right now." When
+ // IsHighResolution() returns false, the resolution of the clock could be
+ // as coarse as ~15.6ms. Otherwise, the resolution should be no worse than one
+ // microsecond.
static TimeTicks Now();
- // Returns a platform-dependent high-resolution tick count. Implementation
- // is hardware dependent and may or may not return sub-millisecond
- // resolution. THIS CALL IS GENERALLY MUCH MORE EXPENSIVE THAN Now() AND
- // SHOULD ONLY BE USED WHEN IT IS REALLY NEEDED.
- static TimeTicks HighResNow();
+ // DEPRECATED
+ // TODO(miu): Remove this function, and all callpoints should call Now().
+ static TimeTicks HighResNow() { return TimeTicks::Now(); }
+
+ // Returns true if the high resolution clock is working on this system and
+ // Now() will return high resolution values. Note that, on systems where the
+ // high resolution clock works but is deemed inefficient, the low resolution
+ // clock will be used instead.
+ static bool IsHighResolution();
- static bool IsHighResNowFastAndReliable();
+ // DEPRECATED
+ // TODO(miu): Remove this function, and all callpoints should call
+ // IsHighResolution().
+ static bool IsHighResNowFastAndReliable() { return IsHighResolution(); }
// Returns true if ThreadNow() is supported on this system.
static bool IsThreadNowSupported() {
@@ -616,24 +635,33 @@ class BASE_EXPORT TimeTicks {
// to (approximately) measure how much time the calling thread spent doing
// actual work vs. being de-scheduled. May return bogus results if the thread
// migrates to another CPU between two calls.
+ //
+ // WARNING: The returned value might NOT have the same origin as Now(). Do not
+ // perform math with TimeTicks values returned by Now() and expect meaningful
+ // results.
+ // TODO(miu): Since the timeline of these values is different, the values
+ // should be of a different type.
static TimeTicks ThreadNow();
- // Returns the current system trace time or, if none is defined, the current
- // high-res time (i.e. HighResNow()). On systems where a global trace clock
- // is defined, timestamping TraceEvents's with this value guarantees
- // synchronization between events collected inside chrome and events
- // collected outside (e.g. kernel, X server).
+ // Returns the current system trace time or, if not available on this
+ // platform, a high-resolution time value; or a low-resolution time value if
+ // neither are avalable. On systems where a global trace clock is defined,
+ // timestamping TraceEvents's with this value guarantees synchronization
+ // between events collected inside chrome and events collected outside
+ // (e.g. kernel, X server).
+ //
+ // WARNING: The returned value might NOT have the same origin as Now(). Do not
+ // perform math with TimeTicks values returned by Now() and expect meaningful
+ // results.
+ // TODO(miu): Since the timeline of these values is different, the values
+ // should be of a different type.
static TimeTicks NowFromSystemTraceTime();
#if defined(OS_WIN)
- // Get the absolute value of QPC time drift. For testing.
- static int64 GetQPCDriftMicroseconds();
-
+ // Translates an absolute QPC timestamp into a TimeTicks value. The returned
+ // value has the same origin as Now(). Do NOT attempt to use this if
+ // IsHighResolution() returns false.
static TimeTicks FromQPCValue(LONGLONG qpc_value);
-
- // Returns true if the high resolution clock is working on this system.
- // This is only for testing.
- static bool IsHighResClockWorking();
#endif
// Returns true if this object has not been initialized.
« no previous file with comments | « no previous file | base/time/time_mac.cc » ('j') | base/time/time_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698