mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
compositing: Add memory reporter for WebRender. (#36557)
This adds a memory reporter for WebRender's memory usage. I seeded it with a couple entries that looked reasonable based on https://searchfox.org/mozilla-central/rev/2c71f1e9b5947612abdc16b64008162c58c1b9d3/gfx/thebes/gfxPlatform.cpp#722-738. Testing: Verified that new numbers appear in about:memory for servo.org. The new images category is surprisingly large (40mb). Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
afe98e9e1e
commit
af000d6c91
9 changed files with 98 additions and 8 deletions
|
@ -27,6 +27,7 @@ image = { workspace = true }
|
|||
ipc-channel = { workspace = true }
|
||||
log = { workspace = true }
|
||||
pixels = { path = '../../pixels' }
|
||||
profile_traits = { path = '../profile' }
|
||||
raw-window-handle = { version = "0.6" }
|
||||
serde = { workspace = true }
|
||||
servo_geometry = { path = "../../geometry" }
|
||||
|
|
|
@ -29,6 +29,7 @@ use display_list::CompositorDisplayListInfo;
|
|||
use embedder_traits::{CompositorHitTestResult, ScreenGeometry};
|
||||
use euclid::default::Size2D as UntypedSize2D;
|
||||
use ipc_channel::ipc::{self, IpcSharedMemory};
|
||||
use profile_traits::mem::{OpaqueSender, ReportsChan};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_geometry::{DeviceIndependentIntRect, DeviceIndependentIntSize};
|
||||
use webrender_api::units::{DevicePoint, LayoutPoint, TexelRect};
|
||||
|
@ -50,6 +51,12 @@ pub struct CompositorProxy {
|
|||
pub event_loop_waker: Box<dyn EventLoopWaker>,
|
||||
}
|
||||
|
||||
impl OpaqueSender<CompositorMsg> for CompositorProxy {
|
||||
fn send(&self, message: CompositorMsg) {
|
||||
CompositorProxy::send(self, message)
|
||||
}
|
||||
}
|
||||
|
||||
impl CompositorProxy {
|
||||
pub fn send(&self, msg: CompositorMsg) {
|
||||
if let Err(err) = self.sender.send(msg) {
|
||||
|
@ -154,6 +161,10 @@ pub enum CompositorMsg {
|
|||
/// Get the available screen size (without toolbars and docks) for the screen
|
||||
/// the client window inhabits.
|
||||
GetAvailableScreenSize(WebViewId, IpcSender<DeviceIndependentIntSize>),
|
||||
|
||||
/// Measure the current memory usage associated with the compositor.
|
||||
/// The report must be sent on the provided channel once it's complete.
|
||||
CollectMemoryReport(ReportsChan),
|
||||
}
|
||||
|
||||
impl Debug for CompositorMsg {
|
||||
|
|
|
@ -50,6 +50,21 @@ where
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct ProfilerChan(pub IpcSender<ProfilerMsg>);
|
||||
|
||||
/// A handle that encompasses a registration with the memory profiler.
|
||||
/// The registration is tied to the lifetime of this type; the memory
|
||||
/// profiler unregister the reporter when this object is dropped.
|
||||
pub struct ProfilerRegistration {
|
||||
sender: ProfilerChan,
|
||||
reporter_name: String,
|
||||
}
|
||||
|
||||
impl Drop for ProfilerRegistration {
|
||||
fn drop(&mut self) {
|
||||
self.sender
|
||||
.send(ProfilerMsg::UnregisterReporter(self.reporter_name.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
impl ProfilerChan {
|
||||
/// Send `msg` on this `IpcSender`.
|
||||
///
|
||||
|
@ -60,15 +75,15 @@ impl ProfilerChan {
|
|||
}
|
||||
}
|
||||
|
||||
/// Runs `f()` with memory profiling.
|
||||
pub fn run_with_memory_reporting<F, M, T, C>(
|
||||
/// Register a new reporter and return a handle to automatically
|
||||
/// unregister it in the future.
|
||||
pub fn prepare_memory_reporting<M, T, C>(
|
||||
&self,
|
||||
f: F,
|
||||
reporter_name: String,
|
||||
channel_for_reporter: C,
|
||||
msg: M,
|
||||
) where
|
||||
F: FnOnce(),
|
||||
) -> ProfilerRegistration
|
||||
where
|
||||
M: Fn(ReportsChan) -> T + Send + 'static,
|
||||
T: Send + 'static,
|
||||
C: OpaqueSender<T> + Send + 'static,
|
||||
|
@ -88,9 +103,28 @@ impl ProfilerChan {
|
|||
Reporter(reporter_sender),
|
||||
));
|
||||
|
||||
f();
|
||||
ProfilerRegistration {
|
||||
sender: self.clone(),
|
||||
reporter_name,
|
||||
}
|
||||
}
|
||||
|
||||
self.send(ProfilerMsg::UnregisterReporter(reporter_name));
|
||||
/// Runs `f()` with memory profiling.
|
||||
pub fn run_with_memory_reporting<F, M, T, C>(
|
||||
&self,
|
||||
f: F,
|
||||
reporter_name: String,
|
||||
channel_for_reporter: C,
|
||||
msg: M,
|
||||
) where
|
||||
F: FnOnce(),
|
||||
M: Fn(ReportsChan) -> T + Send + 'static,
|
||||
T: Send + 'static,
|
||||
C: OpaqueSender<T> + Send + 'static,
|
||||
{
|
||||
let _registration = self.prepare_memory_reporting(reporter_name, channel_for_reporter, msg);
|
||||
|
||||
f();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue