Bug 1376038 - Part 1: Use a cached ghost window value for the distinguished amount. r=mccr8

We already periodically calculate the ghost window amount after cycle
collection, this just uses a cached value of that for the distinguished amount.
This avoids the overhead of a recalculating the value when reporting telemetry.
This commit is contained in:
Eric Rahm
2017-07-11 13:58:20 -07:00
parent c27fd9e6dd
commit 0eed92f03c
3 changed files with 9 additions and 5 deletions

View File

@@ -34,7 +34,8 @@ const int32_t kTimeBetweenChecks = 45; /* seconds */
nsWindowMemoryReporter::nsWindowMemoryReporter()
: mLastCheckForGhostWindows(TimeStamp::NowLoRes()),
mCycleCollectorIsRunning(false),
mCheckTimerWaitingForCCEnd(false)
mCheckTimerWaitingForCCEnd(false),
mGhostWindowCount(0)
{
}
@@ -757,6 +758,7 @@ nsWindowMemoryReporter::CheckForGhostWindows(
// if it's not null.
uint32_t ghostTimeout = GetGhostTimeout();
TimeStamp now = mLastCheckForGhostWindows;
mGhostWindowCount = 0;
for (auto iter = mDetachedWindows.Iter(); !iter.Done(); iter.Next()) {
nsWeakPtr weakKey = do_QueryInterface(iter.Key());
nsCOMPtr<mozIDOMWindow> iwindow = do_QueryReferent(weakKey);
@@ -809,6 +811,7 @@ nsWindowMemoryReporter::CheckForGhostWindows(
// that is not null.
if (aOutGhostIDs && window) {
aOutGhostIDs->PutEntry(window->WindowID());
mGhostWindowCount++;
}
}
}
@@ -821,9 +824,7 @@ NS_IMPL_ISUPPORTS(nsWindowMemoryReporter::GhostWindowsReporter,
/* static */ int64_t
nsWindowMemoryReporter::GhostWindowsReporter::DistinguishedAmount()
{
nsTHashtable<nsUint64HashKey> ghostWindows;
sWindowReporter->CheckForGhostWindows(&ghostWindows);
return ghostWindows.Count();
return sWindowReporter->mGhostWindowCount;
}
void

View File

@@ -258,6 +258,8 @@ private:
bool mCycleCollectorIsRunning;
bool mCheckTimerWaitingForCCEnd;
int64_t mGhostWindowCount;
};
#endif // nsWindowMemoryReporter_h__

View File

@@ -374,7 +374,8 @@ interface nsIMemoryReporterManager : nsISupports
* of low-{virtual,physical}-memory events that have occurred since the
* process started.
*
* |ghostWindows| (UNITS_COUNT) The number of ghost windows.
* |ghostWindows| (UNITS_COUNT) A cached value of the number of ghost
* windows. This should have been updated within the past 60s.
*
* |pageFaultsHard| (UNITS_COUNT_CUMULATIVE) The number of hard (a.k.a.
* major) page faults that have occurred since the process started.