author | Honza Bambas <honzab.moz@firemni.cz> |
Mon, 11 Feb 2013 22:56:59 +0100 | |
changeset 121547 | 55ef31ba2298197993d75f2502bbaa430d9c334b |
parent 121546 | 604e819f63d7effd1f8e0cd4ca7c0b6c34d6113e |
child 121548 | cc3b4a2c1968a77daf04690167d8670d058be7a4 |
push id | 24296 |
push user | emorley@mozilla.com |
push date | Tue, 12 Feb 2013 14:43:19 +0000 |
treeherder | mozilla-central@860d7a47b675 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan, roc |
bugs | 827287 |
milestone | 21.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/xpcom/ds/TimeStamp.h +++ b/xpcom/ds/TimeStamp.h @@ -206,18 +206,27 @@ public: /** * Return true if this is the "null" moment */ bool IsNull() const { return mValue == 0; } /** * Return a timestamp reflecting the current elapsed system time. This * is monotonically increasing (i.e., does not decrease) over the * lifetime of this process' XPCOM session. + * + * Now() is trying to ensure the best possible precision on each platform, + * at least one millisecond. + * + * NowLoRes() has been introduced to workaround performance problems of + * QueryPerformanceCounter on the Windows platform. NowLoRes() is giving + * lower precision, usually 15.6 ms, but with very good performance benefit. + * Use it for measurements of longer times, like >200ms timeouts. */ - static TimeStamp Now(); + static TimeStamp Now() { return Now(true); } + static TimeStamp NowLoRes() { return Now(false); } /** * Compute the difference between two timestamps. Both must be non-null. */ TimeDuration operator-(const TimeStamp& aOther) const { MOZ_ASSERT(!IsNull(), "Cannot compute with a null value"); MOZ_ASSERT(!aOther.IsNull(), "Cannot compute with aOther null value"); PR_STATIC_ASSERT(-INT64_MAX > INT64_MIN); int64_t ticks = int64_t(mValue - aOther.mValue); @@ -293,16 +302,18 @@ public: static NS_HIDDEN_(nsresult) Startup(); static NS_HIDDEN_(void) Shutdown(); private: friend struct IPC::ParamTraits<mozilla::TimeStamp>; TimeStamp(TimeStampValue aValue) : mValue(aValue) {} + static TimeStamp Now(bool aHighResolution); + /** * When built with PRIntervalTime, a value of 0 means this instance * is "null". Otherwise, the low 32 bits represent a PRIntervalTime, * and the high 32 bits represent a counter of the number of * rollovers of PRIntervalTime that we've seen. This counter starts * at 1 to avoid a real time colliding with the "null" value. * * PR_INTERVAL_MAX is set at 100,000 ticks per second. So the minimum
--- a/xpcom/ds/TimeStamp_darwin.cpp +++ b/xpcom/ds/TimeStamp_darwin.cpp @@ -151,14 +151,14 @@ TimeStamp::Startup() } void TimeStamp::Shutdown() { } TimeStamp -TimeStamp::Now() +TimeStamp::Now(bool aHighResolution) { return TimeStamp(ClockTime()); } }
--- a/xpcom/ds/TimeStamp_posix.cpp +++ b/xpcom/ds/TimeStamp_posix.cpp @@ -163,14 +163,14 @@ TimeStamp::Startup() } void TimeStamp::Shutdown() { } TimeStamp -TimeStamp::Now() +TimeStamp::Now(bool aHighResolution) { return TimeStamp(ClockTimeNs()); } }
--- a/xpcom/ds/TimeStamp_windows.cpp +++ b/xpcom/ds/TimeStamp_windows.cpp @@ -532,20 +532,20 @@ TimeStamp::Startup() void TimeStamp::Shutdown() { DeleteCriticalSection(&sTimeStampLock); } TimeStamp -TimeStamp::Now() +TimeStamp::Now(bool aHighResolution) { // sUseQPC is volatile - bool useQPC = sUseQPC; + bool useQPC = (aHighResolution && sUseQPC); // Both values are in [mt] units. ULONGLONG QPC = useQPC ? PerformanceCounter() : uint64_t(0); ULONGLONG GTC = ms2mt(sGetTickCount64()); return TimeStamp(TimeStampValue(GTC, QPC, useQPC)); } } // namespace mozilla