Make the memory reporting multi-process aware (#35863)

So far the memory reporter aggregates reports from all processes, and
runs the system reporter only in the main process. Instead it is
desirable to have per-process reports. We do so by:
- creating a ProcessReports struct that holds includes the pid in
addition to the reports themselves.
- running the system memory reporter also in content processes.
- updating the about:memory page to create one report per process, and
add useful information like the pid and the urls loaded in a given
process.

<!-- Please describe your changes on the following line: -->


---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors


![image](https://github.com/user-attachments/assets/0bafe140-539d-4d6a-8316-639309a22d4a)

Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
webbeef 2025-04-04 22:42:12 -07:00 committed by GitHub
parent 76edcff202
commit aef8537d75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 551 additions and 424 deletions

View file

@ -140,16 +140,36 @@ pub struct Report {
pub size: usize,
}
/// A set of reports belonging to a process.
#[derive(Debug, Deserialize, Serialize)]
pub struct ProcessReports {
/// The set of reports.
pub reports: Vec<Report>,
/// The process id.
pub pid: u32,
}
impl ProcessReports {
/// Adopt these reports and configure the process pid.
pub fn new(reports: Vec<Report>) -> Self {
Self {
reports,
pid: std::process::id(),
}
}
}
/// A channel through which memory reports can be sent.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ReportsChan(pub IpcSender<Vec<Report>>);
pub struct ReportsChan(pub IpcSender<ProcessReports>);
impl ReportsChan {
/// Send `report` on this `IpcSender`.
///
/// Panics if the send fails.
pub fn send(&self, report: Vec<Report>) {
self.0.send(report).unwrap();
pub fn send(&self, reports: ProcessReports) {
self.0.send(reports).unwrap();
}
}
@ -172,12 +192,8 @@ pub struct Reporter(pub IpcSender<ReporterRequest>);
impl Reporter {
/// Collect one or more memory reports. Returns true on success, and false on failure.
pub fn collect_reports(&self, reports_chan: ReportsChan) {
self.0
.send(ReporterRequest {
reports_channel: reports_chan,
})
.unwrap()
pub fn collect_reports(&self, reports_channel: ReportsChan) {
self.0.send(ReporterRequest { reports_channel }).unwrap()
}
}