mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 14:25:49 +00:00
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:
parent
32c8731610
commit
c59e733060
@ -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
|
||||
|
@ -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>
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user