Bug 1382768 - Performance API must be a memory reporter, r=bz

This commit is contained in:
Andrea Marchesini 2017-07-27 09:05:51 +02:00
parent e162c04cba
commit d06ba4ca6f
14 changed files with 139 additions and 1 deletions

View File

@ -13813,6 +13813,13 @@ nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
}
++aWindowSizes->mDOMEventTargetsCount;
}
if (IsInnerWindow() && mPerformance) {
aWindowSizes->mDOMPerformanceUserEntries =
mPerformance->SizeOfUserEntries(aWindowSizes->mMallocSizeOf);
aWindowSizes->mDOMPerformanceResourceEntries =
mPerformance->SizeOfResourceEntries(aWindowSizes->mMallocSizeOf);
}
}
void

View File

@ -406,6 +406,18 @@ CollectWindowReports(nsGlobalWindow *aWindow,
aWindowTotalSizes->mLayoutFramePropertiesSize +=
windowSizes.mLayoutFramePropertiesSize;
REPORT_SIZE("/dom/performance/user-entries",
windowSizes.mDOMPerformanceUserEntries,
"Memory used for performance user entries.");
aWindowTotalSizes->mDOMPerformanceUserEntries +=
windowSizes.mDOMPerformanceUserEntries;
REPORT_SIZE("/dom/performance/resource-entries",
windowSizes.mDOMPerformanceResourceEntries,
"Memory used for performance resource entries.");
aWindowTotalSizes->mDOMPerformanceResourceEntries +=
windowSizes.mDOMPerformanceResourceEntries;
// There are many different kinds of frames, but it is very likely
// that only a few matter. Implement a cutoff so we don't bloat
// about:memory with many uninteresting entries.

View File

@ -27,6 +27,8 @@ class nsWindowSizes {
macro(DOM, mDOMCDATANodesSize) \
macro(DOM, mDOMCommentNodesSize) \
macro(DOM, mDOMEventTargetsSize) \
macro(DOM, mDOMPerformanceUserEntries) \
macro(DOM, mDOMPerformanceResourceEntries) \
macro(DOM, mDOMOtherSize) \
macro(Style, mStyleSheetsSize) \
macro(Other, mLayoutPresShellSize) \

View File

@ -573,5 +573,25 @@ Performance::MemoryPressure()
mUserEntries.Clear();
}
size_t
Performance::SizeOfUserEntries(mozilla::MallocSizeOf aMallocSizeOf) const
{
size_t userEntries = 0;
for (const PerformanceEntry* entry : mUserEntries) {
userEntries += entry->SizeOfIncludingThis(aMallocSizeOf);
}
return userEntries;
}
size_t
Performance::SizeOfResourceEntries(mozilla::MallocSizeOf aMallocSizeOf) const
{
size_t resourceEntries = 0;
for (const PerformanceEntry* entry : mResourceEntries) {
resourceEntries += entry->SizeOfIncludingThis(aMallocSizeOf);
}
return resourceEntries;
}
} // dom namespace
} // mozilla namespace

View File

@ -103,6 +103,9 @@ public:
void MemoryPressure();
size_t SizeOfUserEntries(mozilla::MallocSizeOf aMallocSizeOf) const;
size_t SizeOfResourceEntries(mozilla::MallocSizeOf aMallocSizeOf) const;
protected:
Performance();
explicit Performance(nsPIDOMWindowInner* aWindow);

View File

@ -41,3 +41,16 @@ PerformanceEntry::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return mozilla::dom::PerformanceEntryBinding::Wrap(aCx, this, aGivenProto);
}
size_t
PerformanceEntry::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return mName.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
mEntryType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
size_t
PerformanceEntry::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}

View File

@ -84,7 +84,11 @@ public:
return nullptr;
}
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
protected:
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
nsCOMPtr<nsISupports> mParent;
nsString mName;
nsString mEntryType;

View File

@ -29,3 +29,9 @@ PerformanceMark::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return PerformanceMarkBinding::Wrap(aCx, this, aGivenProto);
}
size_t
PerformanceMark::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}

View File

@ -27,6 +27,8 @@ public:
return mStartTime;
}
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
protected:
virtual ~PerformanceMark();
DOMHighResTimeStamp mStartTime;

View File

@ -31,3 +31,9 @@ PerformanceMeasure::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto
{
return PerformanceMeasureBinding::Wrap(aCx, this, aGivenProto);
}
size_t
PerformanceMeasure::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}

View File

@ -33,6 +33,8 @@ public:
return mDuration;
}
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
protected:
virtual ~PerformanceMeasure();
DOMHighResTimeStamp mStartTime;

View File

@ -26,7 +26,7 @@ NS_IMPL_RELEASE_INHERITED(PerformanceResourceTiming, PerformanceEntry)
PerformanceResourceTiming::PerformanceResourceTiming(PerformanceTiming* aPerformanceTiming,
Performance* aPerformance,
const nsAString& aName)
: PerformanceEntry(aPerformance, aName, NS_LITERAL_STRING("resource")),
: PerformanceEntry(aPerformance->GetParentObject(), aName, NS_LITERAL_STRING("resource")),
mTiming(aPerformanceTiming),
mEncodedBodySize(0),
mTransferSize(0),
@ -51,3 +51,17 @@ PerformanceResourceTiming::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGiv
{
return PerformanceResourceTimingBinding::Wrap(aCx, this, aGivenProto);
}
size_t
PerformanceResourceTiming::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
}
size_t
PerformanceResourceTiming::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return PerformanceEntry::SizeOfExcludingThis(aMallocSizeOf) +
mInitiatorType.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
mNextHopProtocol.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}

View File

@ -168,9 +168,15 @@ public:
mDecodedBodySize = aDecodedBodySize;
}
size_t
SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
protected:
virtual ~PerformanceResourceTiming();
size_t
SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
nsString mInitiatorType;
nsString mNextHopProtocol;
RefPtr<PerformanceTiming> mTiming;

View File

@ -2427,6 +2427,8 @@ private:
{
nsCOMPtr<nsIHandleReportCallback> mHandleReport;
nsCOMPtr<nsISupports> mHandlerData;
size_t mPerformanceUserEntries;
size_t mPerformanceResourceEntries;
const bool mAnonymize;
bool mSuccess;
@ -2441,6 +2443,12 @@ private:
NS_IMETHOD Run() override;
void SetPerformanceSizes(size_t userEntries, size_t resourceEntries)
{
mPerformanceUserEntries = userEntries;
mPerformanceResourceEntries = resourceEntries;
}
void SetSuccess(bool success)
{
mSuccess = success;
@ -2591,6 +2599,15 @@ WorkerPrivate::MemoryReporter::CollectReportsRunnable::WorkerRun(JSContext* aCx,
{
aWorkerPrivate->AssertIsOnWorkerThread();
RefPtr<Performance> performance =
aWorkerPrivate->GlobalScope()->GetPerformanceIfExists();
if (performance) {
size_t userEntries = performance->SizeOfUserEntries(JsWorkerMallocSizeOf);
size_t resourceEntries =
performance->SizeOfResourceEntries(JsWorkerMallocSizeOf);
mFinishCollectRunnable->SetPerformanceSizes(userEntries, resourceEntries);
}
mFinishCollectRunnable->SetSuccess(
aWorkerPrivate->CollectRuntimeStats(&mFinishCollectRunnable->mCxStats, mAnonymize));
@ -2606,6 +2623,8 @@ WorkerPrivate::MemoryReporter::FinishCollectRunnable::FinishCollectRunnable(
"dom::workers::WorkerPrivate::MemoryReporter::FinishCollectRunnable")
, mHandleReport(aHandleReport)
, mHandlerData(aHandlerData)
, mPerformanceUserEntries(0)
, mPerformanceResourceEntries(0)
, mAnonymize(aAnonymize)
, mSuccess(false)
, mCxStats(aPath)
@ -2626,6 +2645,28 @@ WorkerPrivate::MemoryReporter::FinishCollectRunnable::Run()
xpc::ReportJSRuntimeExplicitTreeStats(mCxStats, mCxStats.Path(),
mHandleReport, mHandlerData,
mAnonymize);
if (mPerformanceUserEntries) {
nsCString path = mCxStats.Path();
path.AppendLiteral("dom/performance/user-entries");
mHandleReport->Callback(EmptyCString(), path,
nsIMemoryReporter::KIND_HEAP,
nsIMemoryReporter::UNITS_BYTES,
mPerformanceUserEntries,
NS_LITERAL_CSTRING("Memory used for performance user entries."),
mHandlerData);
}
if (mPerformanceResourceEntries) {
nsCString path = mCxStats.Path();
path.AppendLiteral("dom/performance/resource-entries");
mHandleReport->Callback(EmptyCString(), path,
nsIMemoryReporter::KIND_HEAP,
nsIMemoryReporter::UNITS_BYTES,
mPerformanceResourceEntries,
NS_LITERAL_CSTRING("Memory used for performance resource entries."),
mHandlerData);
}
}
manager->EndReport();