mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 1147555 - Implement logging for MediaTimer. r=mattwoodrow
This commit is contained in:
parent
9f31ecca48
commit
e42f8208f6
@ -10,19 +10,32 @@
|
||||
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "SharedThreadPool.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
PRLogModuleInfo* gMediaTimerLog;
|
||||
static void EnsureMediaTimerLog()
|
||||
{
|
||||
if (!gMediaTimerLog) {
|
||||
gMediaTimerLog = PR_NewLogModule("MediaTimer");
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(MediaTimer)
|
||||
NS_IMPL_RELEASE_WITH_DESTROY(MediaTimer, DispatchDestroy())
|
||||
|
||||
MediaTimer::MediaTimer()
|
||||
: mMonitor("MediaTimer Monitor")
|
||||
, mTimer(do_CreateInstance("@mozilla.org/timer;1"))
|
||||
, mCreationTimeStamp(TimeStamp::Now())
|
||||
, mUpdateScheduled(false)
|
||||
{
|
||||
EnsureMediaTimerLog();
|
||||
TIMER_LOG("MediaTimer::MediaTimer");
|
||||
|
||||
// Use the SharedThreadPool to create an nsIThreadPool with a maximum of one
|
||||
// thread, which is equivalent to an nsIThread for our purposes.
|
||||
RefPtr<SharedThreadPool> threadPool(
|
||||
@ -44,6 +57,7 @@ void
|
||||
MediaTimer::Destroy()
|
||||
{
|
||||
MOZ_ASSERT(OnMediaTimerThread());
|
||||
TIMER_LOG("MediaTimer::Destroy");
|
||||
|
||||
// Reject any outstanding entries. There's no need to acquire the monitor
|
||||
// here, because we're on the timer thread and all other references to us
|
||||
@ -71,6 +85,7 @@ nsRefPtr<MediaTimerPromise>
|
||||
MediaTimer::WaitUntil(const TimeStamp& aTimeStamp, const char* aCallSite)
|
||||
{
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
TIMER_LOG("MediaTimer::WaitUntil %lld", RelativeMicroseconds(aTimeStamp));
|
||||
Entry e(aTimeStamp, aCallSite);
|
||||
nsRefPtr<MediaTimerPromise> p = e.mPromise.get();
|
||||
mEntries.push(e);
|
||||
@ -107,6 +122,8 @@ MediaTimer::UpdateLocked()
|
||||
mMonitor.AssertCurrentThreadOwns();
|
||||
mUpdateScheduled = false;
|
||||
|
||||
TIMER_LOG("MediaTimer::UpdateLocked");
|
||||
|
||||
// Resolve all the promises whose time is up.
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
while (!mEntries.empty() && mEntries.top().mTimeStamp <= now) {
|
||||
@ -160,6 +177,7 @@ MediaTimer::ArmTimer(const TimeStamp& aTarget, const TimeStamp& aNow)
|
||||
// XPCOM timer resolution is in milliseconds. It's important to never resolve
|
||||
// a timer when mTarget might compare < now (even if very close), so round up.
|
||||
unsigned long delay = std::ceil((aTarget - aNow).ToMilliseconds());
|
||||
TIMER_LOG("MediaTimer::ArmTimer delay=%lu", delay);
|
||||
mCurrentTimerTarget = aTarget;
|
||||
nsresult rv = mTimer->InitWithFuncCallback(&TimerCallback, this, delay, nsITimer::TYPE_ONE_SHOT);
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
@ -19,6 +19,13 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
extern PRLogModuleInfo* gMediaTimerLog;
|
||||
|
||||
#define TIMER_LOG(x, ...) \
|
||||
MOZ_ASSERT(gMediaTimerLog); \
|
||||
PR_LOG(gMediaTimerLog, PR_LOG_DEBUG, ("[MediaTimer=%p relative_t=%lld]" x, this, \
|
||||
RelativeMicroseconds(TimeStamp::Now()), ##__VA_ARGS__))
|
||||
|
||||
// This promise type is only exclusive because so far there isn't a reason for
|
||||
// it not to be. Feel free to change that.
|
||||
typedef MediaPromise<bool, bool, /* IsExclusive = */ true> MediaTimerPromise;
|
||||
@ -62,6 +69,7 @@ private:
|
||||
{
|
||||
MOZ_ASSERT(OnMediaTimerThread());
|
||||
if (TimerIsArmed()) {
|
||||
TIMER_LOG("MediaTimer::CancelTimerIfArmed canceling timer");
|
||||
mTimer->Cancel();
|
||||
mCurrentTimerTarget = TimeStamp();
|
||||
}
|
||||
@ -94,6 +102,15 @@ private:
|
||||
Monitor mMonitor;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
TimeStamp mCurrentTimerTarget;
|
||||
|
||||
// Timestamps only have relative meaning, so we need a base timestamp for
|
||||
// logging purposes.
|
||||
TimeStamp mCreationTimeStamp;
|
||||
int64_t RelativeMicroseconds(const TimeStamp& aTimeStamp)
|
||||
{
|
||||
return (int64_t) (aTimeStamp - mCreationTimeStamp).ToMicroseconds();
|
||||
}
|
||||
|
||||
bool mUpdateScheduled;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user