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

@ -113,6 +113,8 @@ pub enum Resource {
/// The page contains a js function `setData` that will then be used to build the list of directory.
/// It can be empty but then nothing will be displayed when a directory listing is requested.
DirectoryListingHTML,
/// A HTML page that is used for the about:memory url.
AboutMemoryHTML,
}
impl Resource {
@ -132,6 +134,7 @@ impl Resource {
Resource::MediaControlsJS => "media-controls.js",
Resource::CrashHTML => "crash.html",
Resource::DirectoryListingHTML => "directory-listing.html",
Resource::AboutMemoryHTML => "about-memory.html",
}
}
}
@ -189,6 +192,9 @@ fn resources_for_tests() -> Box<dyn ResourceReaderMethods + Sync + Send> {
Resource::DirectoryListingHTML => {
&include_bytes!("../../../resources/directory-listing.html")[..]
},
Resource::AboutMemoryHTML => {
&include_bytes!("../../../resources/about-memory.html")[..]
},
}
.to_owned()
}

View file

@ -190,6 +190,13 @@ macro_rules! path {
}}
}
/// The results produced by the memory reporter.
#[derive(Debug, Deserialize, Serialize)]
pub struct MemoryReportResult {
/// The stringified output.
pub content: String,
}
/// Messages that can be sent to the memory profiler thread.
#[derive(Debug, Deserialize, Serialize)]
pub enum ProfilerMsg {
@ -208,4 +215,7 @@ pub enum ProfilerMsg {
/// Tells the memory profiler to shut down.
Exit,
/// Triggers sending back the memory profiling metrics,
Report(IpcSender<MemoryReportResult>),
}

View file

@ -27,6 +27,7 @@ use style_traits::CSSPixel;
#[cfg(feature = "webgpu")]
use webgpu::{WebGPU, WebGPUResponse, wgc};
use crate::mem::MemoryReportResult;
use crate::{
AnimationState, AuxiliaryWebViewCreationRequest, BroadcastMsg, DocumentState,
IFrameLoadInfoWithData, LoadData, MessagePortMsg, NavigationHistoryBehavior, PortMessageTask,
@ -248,6 +249,8 @@ pub enum ScriptMsg {
TitleChanged(PipelineId, String),
/// Notify the constellation that the size of some `<iframe>`s has changed.
IFrameSizes(Vec<IFrameSizeMsg>),
/// Request results from the memory reporter.
ReportMemory(IpcSender<MemoryReportResult>),
}
impl fmt::Debug for ScriptMsg {
@ -308,6 +311,7 @@ impl fmt::Debug for ScriptMsg {
GetWebGPUChan(..) => "GetWebGPUChan",
TitleChanged(..) => "TitleChanged",
IFrameSizes(..) => "IFramSizes",
ReportMemory(..) => "ReportMemory",
};
write!(formatter, "ScriptMsg::{}", variant)
}