forked from mirrors/gecko-dev
Bug 1794529 - Report MEMORY_TOTAL only if there were no errors calculating it r=xpcom-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D209649
This commit is contained in:
parent
6f15d19fc3
commit
9a8138ae0d
2 changed files with 21 additions and 8 deletions
|
|
@ -433,17 +433,22 @@ void MemoryTelemetry::GatherTotalMemory() {
|
|||
|
||||
// Use our handle for the remote process to collect resident unique set
|
||||
// size information for that process.
|
||||
bool success = true;
|
||||
for (const auto& info : infos) {
|
||||
#ifdef XP_MACOSX
|
||||
int64_t memory =
|
||||
nsMemoryReporterManager::PhysicalFootprint(info.mHandle);
|
||||
#else
|
||||
int64_t memory =
|
||||
nsMemoryReporterManager::ResidentUnique(info.mHandle);
|
||||
int64_t memory =
|
||||
nsMemoryReporterManager::ResidentUnique(info.mHandle);
|
||||
#endif
|
||||
if (memory > 0) {
|
||||
childSizes.AppendElement(memory);
|
||||
totalMemory += memory;
|
||||
} else {
|
||||
// We don't break out of the loop otherwise the cleanup code
|
||||
// wouldn't run.
|
||||
success = false;
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
|
|
@ -453,17 +458,22 @@ void MemoryTelemetry::GatherTotalMemory() {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<int64_t> mbTotal;
|
||||
if (success) {
|
||||
mbTotal = Some(totalMemory);
|
||||
}
|
||||
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"MemoryTelemetry::FinishGatheringTotalMemory",
|
||||
[totalMemory, childSizes = std::move(childSizes)] {
|
||||
MemoryTelemetry::Get().FinishGatheringTotalMemory(totalMemory,
|
||||
[mbTotal, childSizes = std::move(childSizes)] {
|
||||
MemoryTelemetry::Get().FinishGatheringTotalMemory(mbTotal,
|
||||
childSizes);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
nsresult MemoryTelemetry::FinishGatheringTotalMemory(
|
||||
int64_t aTotalMemory, const nsTArray<int64_t>& aChildSizes) {
|
||||
Maybe<int64_t> aTotalMemory, const nsTArray<int64_t>& aChildSizes) {
|
||||
mGatheringTotalMemory = false;
|
||||
|
||||
// Total memory usage can be difficult to measure both accurately and fast
|
||||
|
|
@ -472,8 +482,10 @@ nsresult MemoryTelemetry::FinishGatheringTotalMemory(
|
|||
// especially on MacOS where it double-counts shared memory. For a more
|
||||
// detailed explaination see:
|
||||
// https://groups.google.com/a/mozilla.org/g/dev-platform/c/WGNOtjHdsdA
|
||||
HandleMemoryReport(Telemetry::MEMORY_TOTAL, nsIMemoryReporter::UNITS_BYTES,
|
||||
aTotalMemory);
|
||||
if (aTotalMemory) {
|
||||
HandleMemoryReport(Telemetry::MEMORY_TOTAL, nsIMemoryReporter::UNITS_BYTES,
|
||||
aTotalMemory.value());
|
||||
}
|
||||
|
||||
if (aChildSizes.Length() > 1) {
|
||||
int32_t tabsCount;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_MemoryTelemetry_h
|
||||
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsITimer.h"
|
||||
|
|
@ -61,7 +62,7 @@ class MemoryTelemetry final : public nsIObserver,
|
|||
static Result<uint32_t, nsresult> GetOpenTabsCount();
|
||||
|
||||
void GatherTotalMemory();
|
||||
nsresult FinishGatheringTotalMemory(int64_t aTotalMemory,
|
||||
nsresult FinishGatheringTotalMemory(Maybe<int64_t> aTotalMemory,
|
||||
const nsTArray<int64_t>& aChildSizes);
|
||||
|
||||
nsCOMPtr<nsIEventTarget> mThreadPool;
|
||||
|
|
|
|||
Loading…
Reference in a new issue