Bug 827287 - make it possible to use TimeStamp without performance concerns (TimeStamp::NowLoRes), r=ehsan, sr=roc

This commit is contained in:
Honza Bambas 2013-02-11 22:56:59 +01:00
parent a3e10fe7fa
commit 3e6e5d6690
4 changed files with 16 additions and 5 deletions

View File

@ -211,8 +211,17 @@ public:
* 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.
*/
@ -298,6 +307,8 @@ private:
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,

View File

@ -156,7 +156,7 @@ TimeStamp::Shutdown()
}
TimeStamp
TimeStamp::Now()
TimeStamp::Now(bool aHighResolution)
{
return TimeStamp(ClockTime());
}

View File

@ -168,7 +168,7 @@ TimeStamp::Shutdown()
}
TimeStamp
TimeStamp::Now()
TimeStamp::Now(bool aHighResolution)
{
return TimeStamp(ClockTimeNs());
}

View File

@ -537,10 +537,10 @@ TimeStamp::Shutdown()
}
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);