Bug 1749809 - Basic memory reporting test for UtilityProcess r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D137774
This commit is contained in:
Alexandre Lissy 2022-02-04 15:17:26 +00:00
Родитель 9761993a72
Коммит 5a84cf8dc4
4 изменённых файлов: 96 добавлений и 0 удалений

Просмотреть файл

@ -130,6 +130,11 @@ Crash reporting
- Add new ``Xxx*Status`` `annotations <https://searchfox.org/mozilla-central/rev/d4b9c457db637fde655592d9e2048939b7ab2854/toolkit/crashreporter/CrashAnnotations.yaml#968-971>`_ entry for your new process type description. The link here points to `UtilityProcessStatus` so you can see the similar description you have to write, but you might want to respect ordering in that file and put your new code at the appropriate place.
- Add entry in `PROCESS_CRASH_SUBMIT_ATTEMPT <https://searchfox.org/mozilla-central/rev/d4b9c457db637fde655592d9e2048939b7ab2854/toolkit/components/telemetry/Histograms.json#13403-13422>`_
Memory reporting
#################
- Add handling for your new process within `nsMemoryReporterManager::GetReportsExtended <https://searchfox.org/mozilla-central/rev/d4b9c457db637fde655592d9e2048939b7ab2854/xpcom/base/nsMemoryReporterManager.cpp#1786-1809>`
Process reporting
#################

Просмотреть файл

@ -2,6 +2,7 @@
support-files =
../../../../tools/profiler/tests/shared-head.js
[browser_utility_memoryReport.js]
[browser_utility_profiler.js]
skip-if = tsan # from tools/profiler/tests/browser/browser.ini, timing out on profiler tests?
[browser_utility_start.js]

Просмотреть файл

@ -0,0 +1,80 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
var utilityPid = undefined;
var utilityReports = [];
add_task(async () => {
const utilityProcessTest = Cc[
"@mozilla.org/utility-process-test;1"
].createInstance(Ci.nsIUtilityProcessTest);
await utilityProcessTest
.startProcess()
.then(async pid => {
utilityPid = pid;
ok(true, "Could start Utility process: " + pid);
})
.catch(async () => {
ok(false, "Cannot start Utility process?");
});
});
add_task(async () => {
const gMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(
Ci.nsIMemoryReporterManager
);
ok(utilityPid !== undefined, "Utility process is running");
const performCollection = new Promise((resolve, reject) => {
// Record the reports from the live memory reporters then process them.
let handleReport = function(
aProcess,
aUnsafePath,
aKind,
aUnits,
aAmount,
aDescription
) {
const expectedProcess = `Utility (pid ${utilityPid})`;
if (aProcess !== expectedProcess) {
return;
}
let report = {
process: aProcess,
path: aUnsafePath,
kind: aKind,
units: aUnits,
amount: aAmount,
description: aDescription,
};
utilityReports.push(report);
};
info("Memory report: Perform the call");
gMgr.getReports(handleReport, null, resolve, null, false);
});
await performCollection;
info("Collected", utilityReports.length, "reports from utility process");
ok(!!utilityReports.length, "Collected some reports");
ok(
utilityReports.filter(r => r.path === "vsize" && r.amount > 0).length === 1,
"Collected vsize report"
);
ok(
utilityReports.filter(r => r.path === "resident" && r.amount > 0).length ===
1,
"Collected resident report"
);
ok(
!!utilityReports.filter(
r => r.path.search(/^explicit\/.*/) >= 0 && r.amount > 0
).length,
"Collected some explicit/ report"
);
});

Просмотреть файл

@ -40,6 +40,7 @@
#include "mozilla/dom/MemoryReportTypes.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/ipc/UtilityProcessManager.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#ifdef XP_WIN
@ -54,6 +55,7 @@
#endif
using namespace mozilla;
using namespace mozilla::ipc;
using namespace dom;
#if defined(MOZ_MEMORY)
@ -1808,6 +1810,14 @@ nsresult nsMemoryReporterManager::StartGettingReports() {
}
}
if (RefPtr<UtilityProcessManager> utility =
UtilityProcessManager::GetSingleton()) {
if (RefPtr<MemoryReportingProcess> proc =
utility->GetProcessMemoryReporter()) {
s->mChildrenPending.AppendElement(proc.forget());
}
}
if (!s->mChildrenPending.IsEmpty()) {
nsCOMPtr<nsITimer> timer;
rv = NS_NewTimerWithFuncCallback(