Bug 1685503 - Use AwakeTimeStamp to count time for media telemetry. r=alwu

Differential Revision: https://phabricator.services.mozilla.com/D112797
This commit is contained in:
Paul Adenot 2021-05-05 09:24:51 +00:00
parent 32c8731610
commit c59e733060
3 changed files with 30 additions and 28 deletions

View File

@ -7,7 +7,7 @@
#include "MediaInfo.h"
#include "mozilla/Maybe.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/AwakeTimeStamp.h"
#include "nsISupportsImpl.h"
namespace mozilla {
@ -67,22 +67,22 @@ class TelemetryProbesReporter final {
if (IsStarted()) {
return;
}
mStartTime = TimeStamp::Now();
mStartTime = Some(AwakeTimeStamp::NowLoRes());
}
void Pause() {
if (!IsStarted()) {
return;
}
mSum = (TimeStamp::Now() - mStartTime);
mStartTime = TimeStamp();
mSum = (AwakeTimeStamp::NowLoRes() - mStartTime.value());
mStartTime = Nothing();
}
bool IsStarted() const { return !mStartTime.IsNull(); }
bool IsStarted() const { return mStartTime.isSome(); }
double GetAndClearTotal() {
MOZ_ASSERT(!IsStarted(), "only call this when accumulator is paused");
double total = mSum.ToSeconds();
mStartTime = TimeStamp();
mSum = TimeDuration();
mStartTime = Nothing();
mSum = AwakeTimeDuration();
return total;
}
@ -90,12 +90,12 @@ class TelemetryProbesReporter final {
if (!IsStarted()) {
return mSum.ToSeconds();
}
return (TimeStamp::Now() - mStartTime).ToSeconds();
return (AwakeTimeStamp::NowLoRes() - mStartTime.value()).ToSeconds();
}
private:
TimeStamp mStartTime;
TimeDuration mSum;
Maybe<AwakeTimeStamp> mStartTime;
AwakeTimeDuration mSum;
};
// The owner is HTMLMediaElement that is guaranteed being always alive during

View File

@ -33,6 +33,25 @@ double AwakeTimeDuration::ToMicroseconds() const {
return static_cast<double>(mValueUs);
}
AwakeTimeDuration AwakeTimeStamp::operator-(
AwakeTimeStamp const& aOther) const {
return AwakeTimeDuration(mValueUs - aOther.mValueUs);
}
AwakeTimeStamp AwakeTimeStamp::operator+(
const AwakeTimeDuration& aDuration) const {
return AwakeTimeStamp(mValueUs + aDuration.mValueUs);
}
void AwakeTimeStamp::operator+=(const AwakeTimeDuration& aOther) {
mValueUs += aOther.mValueUs;
}
void AwakeTimeStamp::operator-=(const AwakeTimeDuration& aOther) {
MOZ_ASSERT(mValueUs >= aOther.mValueUs);
mValueUs -= aOther.mValueUs;
}
// Apple things
#if defined(__APPLE__) && defined(__MACH__)
# include <time.h>

View File

@ -114,23 +114,6 @@ class AwakeTimeDuration {
uint64_t mValueUs;
};
MFBT_API AwakeTimeDuration
AwakeTimeStamp::operator-(AwakeTimeStamp const& aOther) const {
return AwakeTimeDuration(mValueUs - aOther.mValueUs);
}
MFBT_API AwakeTimeStamp
AwakeTimeStamp::operator+(const AwakeTimeDuration& aDuration) const {
return AwakeTimeStamp(mValueUs + aDuration.mValueUs);
}
MFBT_API void AwakeTimeStamp::operator+=(const AwakeTimeDuration& aOther) {
mValueUs += aOther.mValueUs;
}
MFBT_API void AwakeTimeStamp::operator-=(const AwakeTimeDuration& aOther) {
MOZ_ASSERT(mValueUs >= aOther.mValueUs);
mValueUs -= aOther.mValueUs;
}
} // namespace mozilla
}; // namespace mozilla
#endif // mozilla_AwakeTimeStamp_h