Bug 1407810 - DDMediaLogs::SizeOf accounts for shallow message queue size - r?jwwang
MozReview-Commit-ID: 9irARpytVoh
--- a/dom/media/doctor/DDMediaLogs.cpp
+++ b/dom/media/doctor/DDMediaLogs.cpp
@@ -300,16 +300,19 @@ DDMediaLogs::DestroyLifetimeLinks(const
aLifetime.IsAliveAt(link.mLinkingIndex);
});
}
size_t
DDMediaLogs::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t size = aMallocSizeOf(this) +
+ // This will usually be called after processing, so negligible
+ // external data should still be present in the queue.
+ mMessagesQueue.ShallowSizeOfExcludingThis(aMallocSizeOf) +
mLifetimes.SizeOfExcludingThis(aMallocSizeOf) +
mMediaLogs.ShallowSizeOfExcludingThis(aMallocSizeOf) +
mObjectLinks.ShallowSizeOfExcludingThis(aMallocSizeOf) +
mPendingPromises.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (const DDMediaLog& log : mMediaLogs) {
size += log.SizeOfExcludingThis(aMallocSizeOf);
}
return size;
@@ -671,33 +674,36 @@ DDMediaLogs::CleanUpLogs()
void
DDMediaLogs::ProcessLog()
{
MOZ_ASSERT(!mThread || mThread.get() == NS_GetCurrentThread());
ProcessBuffer();
FulfillPromises();
CleanUpLogs();
- DDL_INFO("DDMediaLog size: %zu", SizeOfIncludingThis(moz_malloc_size_of));
+ DDL_INFO("ProcessLog() completed - DDMediaLog size: %zu",
+ SizeOfIncludingThis(moz_malloc_size_of));
}
nsresult
DDMediaLogs::DispatchProcessLog(const MutexAutoLock& aProofOfLock)
{
if (!mThread) {
return NS_ERROR_SERVICE_NOT_AVAILABLE;
}
return mThread->Dispatch(
NS_NewRunnableFunction("ProcessLog", [this] { ProcessLog(); }),
NS_DISPATCH_NORMAL);
}
nsresult
DDMediaLogs::DispatchProcessLog()
{
+ DDL_INFO("DispatchProcessLog() - Yet-unprocessed message buffers: %d",
+ mMessagesQueue.LiveBuffersStats().mCount);
MutexAutoLock lock(mMutex);
return DispatchProcessLog(lock);
}
RefPtr<DDMediaLogs::LogMessagesPromise>
DDMediaLogs::RetrieveMessages(const dom::HTMLMediaElement* aMediaElement)
{
MozPromiseHolder<LogMessagesPromise> holder;
--- a/dom/media/doctor/MultiWriterQueue.h
+++ b/dom/media/doctor/MultiWriterQueue.h
@@ -3,16 +3,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_MultiWriterQueue_h_
#define mozilla_MultiWriterQueue_h_
#include "mozilla/Atomics.h"
+#include "mozilla/MemoryReporting.h"
#include "mozilla/Move.h"
#include "mozilla/Mutex.h"
#include "prthread.h"
#include "RollingNumber.h"
#include <cstdint>
namespace mozilla {
@@ -248,16 +249,22 @@ public:
MOZ_ASSERT(mNextElementToPop == b->Newer()->Origin());
StopUsing(b, destroy);
destroy = !destroy;
// We will loop and start reading the now-oldest buffer.
}
}
+ // Size of all buffers (used, or recyclable), excluding external data.
+ size_t ShallowSizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
+ {
+ return mAllocatedBuffersStats.Count() * sizeof(Buffer);
+ }
+
struct CountAndWatermark
{
int mCount;
int mWatermark;
};
CountAndWatermark LiveBuffersStats() const { return mLiveBuffersStats.Get(); }
CountAndWatermark ReusableBuffersStats() const
@@ -495,16 +502,18 @@ private:
{
public:
explicit AtomicCountAndWatermark(int aCount)
: mCount(aCount)
, mWatermark(aCount)
{
}
+ int Count() const { return int(mCount); }
+
CountAndWatermark Get() const
{
return CountAndWatermark{ int(mCount), int(mWatermark) };
}
int operator++()
{
int count = int(++mCount);