Add an about:memory page (#35728)

This patch exposes a servo internal DOM API that is only made available to about:
pages on the navigator object to request memory reports. The about:memory page itself is
loaded like other html resources (eg. bad cert, net error) and makes use of this new API.

On the implementation side, notable changes:
- components/script/routed_promise.rs abstracts the setup used to fulfill a promise when the
  work needs to be routed through the constellation. The goal is to migrate other similar
  promise APIs in followup (eg. dom/webgpu/gpu.rs, bluetooth.rs).
- a new message is added to request a report from the memory reporter, and the memory reporter
  creates a json representation of the set of memory reports.
- the post-processing of memory reports is done in Javascript in the about-memory.html page,
  providing the same results as the current Rust code that outputs to stdout. We can decide
  later if we want to remove the current output.

Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
webbeef 2025-03-06 21:25:08 -08:00 committed by GitHub
parent 1864ebfb35
commit 139774e6b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 425 additions and 1 deletions

View file

@ -15,7 +15,8 @@ use ipc_channel::ipc::{self, IpcReceiver};
use ipc_channel::router::ROUTER;
use parking_lot::{Condvar, Mutex};
use profile_traits::mem::{
ProfilerChan, ProfilerMsg, ReportKind, Reporter, ReporterRequest, ReportsChan,
MemoryReportResult, ProfilerChan, ProfilerMsg, Report, ReportKind, Reporter, ReporterRequest,
ReportsChan,
};
use profile_traits::path;
@ -143,10 +144,35 @@ impl Profiler {
true
},
ProfilerMsg::Report(sender) => {
let reports = self.collect_reports();
let content = serde_json::to_string(&reports)
.unwrap_or_else(|_| "{ error: \"failed to create memory report\"}".to_owned());
let _ = sender.send(MemoryReportResult { content });
// Notify the timer thread.
let (mutex, cvar) = &*self.notifier;
let mut done = mutex.lock();
*done = true;
cvar.notify_one();
true
},
ProfilerMsg::Exit => false,
}
}
fn collect_reports(&self) -> Vec<Report> {
let mut result = vec![];
for reporter in self.reporters.values() {
let (chan, port) = ipc::channel().unwrap();
reporter.collect_reports(ReportsChan(chan));
if let Ok(mut reports) = port.recv() {
result.append(&mut reports);
}
}
result
}
fn handle_print_msg(&self) {
let elapsed = self.created.elapsed();
println!("Begin memory reports {}", elapsed.as_secs());