mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
Make Background Hang Monitor Optional
This is done by wrapping all channels of communication and related objects inside Option which are configured using flag inside servo_config.
This commit is contained in:
parent
ada95b9878
commit
a05553f188
9 changed files with 126 additions and 74 deletions
|
@ -282,11 +282,11 @@ pub struct Constellation<Message, LTF, STF> {
|
|||
|
||||
/// A channel for the background hang monitor to send messages
|
||||
/// to the constellation.
|
||||
background_hang_monitor_sender: IpcSender<HangMonitorAlert>,
|
||||
background_hang_monitor_sender: Option<IpcSender<HangMonitorAlert>>,
|
||||
|
||||
/// A channel for the constellation to receiver messages
|
||||
/// from the background hang monitor.
|
||||
background_hang_monitor_receiver: Receiver<Result<HangMonitorAlert, IpcError>>,
|
||||
background_hang_monitor_receiver: Option<Receiver<Result<HangMonitorAlert, IpcError>>>,
|
||||
|
||||
/// An IPC channel for layout threads to send messages to the constellation.
|
||||
/// This is the layout threads' view of `layout_receiver`.
|
||||
|
@ -849,28 +849,42 @@ where
|
|||
ipc_scheduler_receiver,
|
||||
);
|
||||
|
||||
let (background_hang_monitor_sender, ipc_bhm_receiver) =
|
||||
ipc::channel().expect("ipc channel failure");
|
||||
let background_hang_monitor_receiver =
|
||||
route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(ipc_bhm_receiver);
|
||||
let (background_hang_monitor_sender, background_hang_monitor_receiver) =
|
||||
if opts::get().background_hang_monitor {
|
||||
let (bhm_sender, ipc_bhm_receiver) =
|
||||
ipc::channel().expect("ipc channel failure");
|
||||
(
|
||||
Some(bhm_sender),
|
||||
Some(route_ipc_receiver_to_new_mpsc_receiver_preserving_errors(
|
||||
ipc_bhm_receiver,
|
||||
)),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
// If we are in multiprocess mode,
|
||||
// a dedicated per-process hang monitor will be initialized later inside the content process.
|
||||
// See run_content_process in servo/lib.rs
|
||||
let (background_monitor_register, sampler_chan) = if opts::multiprocess() {
|
||||
(None, vec![])
|
||||
} else {
|
||||
let (sampling_profiler_control, sampling_profiler_port) =
|
||||
ipc::channel().expect("ipc channel failure");
|
||||
|
||||
(
|
||||
Some(HangMonitorRegister::init(
|
||||
background_hang_monitor_sender.clone(),
|
||||
sampling_profiler_port,
|
||||
)),
|
||||
vec![sampling_profiler_control],
|
||||
)
|
||||
};
|
||||
let (background_monitor_register, sampler_chan) =
|
||||
if opts::multiprocess() || !opts::get().background_hang_monitor {
|
||||
(None, vec![])
|
||||
} else {
|
||||
let (sampling_profiler_control, sampling_profiler_port) =
|
||||
ipc::channel().expect("ipc channel failure");
|
||||
if let Some(bhm_sender) = background_hang_monitor_sender.clone() {
|
||||
(
|
||||
Some(HangMonitorRegister::init(
|
||||
bhm_sender,
|
||||
sampling_profiler_port,
|
||||
)),
|
||||
vec![sampling_profiler_control],
|
||||
)
|
||||
} else {
|
||||
warn!("No BHM sender found in BHM mode.");
|
||||
(None, vec![])
|
||||
}
|
||||
};
|
||||
|
||||
let (ipc_layout_sender, ipc_layout_receiver) =
|
||||
ipc::channel().expect("ipc channel failure");
|
||||
|
@ -1413,7 +1427,7 @@ where
|
|||
recv(self.script_receiver) -> msg => {
|
||||
msg.expect("Unexpected script channel panic in constellation").map(Request::Script)
|
||||
}
|
||||
recv(self.background_hang_monitor_receiver) -> msg => {
|
||||
recv(self.background_hang_monitor_receiver.as_ref().unwrap_or(&never())) -> msg => {
|
||||
msg.expect("Unexpected BHM channel panic in constellation").map(Request::BackgroundHangMonitor)
|
||||
}
|
||||
recv(self.compositor_receiver) -> msg => {
|
||||
|
|
|
@ -131,7 +131,7 @@ pub struct InitialPipelineState {
|
|||
pub background_monitor_register: Option<Box<dyn BackgroundHangMonitorRegister>>,
|
||||
|
||||
/// A channel for the background hang monitor to send messages to the constellation.
|
||||
pub background_hang_monitor_to_constellation_chan: IpcSender<HangMonitorAlert>,
|
||||
pub background_hang_monitor_to_constellation_chan: Option<IpcSender<HangMonitorAlert>>,
|
||||
|
||||
/// A channel for the layout thread to send messages to the constellation.
|
||||
pub layout_to_constellation_chan: IpcSender<LayoutMsg>,
|
||||
|
@ -319,15 +319,24 @@ impl Pipeline {
|
|||
Some(sampler_chan)
|
||||
} else {
|
||||
// Should not be None in single-process mode.
|
||||
let register = state
|
||||
.background_monitor_register
|
||||
.expect("Couldn't start content, no background monitor has been initiated");
|
||||
unprivileged_pipeline_content.start_all::<Message, LTF, STF>(
|
||||
false,
|
||||
register,
|
||||
state.event_loop_waker,
|
||||
);
|
||||
None
|
||||
if opts::get().background_hang_monitor {
|
||||
let register = state.background_monitor_register.expect(
|
||||
"Couldn't start content, no background monitor has been initiated",
|
||||
);
|
||||
unprivileged_pipeline_content.start_all::<Message, LTF, STF>(
|
||||
false,
|
||||
Some(register),
|
||||
state.event_loop_waker,
|
||||
);
|
||||
None
|
||||
} else {
|
||||
unprivileged_pipeline_content.start_all::<Message, LTF, STF>(
|
||||
false,
|
||||
None,
|
||||
state.event_loop_waker,
|
||||
);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
(EventLoop::new(script_chan), sampler_chan)
|
||||
|
@ -488,7 +497,7 @@ pub struct UnprivilegedPipelineContent {
|
|||
opener: Option<BrowsingContextId>,
|
||||
namespace_request_sender: IpcSender<PipelineNamespaceRequest>,
|
||||
script_to_constellation_chan: ScriptToConstellationChan,
|
||||
background_hang_monitor_to_constellation_chan: IpcSender<HangMonitorAlert>,
|
||||
background_hang_monitor_to_constellation_chan: Option<IpcSender<HangMonitorAlert>>,
|
||||
sampling_profiler_port: Option<IpcReceiver<SamplerControlMsg>>,
|
||||
layout_to_constellation_chan: IpcSender<LayoutMsg>,
|
||||
scheduler_chan: IpcSender<TimerSchedulerMsg>,
|
||||
|
@ -520,7 +529,7 @@ impl UnprivilegedPipelineContent {
|
|||
pub fn start_all<Message, LTF, STF>(
|
||||
self,
|
||||
wait_for_completion: bool,
|
||||
background_hang_monitor_register: Box<dyn BackgroundHangMonitorRegister>,
|
||||
background_hang_monitor_register: Option<Box<dyn BackgroundHangMonitorRegister>>,
|
||||
event_loop_waker: Option<Box<dyn EventLoopWaker>>,
|
||||
) where
|
||||
LTF: LayoutThreadFactory<Message = Message>,
|
||||
|
@ -730,13 +739,17 @@ impl UnprivilegedPipelineContent {
|
|||
|
||||
pub fn register_with_background_hang_monitor(
|
||||
&mut self,
|
||||
) -> Box<dyn BackgroundHangMonitorRegister> {
|
||||
HangMonitorRegister::init(
|
||||
self.background_hang_monitor_to_constellation_chan.clone(),
|
||||
self.sampling_profiler_port
|
||||
.take()
|
||||
.expect("no sampling profiler?"),
|
||||
)
|
||||
) -> Option<Box<dyn BackgroundHangMonitorRegister>> {
|
||||
self.background_hang_monitor_to_constellation_chan
|
||||
.clone()
|
||||
.map(|bhm| {
|
||||
HangMonitorRegister::init(
|
||||
bhm.clone(),
|
||||
self.sampling_profiler_port
|
||||
.take()
|
||||
.expect("no sampling profiler?"),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn script_to_constellation_chan(&self) -> &ScriptToConstellationChan {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue