Bug 1432429 Refactor Timestamp to have a NowInternal function 14/14
MozReview-Commit-ID: C8SjaMTnCW1
--- a/mozglue/misc/TimeStamp.h
+++ b/mozglue/misc/TimeStamp.h
@@ -471,18 +471,18 @@ public:
* 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() { return Now(true); }
static TimeStamp NowLoRes() { return Now(false); }
static TimeStamp NowReally() { return NowReally(true); }
+ static MFBT_API TimeStamp NowFuzzy(TimeStampValue aValue);
- static MFBT_API TimeStamp NowFuzzy(TimeStampValue aValue);
static MFBT_API void UpdateFuzzyTimeStamp(TimeStamp aValue);
/**
* Return a timestamp representing the time when the current process was
* created which will be comparable with other timestamps taken with this
* class. If the actual process creation time is detected to be inconsistent
* the @a aIsInconsistent parameter will be set to true, the returned
* timestamp however will still be valid though inaccurate.
@@ -612,16 +612,18 @@ private:
, mUsedCanonicalNow(false)
{}
MOZ_IMPLICIT TimeStamp(TimeStampValue aValue, bool aUsedCanonicalNow)
: mValue(aValue)
, mUsedCanonicalNow(aUsedCanonicalNow)
{}
+ static MFBT_API TimeStampValue NowInternal(bool aHighResolution);
+
static MFBT_API TimeStamp Now(bool aHighResolution);
static MFBT_API TimeStamp NowReally(bool aHighResolution);
/**
* Computes the uptime of the current process in microseconds. The result
* is platform-dependent and needs to be checked against existing timestamps
* for consistency.
*
--- a/mozglue/misc/TimeStamp_darwin.cpp
+++ b/mozglue/misc/TimeStamp_darwin.cpp
@@ -19,16 +19,17 @@
#include <mach/mach_time.h>
#include <sys/time.h>
#include <sys/sysctl.h>
#include <time.h>
#include <unistd.h>
#include "mozilla/TimeStamp.h"
+
// Estimate of the smallest duration of time we can measure.
static uint64_t sResolution;
static uint64_t sResolutionSigDigs;
static const uint64_t kNsPerMs = 1000000;
static const uint64_t kUsPerSec = 1000000;
static const double kNsPerMsd = 1000000.0;
static const double kNsPerSecd = 1000000000.0;
@@ -151,31 +152,36 @@ TimeStamp::Startup()
return;
}
void
TimeStamp::Shutdown()
{
}
+TimeStampValue
+TimeStamp::NowInternal(bool aHighResolution)
+{
+ return ClockTime();
+}
+
TimeStamp
TimeStamp::Now(bool aHighResolution)
{
- return TimeStamp::NowFuzzy(ClockTime());
+ return TimeStamp::NowFuzzy(TimeStamp::NowInternal(aHighResolution));
}
TimeStamp
TimeStamp::NowReally(bool aHighResolution)
{
- return TimeStamp(ClockTime());
+ return TimeStamp(TimeStamp::NowInternal(aHighResolution));
}
// Computes and returns the process uptime in microseconds.
// Returns 0 if an error was encountered.
-
uint64_t
TimeStamp::ComputeProcessUptime()
{
struct timeval tv;
int rv = gettimeofday(&tv, nullptr);
if (rv == -1) {
return 0;
--- a/mozglue/misc/TimeStamp_posix.cpp
+++ b/mozglue/misc/TimeStamp_posix.cpp
@@ -194,26 +194,32 @@ TimeStamp::Startup()
gInitialized = true;
}
void
TimeStamp::Shutdown()
{
}
+TimeStampValue
+TimeStamp::NowInternal(bool aHighResolution)
+{
+ return ClockTimeNs();
+}
+
TimeStamp
TimeStamp::Now(bool aHighResolution)
{
- return TimeStamp::NowFuzzy(ClockTimeNs());
+ return TimeStamp::NowFuzzy(TimeStamp::NowInternal(aHighResolution));
}
TimeStamp
TimeStamp::NowReally(bool aHighResolution)
{
- return TimeStamp(ClockTimeNs());
+ return TimeStamp(TimeStamp::NowInternal(aHighResolution));
}
#if defined(XP_LINUX) || defined(ANDROID)
// Calculates the amount of jiffies that have elapsed since boot and up to the
// starttime value of a specific process as found in its /proc/*/stat file.
// Returns 0 if an error occurred.
--- a/mozglue/misc/TimeStamp_windows.cpp
+++ b/mozglue/misc/TimeStamp_windows.cpp
@@ -509,38 +509,40 @@ TimeStamp::Startup()
}
MFBT_API void
TimeStamp::Shutdown()
{
DeleteCriticalSection(&sTimeStampLock);
}
-MFBT_API TimeStamp
-TimeStamp::Now(bool aHighResolution)
+
+MFBT_API TimeStampValue
+TimeStamp::NowInternal(bool aHighResolution)
{
// sUseQPC is volatile
bool useQPC = (aHighResolution && sUseQPC);
// Both values are in [mt] units.
ULONGLONG QPC = useQPC ? PerformanceCounter() : uint64_t(0);
ULONGLONG GTC = ms2mt(GetTickCount64());
- return TimeStamp::NowFuzzy(TimeStampValue(GTC, QPC, useQPC));
+
+ return TimeStampValue(GTC, QPC, useQPC);
+}
+
+MFBT_API TimeStamp
+TimeStamp::Now(bool aHighResolution)
+{
+ return TimeStamp::NowFuzzy(TimeStamp::NowInternal(aHighResolution));
}
MFBT_API TimeStamp
TimeStamp::NowReally(bool aHighResolution)
{
- // sUseQPC is volatile
- bool useQPC = (aHighResolution && sUseQPC);
-
- // Both values are in [mt] units.
- ULONGLONG QPC = useQPC ? PerformanceCounter() : uint64_t(0);
- ULONGLONG GTC = ms2mt(GetTickCount64());
- return TimeStamp(TimeStampValue(GTC, QPC, useQPC));
+ return TimeStamp(TimeStamp::NowInternal(aHighResolution));
}
// Computes and returns the process uptime in microseconds.
// Returns 0 if an error was encountered.
MFBT_API uint64_t
TimeStamp::ComputeProcessUptime()
{